Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
embargo_metadata_indexer uses cocina data instead of active-fedora
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Mar 24, 2021
1 parent 603ff72 commit c524843
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 65 deletions.
26 changes: 5 additions & 21 deletions app/indexers/embargo_metadata_indexer.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
# frozen_string_literal: true

class EmbargoMetadataIndexer
attr_reader :resource, :cocina
attr_reader :cocina

def initialize(resource:, cocina:, **)
@resource = resource
def initialize(cocina:, **)
@cocina = cocina
end

# These fields are used by the EmbargoReleaseService in dor-services-app
# @return [Hash] the partial solr document for embargoMetadata
def fedora_to_solr
{
'embargo_status_ssim' => embargo_status
}.tap do |solr_doc|
solr_doc['embargo_release_dtsim'] = Array(release_date.first.utc.strftime('%FT%TZ')) if release_date.first.present?
end
end

def cocina_to_solr
def to_solr
{}.tap do |solr_doc|
embargo_release_date = embargo_release_date(cocina)
if is_future?(embargo_release_date)
if future?(embargo_release_date)
solr_doc['embargo_status_ssim'] = ['embargoed']
solr_doc['embargo_release_dtsim'] = [embargo_release_date.utc.strftime('%FT%TZ')]
end
end
end
alias_method :to_solr, :cocina_to_solr

# rubocop:disable Lint/UselessAccessModifier
private

# rubocop:enable Lint/UselessAccessModifier

delegate :embargoMetadata, to: :resource
delegate :embargo_status, :release_date, to: :embargoMetadata

def embargo_release_date(cocina)
cocina.access.embargo.releaseDate if cocina.access.embargo&.releaseDate.present?
end

def is_future?(embargo_release_date)
def future?(embargo_release_date)
return false unless embargo_release_date

embargo_release_date > DateTime.now
Expand Down
48 changes: 4 additions & 44 deletions spec/indexers/embargo_metadata_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@
require 'rails_helper'

RSpec.describe EmbargoMetadataIndexer do
let(:xml) do
<<~XML
<?xml version="1.0"?>
<embargoMetadata>
<status>embargoed</status>
<releaseDate>2011-10-12T15:47:52-07:00</releaseDate>
<releaseAccess>
<access type="discover">
<machine>
<world />
</machine>
</access>
<access type="read">
<machine>
<world />
</machine>
</access>
</releaseAccess>
</embargoMetadata>
XML
end

let(:obj) { Dor::Item.new }
let(:apo_id) { 'druid:gf999hb9999' }
let(:druid) { 'druid:zz666yy9999' }
let(:release_date) { '2024-06-06' }
Expand All @@ -50,29 +27,16 @@
'hasAdminPolicy' => apo_id
},
'description' => {
'title' => [{ 'value' => 'embargo indexing object'}]
'title' => [{ 'value' => 'embargo indexing object' }]
}
)
end

let(:indexer) do
described_class.new(resource: obj, cocina: cocina)
end

before do
obj.embargoMetadata.content = xml
end

describe '#fedora_to_solr' do
subject(:doc) { indexer.fedora_to_solr }

it 'has the fields used by dor-services-app' do
expect(doc).to eq('embargo_release_dtsim' => ['2011-10-12T22:47:52Z'],
'embargo_status_ssim' => ['embargoed'])
end
described_class.new(cocina: cocina)
end

describe '#cocina_to_solr' do
describe '#to_solr' do
subject(:doc) { indexer.to_solr }

context 'when embargo.releaseDate is in the future' do
Expand Down Expand Up @@ -109,7 +73,7 @@
'hasAdminPolicy' => apo_id
},
'description' => {
'title' => [{ 'value' => 'embargo indexing object'}]
'title' => [{ 'value' => 'embargo indexing object' }]
}
)
end
Expand All @@ -119,8 +83,4 @@
end
end
end

# embargo_status -- in view
# embargo_release_date facet field

end

0 comments on commit c524843

Please sign in to comment.