Skip to content

Commit

Permalink
Merge pull request #4964 from sul-dlss/t4958-purl_fetcher_client2
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne authored May 3, 2024
2 parents 5e64426 + d61a236 commit 1875aae
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gem 'marc'
gem 'marc-vocab', '~> 0.3.0' # for indexing
gem 'moab-versioning', '~> 6.0', require: 'moab/stanford'
gem 'preservation-client', '~> 6.0'
gem 'purl_fetcher-client', '~> 1.2.0'
gem 'stanford-mods' # for indexing
gem 'sul_orcid_client', '~> 0.3'

Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ GEM
public_suffix (5.0.5)
puma (6.4.2)
nio4r (~> 2.0)
purl_fetcher-client (1.2.0)
activesupport
faraday (~> 2.1)
racc (1.7.3)
rack (3.0.10)
rack-console (1.4.0)
Expand Down Expand Up @@ -607,6 +610,7 @@ DEPENDENCIES
preservation-client (~> 6.0)
propshaft
puma (~> 6.0)
purl_fetcher-client (~> 1.2.0)
rack-console
rails (~> 7.1.0)
retries
Expand Down
10 changes: 2 additions & 8 deletions app/services/publish/metadata_transfer_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,14 @@ def purl_druid
# When publishing a PURL, we notify purl-fetcher of changes.
#
def publish_notify_on_success(public_cocina)
Faraday.post(purl_services_url, public_cocina.to_json, { 'Content-Type' => 'application/json' })
PurlFetcher::Client::LegacyPublish.publish(cocina: public_cocina)
end

##
# When deleting a PURL, we notify purl-fetcher of changes.
#
def publish_delete_on_success
Faraday.delete(purl_services_url)
end

def purl_services_url
raise 'You have not configured purl-fetcher (Settings.purl_fetcher.url).' unless Settings.purl_fetcher.url

"#{Settings.purl_fetcher.url}/purls/#{cocina_object.externalIdentifier.delete_prefix('druid:')}"
PurlFetcher::Client::Unpublish.unpublish(druid: cocina_object.externalIdentifier)
end
end
end
3 changes: 3 additions & 0 deletions config/initializers/purl_fetcher_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

PurlFetcher::Client.configure(url: Settings.purl_fetcher.url, token: Settings.purl_fetcher.token)
25 changes: 4 additions & 21 deletions spec/services/publish/metadata_transfer_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
let(:purl_root) { Dir.mktmpdir }

before do
allow(Settings.purl_fetcher).to receive(:url).and_return('http://example.com/purl')
allow(Settings.stacks).to receive(:local_document_cache_root).and_return(purl_root)
allow(PurlFetcher::Client::Unpublish).to receive(:unpublish)

stub_request(:delete, "example.com/purl/purls/#{druid}")
end
Expand All @@ -83,7 +83,7 @@
File.write(File.join(druid1.path, 'tmpfile'), 'junk')
service.publish
expect(File).not_to exist(druid1.path) # it should now be gone
expect(WebMock).to have_requested(:delete, "example.com/purl/purls/#{druid}")
expect(PurlFetcher::Client::Unpublish).to have_received(:unpublish).with(druid: cocina_object.externalIdentifier)
end
end

Expand Down Expand Up @@ -149,31 +149,14 @@

context 'when purl-fetcher is configured' do
before do
allow(Settings.purl_fetcher).to receive(:url).and_return('http://example.com/purl')
allow(CocinaObjectStore).to receive(:find).and_return(cocina_object)
allow(ThumbnailService).to receive(:new).and_return(thumbnail_service)

stub_request(:post, "example.com/purl/purls/#{druid}")
allow(PurlFetcher::Client::LegacyPublish).to receive(:publish)
end

it 'notifies the purl service of the update' do
notify
expect(WebMock).to have_requested(:post, "example.com/purl/purls/#{druid}")
end
end

context 'when purl-fetcher is not configured' do
let(:purl_root) { Dir.mktmpdir }
let(:changes_dir) { Dir.mktmpdir }
let(:changes_file) { File.join(changes_dir, druid) }

before do
allow(Settings.purl_fetcher).to receive(:url).and_return(nil)
allow(ThumbnailService).to receive(:new).and_return(thumbnail_service)
end

it 'writes empty notification file' do
expect { notify }.to raise_error 'You have not configured purl-fetcher (Settings.purl_fetcher.url).'
expect(PurlFetcher::Client::LegacyPublish).to have_received(:publish).with(cocina: cocina_object)
end
end
end
Expand Down

0 comments on commit 1875aae

Please sign in to comment.