diff --git a/app/jobs/shelve_job.rb b/app/jobs/shelve_job.rb index 2afcd845f..3f841f3ae 100644 --- a/app/jobs/shelve_job.rb +++ b/app/jobs/shelve_job.rb @@ -11,7 +11,7 @@ def perform(druid:, background_job_result:) # Skip if publish_shelve is enabled # However, web archive crawls still need to be shelved. - if Settings.enabled_features.publish_shelve && !WasService.crawl?(druid:) + unless WasService.crawl?(druid:) return LogSuccessJob.perform_later(druid:, workflow: 'accessionWF', background_job_result:, diff --git a/app/services/delete_service.rb b/app/services/delete_service.rb index 44c73d566..3acd95ac8 100644 --- a/app/services/delete_service.rb +++ b/app/services/delete_service.rb @@ -7,8 +7,6 @@ class DeleteService # - Removes content from dor workspace # - Removes content from assembly workspace # - Removes content from sdr export area - # - Removes content from stacks - # - Removes content from purl # - Removes active workflows # @param [Cocina::Models::DRO|AdminPolicy||Collection] cocina object wish to remove def self.destroy(cocina_object, user_name:) @@ -22,8 +20,6 @@ def initialize(cocina_object, user_name) def destroy CleanupService.cleanup_by_druid druid - cleanup_stacks - cleanup_purl_doc_cache remove_active_workflows delete_from_dor EventFactory.create(druid:, event_type: 'delete', data: { request: cocina_object.to_h, source_id: cocina_object&.identification&.sourceId, user_name: }) @@ -33,16 +29,6 @@ def destroy attr_reader :cocina_object, :user_name - def cleanup_stacks - stacks_druid = DruidTools::StacksDruid.new(druid, Settings.stacks.local_stacks_root) - PruneService.new(druid: stacks_druid).prune! - end - - def cleanup_purl_doc_cache - purl_druid = DruidTools::PurlDruid.new(druid, Settings.stacks.local_document_cache_root) - PruneService.new(druid: purl_druid).prune! - end - def remove_active_workflows WorkflowClientFactory.build.delete_all_workflows(pid: druid) end diff --git a/app/services/publish/metadata_transfer_service.rb b/app/services/publish/metadata_transfer_service.rb index 54681b63a..5c62fce55 100644 --- a/app/services/publish/metadata_transfer_service.rb +++ b/app/services/publish/metadata_transfer_service.rb @@ -17,15 +17,10 @@ def initialize(cocina_object, workflow:) # Appends contentMetadata file resources from the source objects to this object def publish republish_collection_members! - return unpublish unless discoverable? - - if Settings.enabled_features.publish_shelve - publish_shelve - republish_virtual_object_constituents! - else - transfer_metadata - publish_notify_on_success - end + return publish_delete_on_success unless discoverable? + + publish_shelve + republish_virtual_object_constituents! release_tags_on_success end @@ -41,16 +36,6 @@ def druid cocina_object.externalIdentifier end - def transfer_metadata - transfer_to_document_store(public_cocina.to_json, 'cocina.json') - end - - # Clear out the document cache for this item - def unpublish - PruneService.new(druid: purl_druid).prune! - publish_delete_on_success - end - def discoverable? cocina_object.access.view != 'dark' end @@ -71,27 +56,6 @@ def republish_virtual_object_constituents! end end - # Create a file inside the content directory under the stacks.local_document_cache_root - # @param [String] content The contents of the file to be created - # @param [String] filename The name of the file to be created - # @return [void] - def transfer_to_document_store(content, filename) - new_file = File.join(purl_druid.content_dir, filename) - Rails.logger.debug("[Publish][#{cocina_object.externalIdentifier}] Writing #{new_file}") - File.write(new_file, content) - end - - def purl_druid - @purl_druid ||= DruidTools::PurlDruid.new cocina_object.externalIdentifier, Settings.stacks.local_document_cache_root - end - - ## - # When publishing a PURL, we notify purl-fetcher of changes. - # - def publish_notify_on_success - PurlFetcher::Client::LegacyPublish.publish(cocina: public_cocina) - end - def release_tags_on_success tags = ReleaseTagService.for_public_metadata(cocina_object: public_cocina) actions = { index: [], delete: [] }.tap do |releases| diff --git a/app/services/shelving_service.rb b/app/services/shelving_service.rb index 494f607ba..876077681 100644 --- a/app/services/shelving_service.rb +++ b/app/services/shelving_service.rb @@ -87,9 +87,7 @@ def base_inventory(subset) def stacks_location # Currently the best know way to identify objects like this is to see if the wasCrawlPreassemblyWF workflow is present. # If this condition is met, then shelf to /web-archiving-stacks/data/collections/, where collection_id is the unnamespaced druid of the (first) collection. - return was_stack_location if was? - - Settings.stacks.local_stacks_root + was_stack_location end def was? diff --git a/config/settings.yml b/config/settings.yml index 51b89d8ff..32aaf24d0 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -4,7 +4,6 @@ enabled_features: create_ur_admin_policy: false datacite_update: false orcid_update: true - publish_shelve: false # Ur Admin Policy ur_admin_policy: @@ -16,8 +15,6 @@ ur_admin_policy: stacks: document_cache_host: 'purl-test.stanford.edu' local_workspace_root: '/dor/workspace' - local_stacks_root: '/stacks' - local_document_cache_root: '/purl/document_cache' transfer_stage_root: '/transfer-stage' # Suri diff --git a/spec/jobs/shelve_job_spec.rb b/spec/jobs/shelve_job_spec.rb index b2beb17b5..cf2c8d2d1 100644 --- a/spec/jobs/shelve_job_spec.rb +++ b/spec/jobs/shelve_job_spec.rb @@ -8,32 +8,22 @@ let(:druid) { 'druid:mk420bs7601' } let(:result) { create(:background_job_result) } let(:cocina_object) { instance_double(Cocina::Models::DRO) } - let(:valid) { true } - let(:invalid_filenames) { [] } before do allow(CocinaObjectStore).to receive(:find).with(druid).and_return(cocina_object) allow(result).to receive(:processing!) - allow(EventFactory).to receive(:create) + allow(ShelvingService).to receive(:shelve) + allow(LogSuccessJob).to receive(:perform_later) end - context 'with no errors' do + context 'when not a WAS crawl' do before do - allow(ShelvingService).to receive(:shelve) - allow(LogSuccessJob).to receive(:perform_later) - perform - end - - it 'marks the job as processing' do - expect(result).to have_received(:processing!).once - end - - it 'invokes the ShelvingService' do - expect(ShelvingService).to have_received(:shelve).with(cocina_object).once + allow(WasService).to receive(:crawl?).with(druid:).and_return(false) end - it 'marks the job as complete' do - expect(EventFactory).to have_received(:create) + it 'skips shelving' do + perform + expect(ShelvingService).not_to have_received(:shelve) expect(LogSuccessJob).to have_received(:perform_later) .with(druid:, background_job_result: result, @@ -42,64 +32,19 @@ end end - context 'with errors returned by ShelvingService' do - let(:error_message) { "file isn't where we looked" } - + context 'when a WAS crawl' do before do - allow(ShelvingService).to receive(:shelve).and_raise(LegacyShelvableFilesStager::FileNotFound, error_message) - allow(LogFailureJob).to receive(:perform_later) + allow(WasService).to receive(:crawl?).with(druid:).and_return(true) end - it 'marks the job as errored' do + it 'performs shelving' do perform - expect(result).to have_received(:processing!).once expect(ShelvingService).to have_received(:shelve).with(cocina_object).once - expect(LogFailureJob).to have_received(:perform_later) + expect(LogSuccessJob).to have_received(:perform_later) .with(druid:, background_job_result: result, workflow: 'accessionWF', - workflow_process: 'shelve', - output: { errors: [{ detail: error_message, title: 'Unable to shelve files' }] }) - end - end - - context 'when publish_shelve feature flag is enabled' do - before do - allow(Settings.enabled_features).to receive(:publish_shelve).and_return(true) - allow(ShelvingService).to receive(:shelve) - allow(LogSuccessJob).to receive(:perform_later) - end - - context 'when not a WAS crawl' do - before do - allow(WasService).to receive(:crawl?).with(druid:).and_return(false) - end - - it 'skips shelving' do - perform - expect(ShelvingService).not_to have_received(:shelve) - expect(LogSuccessJob).to have_received(:perform_later) - .with(druid:, - background_job_result: result, - workflow: 'accessionWF', - workflow_process: 'shelve') - end - end - - context 'when a WAS crawl' do - before do - allow(WasService).to receive(:crawl?).with(druid:).and_return(true) - end - - it 'performs shelving' do - perform - expect(ShelvingService).to have_received(:shelve).with(cocina_object).once - expect(LogSuccessJob).to have_received(:perform_later) - .with(druid:, - background_job_result: result, - workflow: 'accessionWF', - workflow_process: 'shelve') - end + workflow_process: 'shelve') end end end diff --git a/spec/services/cleanup_service_spec.rb b/spec/services/cleanup_service_spec.rb index 639a4c697..13a36254d 100644 --- a/spec/services/cleanup_service_spec.rb +++ b/spec/services/cleanup_service_spec.rb @@ -203,7 +203,6 @@ let(:workspace_dir) { File.join(fixture_dir, 'workspace') } let(:export_dir) { File.join(fixture_dir, 'export') } let(:assembly_dir) { File.join(fixture_dir, 'assembly') } - let(:stacks_dir) { File.join(fixture_dir, 'stacks') } let(:druid1) { 'druid:cd456ef7890' } let(:druid2) { 'druid:cd456gh1234' } @@ -214,13 +213,11 @@ local_export_home: export_dir, local_assembly_root: assembly_dir ) - allow(Settings.stacks).to receive(:local_stacks_root).and_return(stacks_dir) FileUtils.mkdir fixture_dir FileUtils.mkdir workspace_dir FileUtils.mkdir export_dir FileUtils.mkdir assembly_dir - FileUtils.mkdir stacks_dir end after do diff --git a/spec/services/delete_service_spec.rb b/spec/services/delete_service_spec.rb index 09a5e9f14..367927b97 100644 --- a/spec/services/delete_service_spec.rb +++ b/spec/services/delete_service_spec.rb @@ -40,31 +40,6 @@ end end - describe '#cleanup_stacks' do - let(:fixture_dir) { '/tmp/cleanup-spec' } - let(:stacks_dir) { File.join(fixture_dir, 'stacks') } - let(:stacks_druid) { DruidTools::StacksDruid.new(druid, Settings.stacks.local_stacks_root) } - - before do - allow(Settings.stacks).to receive(:local_stacks_root).and_return(stacks_dir) - FileUtils.mkdir fixture_dir - FileUtils.mkdir stacks_dir - - stacks_druid.mkdir - - File.write(File.join(stacks_druid.path, 'tempfile'), 'junk') - end - - after do - FileUtils.rm_rf fixture_dir - end - - it 'prunes the item from the local stacks root' do - expect { service.send(:cleanup_stacks) }.to change { File.exist?(stacks_druid.path) } - .from(true).to(false) - end - end - describe '#delete_from_dor' do before do create(:repository_object, external_identifier: druid) diff --git a/spec/services/publish/metadata_transfer_service_spec.rb b/spec/services/publish/metadata_transfer_service_spec.rb index 814c5334b..21a03c3b6 100644 --- a/spec/services/publish/metadata_transfer_service_spec.rb +++ b/spec/services/publish/metadata_transfer_service_spec.rb @@ -18,7 +18,7 @@ let(:structural_contains) { [] } let(:cocina_collection) { build(:collection, id: 'druid:xh235dd9059') } let(:service) { described_class.new(cocina_object, workflow:) } - let(:fake_publish_job) { class_double(PublishJob, perform_later: nil) } + let(:publish_job) { class_double(PublishJob, perform_later: nil) } describe '#publish' do before do @@ -44,43 +44,29 @@ end before do - allow_any_instance_of(described_class).to receive(:transfer_to_document_store) - allow_any_instance_of(described_class).to receive(:transfer_metadata) - allow_any_instance_of(described_class).to receive(:publish_notify_on_success) - allow_any_instance_of(described_class).to receive(:release_tags_on_success) allow(MemberService).to receive(:for).and_return([member_druid]) allow(CocinaObjectStore).to receive(:find).with(member_druid).and_return(member_item) allow(described_class).to receive(:new).with(cocina_object, workflow:).and_call_original - allow(PublishJob).to receive(:set).with(queue: :publish_low).and_return(fake_publish_job) + allow(PublishJob).to receive(:set).with(queue: :publish_low).and_return(publish_job) + allow(service).to receive(:publish_shelve) + allow(service).to receive(:republish_virtual_object_constituents!) + allow(service).to receive(:release_tags_on_success) end it 'republishes member items' do service.publish expect(MemberService).to have_received(:for).once - expect(fake_publish_job).to have_received(:perform_later).once.with(druid: member_druid, background_job_result: BackgroundJobResult.last, workflow:, log_success: false) + expect(publish_job).to have_received(:perform_later).once.with(druid: member_druid, background_job_result: BackgroundJobResult.last, workflow:, log_success: false) end end - context 'with no world discover access in rightsMetadata' do - let(:purl_root) { Dir.mktmpdir } - - let(:druid1) { DruidTools::Druid.new cocina_object.externalIdentifier, purl_root } - + context 'when not discoverable' do before do - allow(Settings.stacks).to receive(:local_document_cache_root).and_return(purl_root) allow(PurlFetcher::Client::Unpublish).to receive(:unpublish) - # create druid tree and dummy content in purl root - druid1.mkdir - File.write(File.join(druid1.path, 'tmpfile'), 'junk') - end - - after do - FileUtils.remove_entry purl_root end - it "removes the item's content from the Purl document cache and notifies the purl service of the deletion" do + it 'unpublishes' do service.publish - expect(File).not_to exist(druid1.path) # it should now be gone expect(PurlFetcher::Client::Unpublish).to have_received(:unpublish).with(druid: cocina_object.externalIdentifier) end @@ -90,8 +76,7 @@ end it 'ignores the error' do - service.publish - expect(File).not_to exist(druid1.path) # it should now be gone + expect { service.publish }.not_to raise_error end end end @@ -99,18 +84,18 @@ describe 'copies to the document cache' do context 'with an item' do before do - allow(service).to receive(:transfer_to_document_store) - allow(service).to receive(:publish_notify_on_success) + allow(service).to receive(:publish_shelve) allow(service).to receive(:release_tags_on_success) + allow(service).to receive(:republish_virtual_object_constituents!) end let(:access) { { view: 'citation-only', download: 'none' } } - it 'transfers public cocina' do + it 'publishes, shelves, and releases tags' do service.publish - expect(service).to have_received(:transfer_to_document_store).with(/{"cocinaVersion"/, 'cocina.json') - expect(service).to have_received(:publish_notify_on_success) + expect(service).to have_received(:publish_shelve) expect(service).to have_received(:release_tags_on_success) + expect(service).to have_received(:republish_virtual_object_constituents!) end end @@ -122,55 +107,23 @@ end before do - allow(service).to receive(:transfer_to_document_store) - allow(service).to receive(:publish_notify_on_success) - allow(service).to receive(:release_tags_on_success) - allow(service).to receive(:republish_collection_members!) - end - - it 'ignores missing data' do - expect { service.publish }.not_to raise_error - expect(service).to have_received(:transfer_to_document_store).with(/{"cocinaVersion"/, 'cocina.json') - expect(service).to have_received(:publish_notify_on_success) - expect(service).to have_received(:release_tags_on_success) - expect(service).to have_received(:republish_collection_members!).with(no_args) - end - end - - context 'when publish_shelve is enabled' do - before do - allow(Settings.enabled_features).to receive(:publish_shelve).and_return(true) allow(service).to receive(:publish_shelve) allow(service).to receive(:release_tags_on_success) allow(service).to receive(:republish_virtual_object_constituents!) + allow(service).to receive(:republish_collection_members!) end - let(:access) { { view: 'citation-only', download: 'none' } } - it 'publishes, shelves, and releases tags' do service.publish expect(service).to have_received(:publish_shelve) expect(service).to have_received(:release_tags_on_success) expect(service).to have_received(:republish_virtual_object_constituents!) + expect(service).to have_received(:republish_collection_members!).with(no_args) end end end end - describe '#publish_notify_on_success' do - subject(:notify) { service.send(:publish_notify_on_success) } - - before do - allow(CocinaObjectStore).to receive(:find).and_return(cocina_object) - allow(PurlFetcher::Client::LegacyPublish).to receive(:publish) - end - - it 'notifies the purl service of the update' do - notify - expect(PurlFetcher::Client::LegacyPublish).to have_received(:publish).with(cocina: Cocina::Models::DRO) - end - end - describe '#release_tags_on_success' do subject(:notify) { service.send(:release_tags_on_success) } @@ -185,28 +138,6 @@ end end - describe '#transfer_to_document_store' do - let(:purl_root) { Dir.mktmpdir } - let(:workspace_root) { Dir.mktmpdir } - - before do - allow(Settings.stacks).to receive_messages(local_document_cache_root: purl_root, local_workspace_root: workspace_root) - end - - after do - FileUtils.remove_entry purl_root - FileUtils.remove_entry workspace_root - end - - it 'copies the given metadata to the document cache in the Digital Stacks' do - dr = DruidTools::PurlDruid.new cocina_object.externalIdentifier, purl_root - service.send(:transfer_to_document_store, '', 'someMd') - file_path = dr.find(:content, 'someMd') - expect(file_path).to match(%r{4567/someMd$}) - expect(File.read(file_path)).to eq('') - end - end - describe '#publish_shelve' do subject(:publish_shelve) { service.send(:publish_shelve) } @@ -306,13 +237,13 @@ before do allow(VirtualObjectService).to receive(:constituents).and_return([constituent_druid]) - allow(PublishJob).to receive(:set).with(queue: :publish_low).and_return(fake_publish_job) + allow(PublishJob).to receive(:set).with(queue: :publish_low).and_return(publish_job) end it 'republishes the virtual object constituents' do republish expect(VirtualObjectService).to have_received(:constituents).with(cocina_object, exclude_opened: true, only_published: true) - expect(fake_publish_job).to have_received(:perform_later).once.with(druid: constituent_druid, background_job_result: BackgroundJobResult.last, workflow:, log_success: false) + expect(publish_job).to have_received(:perform_later).once.with(druid: constituent_druid, background_job_result: BackgroundJobResult.last, workflow:, log_success: false) end end diff --git a/spec/services/shelving_service_spec.rb b/spec/services/shelving_service_spec.rb index 4e0244d8a..2020a06eb 100644 --- a/spec/services/shelving_service_spec.rb +++ b/spec/services/shelving_service_spec.rb @@ -54,11 +54,10 @@ let(:group_difference) { instance_double(Moab::FileGroupDifference) } let(:workflow_client) { instance_double(Dor::Workflow::Client, workflows:) } let(:workflows) { ['accessionWF', 'registrationWF'] } - let(:stacks_object_pathname) { Pathname(DruidTools::StacksDruid.new(druid, stacks_root).path) } + let(:stacks_object_pathname) { Pathname('/web-archiving-stacks/data/collections/bb077hj4590/ng/782/rw/8378') } before do allow(WorkflowClientFactory).to receive(:build).and_return(workflow_client) - allow(Settings.stacks).to receive_messages(local_stacks_root: stacks_root, local_workspace_root: workspace_root) allow(Cocina::ToXml::ContentMetadataGenerator).to receive(:generate).and_return(content_metadata) allow(Preservation::Client.objects).to receive(:metadata).with(druid:, filepath: 'contentMetadata.xml').and_return(previous_content_metadata) allow(Preservation::Client.objects).to receive(:current_version).with(druid).and_return(1) @@ -75,7 +74,6 @@ context 'when structural present and previous version exists in preservation' do it 'pushes file changes for shelve-able files into the stacks' do - stacks_object_pathname = Pathname(DruidTools::StacksDruid.new(druid, stacks_root).path) # make sure the DigitalStacksService is getting the correct delete, rename, and shelve requests # (These methods are unit tested in digital_stacks_service_spec.rb) described_class.shelve(cocina_object) @@ -94,7 +92,6 @@ end it 'pushes file changes for shelve-able files into the stacks' do - stacks_object_pathname = Pathname(DruidTools::StacksDruid.new(druid, stacks_root).path) # make sure the DigitalStacksService is getting the correct delete, rename, and shelve requests # (These methods are unit tested in digital_stacks_service_spec.rb) described_class.shelve(cocina_object) @@ -116,7 +113,6 @@ context 'when a web archive' do let(:workflows) { %w[accessionWF registrationWF wasCrawlPreassemblyWF] } - let(:stacks_object_pathname) { Pathname('/web-archiving-stacks/data/collections/bb077hj4590/ng/782/rw/8378') } it 'pushes file changes for shelve-able files into the stacks' do # make sure the DigitalStacksService is getting the correct delete, rename, and shelve requests