Skip to content

Commit

Permalink
Merge pull request #5847 from samvera/embargo-index-valk
Browse files Browse the repository at this point in the history
index embargoes and leases when using valkyrie infrastructure
  • Loading branch information
dlpierce authored Sep 9, 2022
2 parents 066e828 + 8771dfe commit 0539d4e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/indexers/hyrax/valkyrie_work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met
solr_doc['depositor_tesim'] = [resource.depositor]
solr_doc['hasRelatedMediaFragment_ssim'] = [resource.representative_id.to_s]
solr_doc['hasRelatedImage_ssim'] = [resource.thumbnail_id.to_s]
index_embargo(solr_doc)
index_lease(solr_doc)
end
end

Expand All @@ -39,5 +41,24 @@ def admin_set_label(resource)
admin_set = Hyrax.query_service.find_by(id: resource.admin_set_id)
admin_set.title
end

def index_embargo(doc)
if Hyrax::EmbargoManager.new(resource: resource).under_embargo?
doc['embargo_release_date_dtsi'] = resource.embargo.embargo_release_date&.to_datetime
doc['visibility_after_embargo_ssim'] = resource.embargo.visibility_after_embargo
doc['visibility_during_embargo_ssim'] = resource.embargo.visibility_during_embargo
end
doc
end

def index_lease(doc)
if Hyrax::LeaseManager.new(resource: resource).under_lease?
doc['lease_expiration_date_dtsi'] = resource.lease.lease_expiration_date&.to_datetime
doc['visibility_after_lease_ssim'] = resource.lease.visibility_after_lease
doc['visibility_during_lease_ssim'] = resource.lease.visibility_during_lease
end

doc
end
end
end
31 changes: 31 additions & 0 deletions spec/indexers/hyrax/valkyrie_work_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,36 @@ def to_solr
expect(solr_document.fetch('suppressed_bsi')).to be false
end
end

context 'when work is under embargo' do
let(:work) { FactoryBot.valkyrie_create(:hyrax_work, embargo: embargo) }
let(:embargo) { FactoryBot.valkyrie_create(:hyrax_embargo) }

it 'indexes the embargo visibilities' do
expect(service.to_solr)
.to include('visibility_after_embargo_ssim' => embargo.visibility_after_embargo,
'visibility_during_embargo_ssim' => embargo.visibility_during_embargo)
end

it 'indexes the embargo release date' do
expect(service.to_solr)
.to include('embargo_release_date_dtsi' => embargo.embargo_release_date.to_datetime)
end
end

context 'when work is under lease' do
let(:work) { FactoryBot.valkyrie_create(:hyrax_work, lease: lease) }
let(:lease) { FactoryBot.valkyrie_create(:hyrax_lease) }

it 'indexes the lease visibilities' do
expect(service.to_solr).to include('visibility_after_lease_ssim' => lease.visibility_after_lease,
'visibility_during_lease_ssim' => lease.visibility_during_lease)
end

it 'indexes the lease expiration date' do
expect(service.to_solr)
.to include('lease_expiration_date_dtsi' => lease.lease_expiration_date.to_datetime)
end
end
end
end

0 comments on commit 0539d4e

Please sign in to comment.