From 4e03a3c64240d14c5ab6a36c7cf403448bcb081b Mon Sep 17 00:00:00 2001 From: Justin Littman Date: Wed, 24 Jul 2024 09:26:29 -0400 Subject: [PATCH] Check that shelving was successful. closes #5117 --- app/services/digital_stacks_differ.rb | 2 +- .../publish/metadata_transfer_service.rb | 7 +++ .../publish/metadata_transfer_service_spec.rb | 56 +++++++++++++++++-- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/app/services/digital_stacks_differ.rb b/app/services/digital_stacks_differ.rb index e0a9dbac7..6b949a41d 100644 --- a/app/services/digital_stacks_differ.rb +++ b/app/services/digital_stacks_differ.rb @@ -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 diff --git a/app/services/publish/metadata_transfer_service.rb b/app/services/publish/metadata_transfer_service.rb index 4dffd94c7..e97fc4620 100644 --- a/app/services/publish/metadata_transfer_service.rb +++ b/app/services/publish/metadata_transfer_service.rb @@ -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 @@ -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 diff --git a/spec/services/publish/metadata_transfer_service_spec.rb b/spec/services/publish/metadata_transfer_service_spec.rb index d86f2ec5c..14aaf5c00 100644 --- a/spec/services/publish/metadata_transfer_service_spec.rb +++ b/spec/services/publish/metadata_transfer_service_spec.rb @@ -105,7 +105,7 @@ 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 @@ -113,7 +113,7 @@ 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')) @@ -183,7 +183,7 @@ 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 @@ -191,7 +191,7 @@ 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')) @@ -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