Skip to content

Commit

Permalink
Merge pull request #5135 from sul-dlss/t5117-shelve_check
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Jul 24, 2024
2 parents c6e8518 + 4e03a3c commit 3fda083
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/services/digital_stacks_differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def bare_druid
end

def purl_file_md5s
@purl_file_md5s ||= purl_fetcher_reader.files_by_digest(bare_druid).map { |md5_file| md5_file.keys.first }
@purl_file_md5s ||= purl_fetcher_reader.files_by_digest(bare_druid).map { |md5_file| md5_file.keys.first }.uniq
rescue PurlFetcher::Client::NotFoundResponseError
[]
rescue PurlFetcher::Client::ResponseError => e
Expand Down
7 changes: 7 additions & 0 deletions app/services/publish/metadata_transfer_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def publish
return publish_delete_on_success unless discoverable?

publish_shelve
check_stacks if public_cocina.dro?
republish_virtual_object_constituents!
release_tags_on_success
end
Expand Down Expand Up @@ -78,6 +79,12 @@ def publish_shelve
must_version: must_version?, version_date:)
end

def check_stacks
missing_filepaths = DigitalStacksDiffer.call(cocina_object: public_cocina)

raise "Files are missing from stacks: #{missing_filepaths}" if missing_filepaths.present?
end

def filepaths_to_shelve
@filepaths_to_shelve ||= public_cocina.dro? ? DigitalStacksDiffer.call(cocina_object: public_cocina) : []
end
Expand Down
56 changes: 52 additions & 4 deletions spec/services/publish/metadata_transfer_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@
before do
repository_object_version = create(:repository_object_version, :with_repository_object, external_identifier: druid, closed_at:, structural:)
repository_object_version.repository_object.open_version!(description: 'This is a draft repository object version; it should not be used.')
allow(DigitalStacksDiffer).to receive(:call).and_return(['00001.html'])
allow(DigitalStacksDiffer).to receive(:call).and_return(['00001.html'], [])
allow(ShelvableFilesStager).to receive(:stage)
allow(SecureRandom).to receive(:uuid).and_return(uuid)
end

it 'publishes the item' do
described_class.publish(druid:)

expect(DigitalStacksDiffer).to have_received(:call).with(cocina_object: public_cocina)
expect(DigitalStacksDiffer).to have_received(:call).with(cocina_object: public_cocina).twice
expect(ShelvableFilesStager).to have_received(:stage).with(druid:,
version: 1, filepaths: ['00001.html'],
workspace_content_pathname: Pathname.new('tmp/dor/workspace/bc/123/df/4567/bc123df4567/content'))
Expand Down Expand Up @@ -183,15 +183,15 @@
before do
repository_object_version = create(:repository_object_version, :with_repository_object, external_identifier: druid, closed_at:, structural:)
create(:user_version, repository_object_version:, version: 2)
allow(DigitalStacksDiffer).to receive(:call).and_return(['00001.html'])
allow(DigitalStacksDiffer).to receive(:call).and_return(['00001.html'], [])
allow(ShelvableFilesStager).to receive(:stage)
allow(SecureRandom).to receive(:uuid).and_return(uuid)
end

it 'publishes the item' do
described_class.publish(druid:)

expect(DigitalStacksDiffer).to have_received(:call).with(cocina_object: public_cocina)
expect(DigitalStacksDiffer).to have_received(:call).with(cocina_object: public_cocina).twice
expect(ShelvableFilesStager).to have_received(:stage).with(druid:,
version: 1, filepaths: ['00001.html'],
workspace_content_pathname: Pathname.new('tmp/dor/workspace/bc/123/df/4567/bc123df4567/content'))
Expand Down Expand Up @@ -254,5 +254,53 @@
expect(PurlFetcher::Client::ReleaseTags).to have_received(:release).with(druid:, index: ['Searchworks'], delete: ['Earthworks'])
end
end

context 'when a file missing from shelves' do
let(:public_cocina) { instance_double(Cocina::Models::DRO, externalIdentifier: druid, dro?: true) }

let(:structural) do
{ contains: [
{
type: Cocina::Models::FileSetType.file,
externalIdentifier: 'https://cocina.sul.stanford.edu/fileSet/123-456-789', label: 'Page 1', version: 1,
structural: {
contains: [
{
type: Cocina::Models::ObjectType.file,
externalIdentifier: 'https://cocina.sul.stanford.edu/file/123-456-789',
label: '00001.html',
filename: '00001.html',
size: 0,
version: 1,
hasMimeType: 'text/html',
use: 'transcription',
hasMessageDigests: [
{
type: 'sha1', digest: 'cb19c405f8242d1f9a0a6180122dfb69e1d6e4c7'
}, {
type: 'md5', digest: 'e6d52da47a5ade91ae31227b978fb023'
}
],
access: { view: 'world', download: 'world' },
administrative: { publish: true, sdrPreserve: true, shelve: true }
}
]
}
}
] }
end

before do
repository_object_version = create(:repository_object_version, :with_repository_object, external_identifier: druid, closed_at:, structural:)
repository_object_version.repository_object.open_version!(description: 'This is a draft repository object version; it should not be used.')
allow(DigitalStacksDiffer).to receive(:call).and_return(['00001.html'])
allow(ShelvableFilesStager).to receive(:stage)
allow(SecureRandom).to receive(:uuid).and_return(uuid)
end

it 'raises' do
expect { described_class.publish(druid:) }.to raise_error('Files are missing from stacks: ["00001.html"]')
end
end
end
end

0 comments on commit 3fda083

Please sign in to comment.