Skip to content

Commit

Permalink
Merge pull request #5123 from sul-dlss/t5122-staging
Browse files Browse the repository at this point in the history
Copies files to be shelved to staging area.
  • Loading branch information
jcoyne authored Jul 10, 2024
2 parents 669b922 + acd8df7 commit 678744c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
19 changes: 16 additions & 3 deletions app/services/publish/metadata_transfer_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def publish_delete_on_success

def publish_shelve
ShelvableFilesStager.stage(druid:, version: cocina_object.version, filepaths: filepaths_to_shelve, workspace_content_pathname:) if filepaths_to_shelve.present?
PurlFetcher::Client::PublishShelve.publish_and_shelve(cocina: public_cocina, filepath_map:)
filepath_map.each do |filename, stage_filename|
copy(workspace_content_pathname.join(filename), transfer_stage_pathname.join(stage_filename))
end
PurlFetcher::Client::Publish.publish(cocina: public_cocina, file_uploads: filepath_map)
end

def workspace_content_pathname
Expand All @@ -134,13 +137,23 @@ def workspace_content_pathname
end
end

def copy(src_pathname, dest_pathname)
return if dest_pathname.exist?

FileUtils.copy(src_pathname, dest_pathname)
end

def transfer_stage_pathname
@transfer_stage_pathname ||= Pathname(Settings.stacks.transfer_stage_root)
end

def filepaths_to_shelve
@filepaths_to_shelve ||= public_cocina.dro? ? DigitalStacksDiffer.call(cocina_object: public_cocina) : []
end

def filepath_map
filepaths_to_shelve.index_with do |filename|
workspace_content_pathname.join(filename).to_s
@filepath_map ||= filepaths_to_shelve.index_with do |_filename|
SecureRandom.uuid
end
end
end
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ stacks:
local_workspace_root: '/dor/workspace'
local_stacks_root: '/stacks'
local_document_cache_root: '/purl/document_cache'
transfer_stage_root: '/transfer-stage'

# Suri
suri:
Expand Down
23 changes: 17 additions & 6 deletions spec/services/publish/metadata_transfer_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,30 @@
]
end

let(:transfer_stage_root) { Dir.mktmpdir }
let(:workspace_root) { Dir.mktmpdir }

after do
FileUtils.remove_entry transfer_stage_root
FileUtils.remove_entry workspace_root
end

before do
allow(Settings.stacks).to receive_messages(transfer_stage_root:, local_workspace_root: workspace_root)
allow(CocinaObjectStore).to receive(:find).and_return(cocina_object)
allow(PurlFetcher::Client::PublishShelve).to receive(:publish_and_shelve)
allow(PurlFetcher::Client::Publish).to receive(:publish)
allow(DigitalStacksDiffer).to receive(:call).and_return(['images/jt667tw2770_05_0001.jp2'])
allow(ShelvableFilesStager).to receive(:stage)
allow(SecureRandom).to receive(:uuid).and_return('fe54b4a9-220f-4522-9ce6-0453c716dca6')
src_filepath = File.join(workspace_root, 'bc/123/df/4567/bc123df4567/content/images/jt667tw2770_05_0001.jp2')
FileUtils.mkdir_p(File.dirname(src_filepath))
File.write(src_filepath, 'jp2 content')
end

it 'shelves and publishes to purl fetcher service' do
it 'shelves and publishes' do
publish_shelve
expect(PurlFetcher::Client::PublishShelve).to have_received(:publish_and_shelve).with(cocina: Cocina::Models::DRO, filepath_map: { 'images/jt667tw2770_05_0001.jp2' =>
'tmp/dor/workspace/bc/123/df/4567/bc123df4567/content/images/jt667tw2770_05_0001.jp2' })
expect(ShelvableFilesStager).to have_received(:stage).with(druid: "druid:#{druid}", version: 1, filepaths: ['images/jt667tw2770_05_0001.jp2'], workspace_content_pathname: Pathname('tmp/dor/workspace/bc/123/df/4567/bc123df4567/content'))
expect(ShelvableFilesStager).to have_received(:stage).with(druid: "druid:#{druid}", version: 1, filepaths: ['images/jt667tw2770_05_0001.jp2'], workspace_content_pathname: Pathname(File.join(workspace_root, 'bc/123/df/4567/bc123df4567/content')))
expect(PurlFetcher::Client::Publish).to have_received(:publish).with(cocina: Cocina::Models::DRO, file_uploads: { 'images/jt667tw2770_05_0001.jp2' => 'fe54b4a9-220f-4522-9ce6-0453c716dca6' })
end

context 'when a collection' do
Expand All @@ -281,7 +293,6 @@

it 'shelves and publishes to purl fetcher service' do
publish_shelve
expect(PurlFetcher::Client::PublishShelve).to have_received(:publish_and_shelve).with(cocina: Cocina::Models::Collection, filepath_map: {})
expect(DigitalStacksDiffer).not_to have_received(:call)
expect(ShelvableFilesStager).not_to have_received(:stage)
end
Expand Down

0 comments on commit 678744c

Please sign in to comment.