From c76132f53a21a21912c9a9e88d2be0104818e051 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Thu, 6 Mar 2025 00:58:12 -0500 Subject: [PATCH] Lazy migrate sipity entity with work When lazy migration is used, the sipity entity cannot be found for works which are not yet migrated. Valkyrie resources have a `proxy_for_global_id` with the format: `gid://hyku/Hyrax::ValkyrieGlobalIdProxy/2f6da5dd-9314-421f-b0dd-fda84fec9ee3` while prior works used the model name such as: `gid://hyku/GenericWork/2f6da5dd-9314-421f-b0dd-fda84fec9ee3`. This commit introduces a lazy migration of the sipity entity via a job which is submitted after a work is migrated to valkyrie via the Freyja persister. Prior work in pull request https://github.com/samvera/hyku/pull/2471 added some overrides in Hyku to resolve the sipity entity issues. These changes still needs to be backported. The prior work includes these changes: The MigrateResourceService introduced a migration of the entity along with the work's migration. This service is needed for direct migration calls, but is not adequate for lazy migration, as the Freyja persister does not call it for the work itself that was just migrated. Hyku overrides to sipity.rb support cases where the entity is not yet migrated and lazy migration is in use. This is necessary because the solr_document is used to find the Sipity::Entity. Due to the model mapping found in the solr document, the Entity method searches for the entity with the model name. This is problematic when the entity is not yet migrated and the entity is searched with a GenericWorkResource model rather than the model. --- app/jobs/migrate_sipity_entity_job.rb | 15 +++++++++++++++ lib/freyja/persister.rb | 1 + 2 files changed, 16 insertions(+) create mode 100644 app/jobs/migrate_sipity_entity_job.rb diff --git a/app/jobs/migrate_sipity_entity_job.rb b/app/jobs/migrate_sipity_entity_job.rb new file mode 100644 index 0000000000..fea9b51b9a --- /dev/null +++ b/app/jobs/migrate_sipity_entity_job.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# migrates a resource's sipity entity so it can be found +class MigrateSipityEntityJob < ApplicationJob + # input [String] id of a migrated resource + def perform(id:) + resource = Hyrax.query_service.find_by(id: id) + new_gid = Hyrax::GlobalID(resource).to_s + work = resource.internal_resource.constantize.find(id) + original_gid = Hyrax::GlobalID(work).to_s + return if new_gid == original_gid + original_entity = Sipity::Entity.find_by(proxy_for_global_id: original_gid) + original_entity.update(proxy_for_global_id: new_gid) + end +end diff --git a/lib/freyja/persister.rb b/lib/freyja/persister.rb index e0547c1e9c..79b4fd1dcb 100644 --- a/lib/freyja/persister.rb +++ b/lib/freyja/persister.rb @@ -38,6 +38,7 @@ def convert_and_migrate_resource(orm_object) if new_resource.is_a?(Hyrax::Work) member_ids = new_resource.member_ids.map(&:to_s) MigrateResourcesJob.perform_later(ids: member_ids) unless member_ids.empty? + MigrateSipityEntityJob.perform_later(id: new_resource.id) end end new_resource