Class: Preservation::Client::Objects
- Inherits:
-
VersionedApiService
- Object
- VersionedApiService
- Preservation::Client::Objects
- Defined in:
- lib/preservation/client/objects.rb
Overview
API calls that are about Preserved Objects
Instance Method Summary collapse
-
#checksum(druid:) ⇒ Hash
The checksums and filesize for the druid.
-
#content(druid:, filepath:, version: nil, on_data: nil) ⇒ Object
retrieve a content file from a Moab object.
-
#content_inventory_diff(druid:, content_metadata:, subset: 'all', version: nil) ⇒ Moab::FileInventoryDifference
Differences of passed contentMetadata.xml with latest (or specified) version in Moab for all files (default) or a specified subset (shelve|preserve|publish).
-
#content_to_file(druid:, filepath:, destination_filepath:, version: nil, expected_md5: nil, max: nil, interval: nil) ⇒ Object
retrieve a content file from a Moab object and write it to destination atomically.
-
#current_version(druid) ⇒ Integer
The current version of the Preserved Object.
-
#initialize(connection:, streaming_connection:, retry_max:, retry_interval:, api_version: DEFAULT_API_VERSION) ⇒ Objects
constructor
rubocop:disable Metrics/ClassLength.
-
#manifest(druid:, filepath:, version: nil) ⇒ Object
retrieve a manifest file from a Moab object.
-
#metadata(druid:, filepath:, version: nil) ⇒ Object
retrieve a metadata file from a Moab object.
-
#object(druid) ⇒ Preservation::Client::Object
Attributes of the Preserved Object.
-
#shelve_content_diff(druid:, content_metadata:) ⇒ Moab::FileGroupDifference
convenience method for retrieving the differences in content files that should be "shelved" (altered in stacks) (or nil if no such differences).
-
#signature_catalog(druid) ⇒ Moab::SignatureCatalog
convenience method for retrieving latest Moab::SignatureCatalog from a Moab object,.
-
#validate_moab(druid:) ⇒ String
calls the endpoint to queue a ValidateMoab job for a specific druid typically called by a preservationIngestWF robot.
Constructor Details
#initialize(connection:, streaming_connection:, retry_max:, retry_interval:, api_version: DEFAULT_API_VERSION) ⇒ Objects
rubocop:disable Metrics/ClassLength
14 15 16 17 18 |
# File 'lib/preservation/client/objects.rb', line 14 def initialize(connection:, streaming_connection:, retry_max:, retry_interval:, api_version: DEFAULT_API_VERSION) super(connection: connection, streaming_connection: streaming_connection, api_version: api_version) @retry_max = retry_max @retry_interval = retry_interval end |
Instance Method Details
#checksum(druid:) ⇒ Hash
Returns the checksums and filesize for the druid.
22 23 24 |
# File 'lib/preservation/client/objects.rb', line 22 def checksum(druid:) get_json("objects/#{druid}/checksum", druid) end |
#content(druid:, filepath:, version: nil, on_data: nil) ⇒ Object
retrieve a content file from a Moab object
68 69 70 |
# File 'lib/preservation/client/objects.rb', line 68 def content(druid:, filepath:, version: nil, on_data: nil) file(druid, 'content', filepath, version, on_data: on_data) end |
#content_inventory_diff(druid:, content_metadata:, subset: 'all', version: nil) ⇒ Moab::FileInventoryDifference
Returns differences of passed contentMetadata.xml with latest (or specified) version in Moab for all files (default) or a specified subset (shelve|preserve|publish).
33 34 35 36 37 |
# File 'lib/preservation/client/objects.rb', line 33 def content_inventory_diff(druid:, content_metadata:, subset: 'all', version: nil) result = post("objects/#{druid}/content_diff", content_metadata: , subset: subset, version: version) Moab::FileInventoryDifference.parse(result) end |
#content_to_file(druid:, filepath:, destination_filepath:, version: nil, expected_md5: nil, max: nil, interval: nil) ⇒ Object
retrieve a content file from a Moab object and write it to destination atomically
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/preservation/client/objects.rb', line 83 def content_to_file(druid:, filepath:, destination_filepath:, version: nil, expected_md5: nil, # rubocop:disable Metrics/ParameterLists max: nil, interval: nil) with_retries(max: max || @retry_max, interval: interval || @retry_interval) do temp_filepath = nil begin temp_filepath = download_to_tempfile(druid: druid, filepath: filepath, destination_filepath: destination_filepath, version: version) verify_md5!(filepath: temp_filepath, expected_md5: expected_md5) if expected_md5 File.rename(temp_filepath, destination_filepath) temp_filepath = nil ensure cleanup_tempfile(temp_filepath) end end end |
#current_version(druid) ⇒ Integer
Returns the current version of the Preserved Object.
59 60 61 |
# File 'lib/preservation/client/objects.rb', line 59 def current_version(druid) object(druid).current_version end |
#manifest(druid:, filepath:, version: nil) ⇒ Object
retrieve a manifest file from a Moab object
106 107 108 |
# File 'lib/preservation/client/objects.rb', line 106 def manifest(druid:, filepath:, version: nil) file(druid, 'manifest', filepath, version) end |
#metadata(druid:, filepath:, version: nil) ⇒ Object
retrieve a metadata file from a Moab object
114 115 116 |
# File 'lib/preservation/client/objects.rb', line 114 def (druid:, filepath:, version: nil) file(druid, 'metadata', filepath, version) end |
#object(druid) ⇒ Preservation::Client::Object
Returns attributes of the Preserved Object.
52 53 54 55 |
# File 'lib/preservation/client/objects.rb', line 52 def object(druid) resp_body = get_json("objects/#{druid}.json", druid) Object.new(**resp_body) end |
#shelve_content_diff(druid:, content_metadata:) ⇒ Moab::FileGroupDifference
convenience method for retrieving the differences in content files that should be "shelved" (altered in stacks) (or nil if no such differences)
45 46 47 48 |
# File 'lib/preservation/client/objects.rb', line 45 def shelve_content_diff(druid:, content_metadata:) inventory_diff = content_inventory_diff(druid: druid, content_metadata: , subset: 'shelve') inventory_diff.group_difference('content') end |
#signature_catalog(druid) ⇒ Moab::SignatureCatalog
convenience method for retrieving latest Moab::SignatureCatalog from a Moab object,
130 131 132 |
# File 'lib/preservation/client/objects.rb', line 130 def signature_catalog(druid) Moab::SignatureCatalog.parse manifest(druid: druid, filepath: 'signatureCatalog.xml') end |
#validate_moab(druid:) ⇒ String
calls the endpoint to queue a ValidateMoab job for a specific druid typically called by a preservationIngestWF robot
123 124 125 |
# File 'lib/preservation/client/objects.rb', line 123 def validate_moab(druid:) get("objects/#{druid}/validate_moab", {}, on_data: nil) end |