Skip to content

Commit

Permalink
🐛 Fix OAI importers
Browse files Browse the repository at this point in the history
This commit will fix the OAI importer by adjusting the `FileSetActor`
and `ImportUrlJob`.  The reason why it wasn't working is because it was
based on Hyrax 2.9.6 method signatures which has changed in Hyrax 3.5.0.

Ref:
  - https://github.com/scientist-softserv/adventist-dl/issues/624
  • Loading branch information
kirkkwang committed Nov 19, 2023
1 parent 2b50ce5 commit 51e17c9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 198 deletions.
183 changes: 0 additions & 183 deletions app/actors/hyrax/actors/file_set_actor.rb

This file was deleted.

41 changes: 41 additions & 0 deletions app/actors/hyrax/actors/file_set_actor_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 3.5.0 to override default_thumbnail

module Hyrax
module Actors
module FileSetActorDecorator
def attach_to_valkyrie_work(work, file_set_params)
work = Hyrax.query_service.find_by(id: work.id) unless work.new_record
file_set.visibility = work.visibility unless assign_visibility?(file_set_params)
fs = Hyrax.persister.save(resource: file_set)
Hyrax.publisher.publish('object.metadata.updated', object: fs, user: user)
work.member_ids << fs.id
work.representative_id = fs.id if work.representative_id.blank?
# OVERRIDE Hyrax 3.5.0 to override default_thumbnail
work.thumbnail = file_set if file_set.override_default_thumbnail == 'true' || work.thumbnail_id.blank?

# Save the work so the association between the work and the file_set is persisted (head_id)
# NOTE: the work may not be valid, in which case this save doesn't do anything.
Hyrax.persister.save(resource: work)
Hyrax.publisher.publish('object.metadata.updated', object: work, user: user)
end

# Adds a FileSet to the work using ore:Aggregations.
def attach_to_af_work(work, file_set_params)
work.reload unless work.new_record?
file_set.visibility = work.visibility unless assign_visibility?(file_set_params)
work.ordered_members << file_set
work.representative = file_set if work.representative_id.blank?
# OVERRIDE Hyrax 3.5.0 to override default_thumbnail
work.thumbnail = file_set if file_set.override_default_thumbnail == 'true' || work.thumbnail_id.blank?

# Save the work so the association between the work and the file_set is persisted (head_id)
# NOTE: the work may not be valid, in which case this save doesn't do anything.
work.save
end
end
end
end

Hyrax::Actors::FileSetActor.prepend Hyrax::Actors::FileSetActorDecorator
27 changes: 12 additions & 15 deletions app/jobs/import_url_job_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# frozen_string_literal: true

# OVERRIDE in v2.9.6 of Hyrax
# OVERRIDE in v3.5.0 of Hyrax
module ImportUrlJobDecorator
# OVERRIDE to gain further insight into the StandardError that was reported but hidden.
def copy_remote_file(uri, name, headers = {})
def copy_remote_file(name)
filename = File.basename(name)
dir = Dir.mktmpdir
Rails.logger.debug("ImportUrlJob: Copying <#{uri}> to #{dir}")

File.open(File.join(dir, filename), 'wb') do |f|
begin
write_file(uri, f, headers)
yield f
rescue StandardError => e
# OVERRIDE adding Rails.logger.error call
Rails.logger.error(
%(ImportUrlJob: Error copying <#{uri}> to #{dir} with #{e.message}. #{e.backtrace.join("\n")})
)
send_error(e.message)
# TODO: Should we re-raise the exception? As written this copy_remote_file has a false
# success.
end
write_file(f)
yield f
rescue StandardError => e
# OVERRIDE adding Rails.logger.error call
Rails.logger.error(
%(ImportUrlJob: Error copying <#{uri}> to #{dir} with #{e.message}. #{e.backtrace.join("\n")})
)
send_error(e.message)
# TODO: Should we re-raise the exception? As written this copy_remote_file has a false success.
end
Rails.logger.debug("ImportUrlJob: Copying <#{uri}> to #{dir}, closing #{File.join(dir, filename)}")
Rails.logger.debug("ImportUrlJob: Closing #{File.join(dir, filename)}")
end

# OVERRIDE there are calls to send_error that send two arguments.
Expand Down

0 comments on commit 51e17c9

Please sign in to comment.