From dd10886a3e4840aec99617a43b9ba5a93c9d899f Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Fri, 8 Nov 2024 16:30:34 -0800 Subject: [PATCH] call the cops --- app/jobs/migrate_resources_job.rb | 26 +++++++++++++++---------- app/models/hyrax/resource.rb | 2 +- spec/jobs/migrate_resources_job_spec.rb | 4 ++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/jobs/migrate_resources_job.rb b/app/jobs/migrate_resources_job.rb index 128f757793..6f43559b74 100644 --- a/app/jobs/migrate_resources_job.rb +++ b/app/jobs/migrate_resources_job.rb @@ -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 diff --git a/app/models/hyrax/resource.rb b/app/models/hyrax/resource.rb index 766c5091d7..176f900848 100644 --- a/app/models/hyrax/resource.rb +++ b/app/models/hyrax/resource.rb @@ -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) diff --git a/spec/jobs/migrate_resources_job_spec.rb b/spec/jobs/migrate_resources_job_spec.rb index 4eb7102f3d..2734509e26 100644 --- a/spec/jobs/migrate_resources_job_spec.rb +++ b/spec/jobs/migrate_resources_job_spec.rb @@ -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'])