Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix OAI importers #102

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 12 additions & 14 deletions app/jobs/import_url_job_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# 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)
begin
File.open(File.join(dir, filename), 'wb') do |f|
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
rescue StandardError => e
Rails.logger.error(
%(ImportUrlJob: Error copying <#{uri}> to #{dir} with #{e.message}. #{e.backtrace.join("\n")})
)
send_error(e.message)
# TODO: Consider re-raising the exception if needed
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.