Skip to content

Commit

Permalink
HELIO-4322 update APtrust API usage to V3
Browse files Browse the repository at this point in the history
  • Loading branch information
sethaj committed Nov 15, 2022
1 parent 5fe18db commit 83ad306
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion app/jobs/aptrust_deposit_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ def bag(monograph)
Export::Exporter.new(monograph.noid).extract("#{bag.bag_dir}/data/", true)

# Create manifests
bag.manifest!
bag.manifest!(algo: 'md5')
# HELIO-4380 demo.aptrust.org doesn't like this file for some reason, gives an ingest error:
# "Bag contains illegal tag manifest 'sha1'""
# APTrust only wants SHA256, or MD5, not SHA1.
# 'tagmanifest-sha1.txt' is a bagit gem default, so we need to remove it manually.
sha1tag = File.join(bag.bag_dir, 'tagmanifest-sha1.txt')
File.delete(sha1tag) if File.exist?(sha1tag)

dirname
end
Expand Down
6 changes: 4 additions & 2 deletions app/services/aptrust/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
module Aptrust
class Service
def ingest_status(identifier) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
response = connection.get("items?object_identifier_like=#{identifier}&item_action=Ingest")
# For API V3 we need identifiers that look like fulcrum.org/fulcrum.org.michelt-zc77ss45g
# and not just fulcrum.org.michelt-zc77ss45g
response = connection.get("items?object_identifier=fulcrum.org\/#{identifier}&action=Ingest")

return 'http_error' unless response.success?

results = response.body['results']

return 'not_found' if results.empty?
return 'not_found' if results.blank?

item = results.first

Expand Down
4 changes: 2 additions & 2 deletions spec/services/aptrust/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
let(:body) { { "results" => items } }
let(:items) { [] }

before { allow(connection).to receive(:get).with("items?object_identifier_like=#{identifier}&item_action=Ingest").and_return(response) }
before { allow(connection).to receive(:get).with("items?object_identifier=fulcrum.org\/#{identifier}&action=Ingest").and_return(response) }

it { is_expected.to eq('http_error') }

Expand All @@ -71,7 +71,7 @@
it { is_expected.to eq('success') }

context 'standard error' do
before { allow(connection).to receive(:get).with("items?object_identifier_like=#{identifier}&item_action=Ingest").and_raise(StandardError) }
before { allow(connection).to receive(:get).with("items?object_identifier=fulcrum.org\/#{identifier}&action=Ingest").and_raise(StandardError) }

it { is_expected.to eq('standard_error') }
end
Expand Down

0 comments on commit 83ad306

Please sign in to comment.