-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transitions alternate_ids to emory_persistent_id. (#616)
* Transitions alternate_ids to emory_persistent_id. * Add a little spec. * Add a little more spec. * Rubo happiness. --------- Co-authored-by: Alex Zotov <[email protected]>
- Loading branch information
Showing
25 changed files
with
202 additions
and
67 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
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
37 changes: 37 additions & 0 deletions
37
app/services/self_deposit/custom_queries/find_all_objects_with_alternate_ids_present.rb
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,37 @@ | ||
# frozen_string_literal: true | ||
module SelfDeposit | ||
module CustomQueries | ||
# @example | ||
# | ||
# Hyrax.custom_queries.find_all_objects_with_alternate_ids_present | ||
# | ||
# @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries | ||
class FindAllObjectsWithAlternateIdsPresent | ||
def self.queries | ||
[:find_all_objects_with_alternate_ids_present] | ||
end | ||
|
||
def initialize(query_service:) | ||
@query_service = query_service | ||
end | ||
|
||
attr_reader :query_service | ||
|
||
## | ||
# @return enumerator of Valkyrie Fedora objects | ||
def find_all_objects_with_alternate_ids_present | ||
enum_for(:each) | ||
end | ||
|
||
# Queries the Solr index for parent works of the provided resource | ||
# For each Document, it yields the pulled Hyrax Work object | ||
# @yield [Valkyrie::Resources] | ||
def each | ||
objects = @query_service.find_all | ||
objects.each do |obj| | ||
yield obj if obj.respond_to?(:alternate_ids) && obj.alternate_ids.present? | ||
end | ||
end | ||
end | ||
end | ||
end |
14 changes: 0 additions & 14 deletions
14
app/services/self_deposit/custom_queries/find_by_alternate_id.rb
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
app/services/self_deposit/custom_queries/find_by_emory_persistent_id.rb
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,14 @@ | ||
# frozen_string_literal: true | ||
class SelfDeposit::CustomQueries::FindByEmoryPersistentId < ::SelfDeposit::CustomQueries::SolrDocumentQuery | ||
self.queries = [:find_by_emory_persistent_id] | ||
|
||
def find_by_emory_persistent_id(emory_persistent_id:) | ||
@emory_persistent_id = emory_persistent_id | ||
raise ::Valkyrie::Persistence::ObjectNotFoundError unless resource | ||
@query_service.find_by(id: resource['id']) | ||
end | ||
|
||
def query | ||
"emory_persistent_id_ssi:#{@emory_persistent_id}" | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
app/services/self_deposit/valkyrie_object_remediation_service.rb
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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module SelfDeposit | ||
class ValkyrieObjectRemediationService | ||
def self.migrate_alternate_ids_to_emory_persistent_id | ||
operating_ids = pull_operating_ids | ||
process_objects_with_alternate_ids | ||
operating_ids | ||
end | ||
|
||
class << self | ||
private | ||
|
||
def objects_with_alternate_ids | ||
Hyrax.custom_queries.find_all_objects_with_alternate_ids_present | ||
end | ||
|
||
def pull_operating_ids | ||
objects_with_alternate_ids.map(&:id).join(', ') | ||
end | ||
|
||
def process_objects_with_alternate_ids | ||
objects_with_alternate_ids.each do |obj| | ||
value_in_alternate_ids = obj.alternate_ids.map(&:to_s).first | ||
obj.emory_persistent_id = value_in_alternate_ids if obj.emory_persistent_id.blank? | ||
obj.alternate_ids = [] | ||
Hyrax.persister.save(resource: obj) | ||
end | ||
end | ||
end | ||
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
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
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,11 @@ | ||
# frozen_string_literal: true | ||
namespace :selfdeposit do | ||
namespace :valkyrie_object_remediation do | ||
desc "Moves 'alternate_ids' values to 'emory_persistent_id'." | ||
task migrate_alternate_ids_to_emory_persistent_id: :environment do | ||
operating_ids = ::SelfDeposit::ValkyrieObjectRemediationService.migrate_alternate_ids_to_emory_persistent_id | ||
|
||
puts "Valkyrie object IDs remediated: #{operating_ids}" | ||
end | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
require 'hyrax/transactions' | ||
|
||
RSpec.describe Hyrax::Transactions::Steps::SetNoidId do | ||
subject(:step) { described_class.new } | ||
let(:publication) { FactoryBot.valkyrie_create(:publication) } | ||
|
||
describe '#call' do | ||
context 'without a passed ID' do | ||
it 'is a success' do | ||
expect(step.call(publication)).to be_success | ||
expect(publication.emory_persistent_id).to be_present | ||
end | ||
end | ||
|
||
context 'with a passed ID' do | ||
let(:fake_id) { '123jkdcjh-emory' } | ||
it 'is a success' do | ||
expect(step.call(publication, emory_persistent_id: fake_id)).to be_success | ||
expect(publication.emory_persistent_id).to eq(fake_id) | ||
end | ||
end | ||
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
Oops, something went wrong.