Skip to content

Commit

Permalink
call the cops
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf committed Nov 9, 2024
1 parent b737ba2 commit dd10886
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
26 changes: 16 additions & 10 deletions app/jobs/migrate_resources_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@

# migrates models from AF to valkyrie
class MigrateResourcesJob < ApplicationJob
attr_accessor :errors
attr_writer :errors
# input [Array>>String] Array of ActiveFedora model names to migrate to valkyrie objects
# defaults to AdminSet & Collection models if empty
def perform(models: ['AdminSet', 'Collection'], ids: [])
errors = []
if ids.blank?
models.each do |model|
model.constantize.find_each do |item|
resource = Hyrax.query_service.find_by(id: item.id)
result = MigrateResourceService.new(resource: resource).call
errors << result unless result.success?
migrate(item.id)
end
end
else
ids.each do |id|
resource = Hyrax.query_service.find_by(id: id)
next unless resource.wings? # this resource has already been converted
result = MigrateResourceService.new(resource: resource).call
errors << result unless result.success?
end
migrate(id)
end
end
raise errors.inspect if errors.present?
end

def errors
@errors ||= []
end

def migrate(id)
resource = Hyrax.query_service.find_by(id: id)
next unless resource.wings? # this resource has already been converted
result = MigrateResourceService.new(resource: resource).call
errors << result unless result.success?
result
end
end
2 changes: 1 addition & 1 deletion app/models/hyrax/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def work?

# Its nice to know if a record is still in AF or not
def wings?
self.respond_to?(:head) && self.respond_to?(:tail)
respond_to?(:head) && respond_to?(:tail)
end

def ==(other)
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/migrate_resources_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
clear_enqueued_jobs
end

let(:account) { create(:account_with_public_schema) }
let(:af_file_set) { create(:file_set, title: ['TestFS']) }
let(:account) { create(:account_with_public_schema) }
let(:af_file_set) { create(:file_set, title: ['TestFS']) }

let!(:af_admin_set) do
as = AdminSet.new(title: ['AF Admin Set'])
Expand Down

0 comments on commit dd10886

Please sign in to comment.