-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move valkyrie resource migration code from hyku to hyrax (#6973)
* move valkyrie resource migration code from hyku to hyrax * prevent works from becoming inaccessible during valkyrie transition * more cross compatible fix for collection thumbnail issue * make adminset wings identifiable
- Loading branch information
1 parent
8548a92
commit a9c8e9c
Showing
10 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
# migrates models from AF to valkyrie | ||
class MigrateResourcesJob < ApplicationJob | ||
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(ids: [], models: ['AdminSet', 'Collection']) | ||
if ids.blank? | ||
models.each do |model| | ||
model.constantize.find_each do |item| | ||
migrate(item.id) | ||
end | ||
end | ||
else | ||
ids.each do |id| | ||
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) | ||
return unless resource.wings? # this resource has already been converted | ||
result = MigrateResourceService.new(resource: resource).call | ||
errors << result unless result.success? | ||
result | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
# migrates models from AF to valkyrie | ||
class MigrateResourceService | ||
attr_accessor :resource | ||
def initialize(resource:) | ||
@resource = resource | ||
end | ||
|
||
def model | ||
@model || Wings::ModelRegistry.lookup(resource.class).to_s | ||
end | ||
|
||
def call | ||
prep_resource | ||
Hyrax::Transactions::Container[model_events(model)] | ||
.with_step_args(**model_steps(model)).call(resource_form) | ||
end | ||
|
||
def prep_resource | ||
case model | ||
when 'FileSet' | ||
resource.creator << ::User.batch_user.email if resource.creator.blank? | ||
end | ||
end | ||
|
||
def resource_form | ||
@resource_form ||= Hyrax::Forms::ResourceForm.for(resource: resource) | ||
end | ||
|
||
def model_events(model) | ||
{ | ||
'AdminSet' => 'admin_set_resource.update', | ||
'Collection' => 'change_set.update_collection', | ||
'FileSet' => 'change_set.update_file_set' | ||
}[model] || 'change_set.update_work' | ||
end | ||
|
||
def model_steps(model) | ||
{ | ||
'AdminSet' => {}, | ||
'Collection' => { | ||
'collection_resource.save_collection_banner' => { banner_unchanged_indicator: true }, | ||
'collection_resource.save_collection_logo' => { logo_unchanged_indicator: true } | ||
}, | ||
'FileSet' => { | ||
'file_set.save_acl' => {} | ||
} | ||
}[model] || { | ||
'work_resource.add_file_sets' => { uploaded_files: [], file_set_params: [] }, | ||
'work_resource.update_work_members' => { work_members_attributes: [] }, | ||
'work_resource.save_acl' => { permissions_params: [] } | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'freyja/persister' | ||
RSpec.describe MigrateResourcesJob, index_adapter: :solr_index, valkyrie_adapter: :freyja_adapter do | ||
let(:af_file_set) { create(:file_set, title: ['TestFS']) } | ||
|
||
let!(:af_admin_set) do | ||
as = AdminSet.new(title: ['AF Admin Set']) | ||
as.save | ||
AdminSet.find(as.id) | ||
end | ||
|
||
describe '#perform' do | ||
it "migrates admin sets to valkyrie", active_fedora_to_valkyrie: true do | ||
expect(Valkyrie::Persistence::Postgres::ORM::Resource.find_by(id: af_admin_set.id.to_s)).to be_nil | ||
|
||
MigrateResourcesJob.perform_now(ids: [af_admin_set.id]) | ||
expect(Valkyrie::Persistence::Postgres::ORM::Resource.find_by(id: af_admin_set.id.to_s)).to be_present | ||
end | ||
|
||
it "migrates a file set by its id", active_fedora_to_valkyrie: true do | ||
expect(Valkyrie::Persistence::Postgres::ORM::Resource.find_by(id: af_file_set.id.to_s)).to be_nil | ||
|
||
MigrateResourcesJob.perform_now(ids: [af_file_set.id]) | ||
|
||
expect(Valkyrie::Persistence::Postgres::ORM::Resource.find_by(id: af_file_set.id.to_s)).to be_present | ||
end | ||
end | ||
end |