Skip to content

Commit

Permalink
Merge pull request #13 from sul-dlss/sig_cat_object
Browse files Browse the repository at this point in the history
signature_catalog returns Moab::SignatureCatalog
  • Loading branch information
jcoyne authored Dec 7, 2019
2 parents d022a75 + 00a3fff commit 48d25ed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ druids may be with or without the "druid:" prefix - 'oo000oo0000' or 'druid:oo00
- `client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml')` - returns contents of identityMetadata.xml in most recent version of Moab object
- You may specify the version:
- `client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml', version: '8')` - returns contents of identityMetadata.xml in version 8 of Moab object
- `client.objects.signature_catalog(druid: 'oo000oo0000')` - returns contents of latest version of signatureCatalog.xml from Moab object
- `client.objects.signature_catalog('oo000oo0000')` - returns latest Moab::SignatureCatalog from Moab, or new Moab::SignatureCatalog for Moab if none yet exists


### Get difference information between passed contentMetadata.xml and files in the Moab

Expand Down
11 changes: 9 additions & 2 deletions lib/preservation/client/objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ def metadata(druid:, filepath:, version: nil)
file(druid, 'metadata', filepath, version)
end

# convenience method for retrieving latest signatureCatalog.xml file from a Moab object
# convenience method for retrieving latest Moab::SignatureCatalog from a Moab object,
# or a newly minted Moab::SignatureCatalog if it doesn't yet exist
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
# @return [Moab::SignatureCatalog] the catalog of all files previously ingested
def signature_catalog(druid)
manifest(druid: druid, filepath: 'signatureCatalog.xml')
Moab::SignatureCatalog.parse manifest(druid: druid, filepath: 'signatureCatalog.xml')
rescue Preservation::Client::UnexpectedResponseError => e
return Moab::SignatureCatalog.new(digital_object_id: druid, version_id: 0) if
e.message.match?('404 File Not Found')

raise
end

private
Expand Down
11 changes: 9 additions & 2 deletions spec/preservation/client/objects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
end

it 'returns the signature catalog file' do
expect(subject.signature_catalog(file_druid)).to eq valid_response_body
expect(subject.signature_catalog(file_druid).to_xml).to eq Moab::SignatureCatalog.parse(valid_response_body).to_xml
end
end

Expand All @@ -376,7 +376,14 @@
allow(subject).to receive(:get).with(file_api_path, file_api_params).and_raise(Preservation::Client::UnexpectedResponseError, err_msg)
end

it 'raises an error' do
it 'if 404 status, return new Moab::SignatureCatalog for druid' do
prescat_err_msg = "Preservation::Client.signature_catalog for #{file_druid} got 404 File Not Found (404) from Preservation ..."
allow(subject).to receive(:get).with(file_api_path, file_api_params).and_raise(Preservation::Client::UnexpectedResponseError, prescat_err_msg)
expect(subject.signature_catalog(file_druid).to_xml).to eq Moab::SignatureCatalog.new(digital_object_id: file_druid, version_id: 0).to_xml
end

it 'if not 404 status, raises an error' do
allow(subject).to receive(:get).with(file_api_path, file_api_params).and_raise(Preservation::Client::UnexpectedResponseError, err_msg)
expect { subject.signature_catalog(file_druid) }.to raise_error(Preservation::Client::UnexpectedResponseError, err_msg)
end
end
Expand Down

0 comments on commit 48d25ed

Please sign in to comment.