Skip to content

Commit 51e17c9

Browse files
author
Kirk Wang
committed
🐛 Fix OAI importers
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
1 parent 2b50ce5 commit 51e17c9

File tree

3 files changed

+53
-198
lines changed

3 files changed

+53
-198
lines changed

app/actors/hyrax/actors/file_set_actor.rb

Lines changed: 0 additions & 183 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# frozen_string_literal: true
2+
3+
# OVERRIDE Hyrax 3.5.0 to override default_thumbnail
4+
5+
module Hyrax
6+
module Actors
7+
module FileSetActorDecorator
8+
def attach_to_valkyrie_work(work, file_set_params)
9+
work = Hyrax.query_service.find_by(id: work.id) unless work.new_record
10+
file_set.visibility = work.visibility unless assign_visibility?(file_set_params)
11+
fs = Hyrax.persister.save(resource: file_set)
12+
Hyrax.publisher.publish('object.metadata.updated', object: fs, user: user)
13+
work.member_ids << fs.id
14+
work.representative_id = fs.id if work.representative_id.blank?
15+
# OVERRIDE Hyrax 3.5.0 to override default_thumbnail
16+
work.thumbnail = file_set if file_set.override_default_thumbnail == 'true' || work.thumbnail_id.blank?
17+
18+
# Save the work so the association between the work and the file_set is persisted (head_id)
19+
# NOTE: the work may not be valid, in which case this save doesn't do anything.
20+
Hyrax.persister.save(resource: work)
21+
Hyrax.publisher.publish('object.metadata.updated', object: work, user: user)
22+
end
23+
24+
# Adds a FileSet to the work using ore:Aggregations.
25+
def attach_to_af_work(work, file_set_params)
26+
work.reload unless work.new_record?
27+
file_set.visibility = work.visibility unless assign_visibility?(file_set_params)
28+
work.ordered_members << file_set
29+
work.representative = file_set if work.representative_id.blank?
30+
# OVERRIDE Hyrax 3.5.0 to override default_thumbnail
31+
work.thumbnail = file_set if file_set.override_default_thumbnail == 'true' || work.thumbnail_id.blank?
32+
33+
# Save the work so the association between the work and the file_set is persisted (head_id)
34+
# NOTE: the work may not be valid, in which case this save doesn't do anything.
35+
work.save
36+
end
37+
end
38+
end
39+
end
40+
41+
Hyrax::Actors::FileSetActor.prepend Hyrax::Actors::FileSetActorDecorator

app/jobs/import_url_job_decorator.rb

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
# frozen_string_literal: true
22

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

1111
File.open(File.join(dir, filename), 'wb') do |f|
12-
begin
13-
write_file(uri, f, headers)
14-
yield f
15-
rescue StandardError => e
16-
# OVERRIDE adding Rails.logger.error call
17-
Rails.logger.error(
18-
%(ImportUrlJob: Error copying <#{uri}> to #{dir} with #{e.message}. #{e.backtrace.join("\n")})
19-
)
20-
send_error(e.message)
21-
# TODO: Should we re-raise the exception? As written this copy_remote_file has a false
22-
# success.
23-
end
12+
write_file(f)
13+
yield f
14+
rescue StandardError => e
15+
# OVERRIDE adding Rails.logger.error call
16+
Rails.logger.error(
17+
%(ImportUrlJob: Error copying <#{uri}> to #{dir} with #{e.message}. #{e.backtrace.join("\n")})
18+
)
19+
send_error(e.message)
20+
# TODO: Should we re-raise the exception? As written this copy_remote_file has a false success.
2421
end
25-
Rails.logger.debug("ImportUrlJob: Copying <#{uri}> to #{dir}, closing #{File.join(dir, filename)}")
22+
Rails.logger.debug("ImportUrlJob: Closing #{File.join(dir, filename)}")
2623
end
2724

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

0 commit comments

Comments
 (0)