Skip to content

Commit be530c4

Browse files
author
LaRita Robinson
committed
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 samvera/hyku#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.
1 parent d4b8f81 commit be530c4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

app/jobs/migrate_sipity_entity_job.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
# migrates a resource's sipity entity so it can be found
4+
class MigrateSipityEntityJob < ApplicationJob
5+
# input [String] id of a migrated resource
6+
def perform(id:)
7+
resource = Hyrax.query_service.find_by(id: id)
8+
new_gid = Hyrax::GlobalID(resource).to_s
9+
work = resource.internal_resource.constantize.find(id)
10+
original_gid = Hyrax::GlobalID(work).to_s
11+
return if new_gid == original_gid
12+
original_entity = Sipity::Entity.find_by(proxy_for_global_id: original_gid)
13+
original_entity.update(proxy_for_global_id: new_gid)
14+
end
15+
end

lib/freyja/persister.rb

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def convert_and_migrate_resource(orm_object)
3838
if new_resource.is_a?(Hyrax::Work)
3939
member_ids = new_resource.member_ids.map(&:to_s)
4040
MigrateResourcesJob.perform_later(ids: member_ids) unless member_ids.empty?
41+
MigrateSipityEntityJob.perform_later(id: new_resource.id)
4142
end
4243
end
4344
new_resource

0 commit comments

Comments
 (0)