Skip to content

Commit

Permalink
Transitions alternate_ids to emory_persistent_id. (#616)
Browse files Browse the repository at this point in the history
* 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
bwatson78 and alexBLR authored Nov 5, 2024
1 parent c55c3b9 commit 84859e2
Show file tree
Hide file tree
Showing 25 changed files with 202 additions and 67 deletions.
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def self.modified_field
# Emory Note: the fields are no longer dynamically delivered via this config setting.
# Instead, they are hard coded in views/hyrax/base/_attribute_rows.html.erb. We, in turn,
# have overridden tht partial so we can institute our own choices/order.
config.add_show_field "alternate_ids_ssim"
config.add_show_field "emory_persistent_id_ssi"
config.add_show_field "content_genre_tesi"
config.add_show_field "title_tesim"
config.add_show_field "creator_tesim"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/purl_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class PurlController < ApplicationController
def redirect_to_original
purl_object = Hyrax.custom_queries.find_by_alternate_id(alternate_ids: params[:alternate_ids])
purl_object = Hyrax.custom_queries.find_by_emory_persistent_id(emory_persistent_id: params[:emory_persistent_id])

if purl_object.work?
object_url = "#{request.base_url}/concern/publications/#{purl_object.id}"
Expand Down
15 changes: 4 additions & 11 deletions app/indexers/collection_resource_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ class CollectionResourceIndexer < Hyrax::PcdmCollectionIndexer
include Hyrax::Indexer(:collection_resource)

# Uncomment this block if you want to add custom indexing behavior:
def to_solr
super.tap do |index_document|
index_document[:alternate_ids_ssim] = find_alternate_ids
end
end

private

def find_alternate_ids
resource.alternate_ids.map(&:id)
end
# def to_solr
# super.tap do |index_document|
# end
# end
end
5 changes: 0 additions & 5 deletions app/indexers/publication_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def to_solr
index_document[:failed_preservation_events_ssim] = failed_preservation_events
index_document[:preservation_events_tesim] = resource&.preservation_events&.map(&:preservation_event_terms)
index_document[:preservation_workflow_terms_tesim] = preservation_workflow_terms
index_document[:alternate_ids_ssim] = find_alternate_ids
index_document[:all_text_tsimv] = resource&.primary_file_set&.extracted_text_content
index_document[:member_of_collections_ssim] = collection_names_for_facets
end
Expand All @@ -26,10 +25,6 @@ def failed_preservation_events
failures.map(&:failed_event_json)
end

def find_alternate_ids
resource.alternate_ids.map(&:id)
end

def preservation_workflow_terms
resource.preservation_workflows.map(&:preservation_terms)
end
Expand Down
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 app/services/self_deposit/custom_queries/find_by_alternate_id.rb

This file was deleted.

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 app/services/self_deposit/valkyrie_object_remediation_service.rb
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
4 changes: 2 additions & 2 deletions app/views/hyrax/base/_purl.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<dt>Persistent URL</dt>
<dd>
<ul class="tabular">
<% if presenter.solr_document['alternate_ids_ssim'].present? %>
<% url = "#{request.base_url}/purl/#{presenter.solr_document['alternate_ids_ssim'].first}" %>
<% if presenter.solr_document['emory_persistent_id_ssi'].present? %>
<% url = "#{request.base_url}/purl/#{presenter.solr_document['emory_persistent_id_ssi']}" %>
<li><a href="<%= url %>"><%= url %></a></li>
<% else %>
<li>No alternate ID available</li>
Expand Down
6 changes: 3 additions & 3 deletions app/views/hyrax/collections/_show_descriptions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<div class='metadata-line'>
<div class='col-xs-12 col-sm-4'><dt >Persistent URL</dt></div>
<div class='col-xs-12 col-sm-8'><dd>
<% if @presenter.solr_document['alternate_ids_ssim'].present? %>
<% url = "#{request.base_url}/purl/#{@presenter.solr_document['alternate_ids_ssim'].first}" %>
<% if @presenter.solr_document['emory_persistent_id_ssi'].present? %>
<% url = "#{request.base_url}/purl/#{@presenter.solr_document['emory_persistent_id_ssi']}" %>
<a href="<%= url %>"><%= url %></a>
<% else %>
No alternate ID available
Expand All @@ -19,4 +19,4 @@
<div class='col-xs-12 col-sm-8'><dd><%= collection_metadata_value(@presenter, field_name) %></dd></div>
</div>
<% end %>
</dl>
</dl>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<div class='metadata-line'>
<div class='col-xs-12 col-sm-4'><dt >Persistent URL</dt></div>
<div class='col-xs-12 col-sm-8'><dd>
<% if @presenter.solr_document['alternate_ids_ssim'].present? %>
<% url = "#{request.base_url}/purl/#{@presenter.solr_document['alternate_ids_ssim'].first}" %>
<% if @presenter.solr_document['emory_persistent_id_ssi'].present? %>
<% url = "#{request.base_url}/purl/#{@presenter.solr_document['emory_persistent_id_ssi']}" %>
<a href="<%= url %>"><%= url %></a>
<% else %>
No alternate ID available
Expand All @@ -21,4 +21,4 @@
<dd class="col-7"><%= collection_metadata_value(@presenter, field_name) %></dd>
</div>
<% end %>
</dl>
</dl>
3 changes: 2 additions & 1 deletion config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,10 @@
Hyrax::CustomQueries::FindModelsByAccess,
Hyrax::CustomQueries::FindCountBy,
Hyrax::CustomQueries::FindByDateRange,
SelfDeposit::CustomQueries::FindAllObjectsWithAlternateIdsPresent,
SelfDeposit::CustomQueries::FindPublicationByDeduplicationKey,
SelfDeposit::CustomQueries::FindParentWorks,
SelfDeposit::CustomQueries::FindByAlternateId,
SelfDeposit::CustomQueries::FindByEmoryPersistentId,
SelfDeposit::CustomQueries::FindByCollectionTitle,
SelfDeposit::CustomQueries::FindBySourceIdentifier]
custom_queries.each do |handler|
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/hyrax_work_uploads_handler_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def file_set_args(file)
{ depositor: file.user.user_key,
creator: file.user.user_key,
date_uploaded: file.created_at,
alternate_ids: ["#{Noid::Rails::Service.new.mint}-emory"],
emory_persistent_id: "#{Noid::Rails::Service.new.mint}-emory",
date_modified: Hyrax::TimeService.time_in_utc,
label: file.fileset_name.presence || file.uploader.filename,
title: file.fileset_name.presence || file.uploader.filename,
Expand Down
6 changes: 6 additions & 0 deletions config/metadata/emory_basic_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ attributes:
index_keys:
- 'emory_ark_tesim'
predicate: http://id.loc.gov/vocabulary/identifiers/local#ark
emory_persistent_id:
type: string
multiple: false
index_keys:
- 'emory_persistent_id_ssi'
predicate: http://metadata.emory.edu/vocab/cor-terms#emoryPersistentId
holding_repository:
type: string
multiple: false
Expand Down
6 changes: 6 additions & 0 deletions config/metadata/emory_file_set_metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
attributes:
emory_persistent_id:
type: string
multiple: false
index_keys:
- 'emory_persistent_id_ssi'
predicate: http://metadata.emory.edu/vocab/cor-terms#emoryPersistentId
file_set_use:
type: string
multiple: false
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
mount Hyrax::Engine, at: '/'
resources :welcome, only: 'index'
root 'hyrax/homepage#index'
get 'purl/:alternate_ids', to: 'purl#redirect_to_original'
get 'purl/:emory_persistent_id', to: 'purl#redirect_to_original'
curation_concerns_basic_routes
concern :exportable, Blacklight::Routes::Exportable.new

Expand Down
14 changes: 7 additions & 7 deletions lib/hyrax/transactions/steps/set_noid_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ module Hyrax
module Transactions
module Steps
##
# A step that sets the `#collection_type_gid` in the change set.
# A step that sets the `#emory_persistent_id` in the change set.
#
# @since 3.2.0
class SetNoidId
include Dry::Monads[:result]

##
# @param [Hyrax::ChangeSet] change_set
# @param alternate_ids for the collection, file_set, publication
def call(change_set, alternate_ids: [new_noid_id])
return Failure[:no_alternate_ids, change_set] unless
change_set.respond_to?(:alternate_ids=)
# @param emory_persistent_id for the collection, file_set, publication
def call(change_set, emory_persistent_id: new_noid_id)
return Failure[:no_emory_persistent_id, change_set] unless
change_set.respond_to?(:emory_persistent_id=)
return Success(change_set) if
change_set.alternate_ids.present?
change_set.emory_persistent_id.present?

change_set.alternate_ids = alternate_ids
change_set.emory_persistent_id = emory_persistent_id
Hyrax.persister.save(resource: change_set)
Success(change_set)
end
Expand Down
11 changes: 11 additions & 0 deletions lib/tasks/valkyrie_object_remediation.rake
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
2 changes: 1 addition & 1 deletion spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RSpec.describe CatalogController, type: :controller do
include Devise::Test::ControllerHelpers

expected_show_fields = ["alternate_ids_ssim", "content_genre_tesi", "title_tesim", "creator_tesim",
expected_show_fields = ["emory_persistent_id_ssi", "content_genre_tesi", "title_tesim", "creator_tesim",
"language_tesim", "date_issued_tesi", "publisher_tesim", "publisher_version_tesi",
"parent_title_tesi", "conference_name_tesi", "issn_tesi", "isbn_tesi",
"series_title_tesi", "grant_agencies_tesim", "grant_information_tesim",
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/purl_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
let(:admin_set) { FactoryBot.valkyrie_create(:hyrax_admin_set) }
let(:permission_template) { FactoryBot.create(:permission_template, source_id: admin_set.id) }
let(:workflow) { FactoryBot.create(:workflow, allows_access_grant: true, active: true, permission_template_id: permission_template.id) }
let(:publication_alt_ids) { ['1234567-emory'] }
let!(:publication) { FactoryBot.valkyrie_create(:publication, with_index: true, admin_set_id: admin_set.id, depositor: user.user_key, alternate_ids: publication_alt_ids) }
let(:collection_alt_ids) { ['89abcef-emory'] }
let!(:collection) { FactoryBot.valkyrie_create(:hyrax_collection, alternate_ids: collection_alt_ids) }
let(:publication_alt_id) { '1234567-emory' }
let!(:publication) { FactoryBot.valkyrie_create(:publication, with_index: true, admin_set_id: admin_set.id, depositor: user.user_key, emory_persistent_id: publication_alt_id) }
let(:collection_alt_id) { '89abcef-emory' }
let!(:collection) { FactoryBot.valkyrie_create(:hyrax_collection, emory_persistent_id: collection_alt_id) }

before do
Hyrax.index_adapter.wipe!
Expand All @@ -25,7 +25,7 @@
context 'when purl_object is a Publication' do
it 'redirects to the publication URL' do
Hyrax.index_adapter.save(resource: publication)
get :redirect_to_original, params: { alternate_ids: publication_alt_ids.first }
get :redirect_to_original, params: { emory_persistent_id: publication_alt_id }

expect(response).to redirect_to("http://test.host/concern/publications/#{publication.id}")
end
Expand All @@ -34,15 +34,15 @@
context 'when purl_object is a Collection' do
it 'redirects to the collection URL' do
Hyrax.index_adapter.save(resource: collection)
get :redirect_to_original, params: { alternate_ids: collection_alt_ids.first }
get :redirect_to_original, params: { emory_persistent_id: collection_alt_id }

expect(response).to redirect_to("http://test.host/collections/#{collection.id}")
end
end

context 'when purl_object is not found' do
before do
get :redirect_to_original, params: { alternate_ids: admin_set.id }
get :redirect_to_original, params: { emory_persistent_id: admin_set.id }
end

it 'returns a 404 not found status' do
Expand Down
25 changes: 25 additions & 0 deletions spec/hyrax/transactions/steps/set_noid_id_spec.rb
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
8 changes: 4 additions & 4 deletions spec/indexers/collection_resource_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
it_behaves_like 'a Hyrax::Resource indexer'
it_behaves_like 'a Basic metadata indexer'

context 'alternate_ids_ssim' do
let(:alternate_ids) { [double(id: 'alt_id_1'), double(id: 'alt_id_2')] }
context 'emory_persistent_id_ssi' do
let(:emory_persistent_id) { 'alt_id_1' }

before do
allow(resource).to receive(:alternate_ids).and_return(alternate_ids)
allow(resource).to receive(:emory_persistent_id).and_return(emory_persistent_id)
end

it 'contains an array of alternate IDs' do
expect(indexer.to_solr['alternate_ids_ssim']).to eq(['alt_id_1', 'alt_id_2'])
expect(indexer.to_solr['emory_persistent_id_ssi']).to eq('alt_id_1')
end
end
end
Loading

0 comments on commit 84859e2

Please sign in to comment.