Class: Preservation::Client::Objects

Inherits:
VersionedApiService show all
Defined in:
lib/preservation/client/objects.rb

Overview

API calls that are about Preserved Objects

Instance Method Summary collapse

Methods inherited from VersionedApiService

#initialize

Constructor Details

This class inherits a constructor from Preservation::Client::VersionedApiService

Instance Method Details

#checksum(druid:) ⇒ Hash

Returns the checksums and filesize for the druid.

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:bb123cd4567’ OR ‘bb123cd4567’

Returns:

  • (Hash)

    the checksums and filesize for the druid



16
17
18
# File 'lib/preservation/client/objects.rb', line 16

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

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:ab123cd4567’ OR ‘ab123cd4567’

  • filepath (String)
    • the path of the file relative to the moab content directory

  • version (String) (defaults to: nil)
    • the version of the file requested (defaults to nil for latest version)

  • on_data (Proc) (defaults to: nil)

    a block, if provided is called to do streaming responses



62
63
64
# File 'lib/preservation/client/objects.rb', line 62

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).

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:bb123cd4567’ OR ‘bb123cd4567’

  • content_metadata (String)
    • contentMetadata.xml to be compared against a version of Moab

  • subset (String) (defaults to: 'all')
    • (default: ‘all’) which subset of files to compare (all|shelve|preserve|publish)

  • version (String) (defaults to: nil)
    • version of Moab to be compared against (defaults to nil for latest version)

Returns:

  • (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)



27
28
29
30
31
# File 'lib/preservation/client/objects.rb', line 27

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_retries: 3, delay_seconds: 0.5) ⇒ Object

retrieve a content file from a Moab object and write it to destination atomically

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:ab123cd4567’ OR ‘ab123cd4567’

  • filepath (String)
    • the path of the file relative to the moab content directory

  • destination_filepath (String)
    • absolute or relative path to desired destination file

  • version (String) (defaults to: nil)
    • the version of the file requested (defaults to nil for latest version)

  • expected_md5 (String, nil) (defaults to: nil)
    • optional expected md5 checksum for integrity validation

  • max_retries (Integer) (defaults to: 3)
    • number of retry attempts after the initial attempt

  • delay_seconds (Float) (defaults to: 0.5)
    • base delay for retry backoff

Raises:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/preservation/client/objects.rb', line 77

def content_to_file(druid:, filepath:, destination_filepath:, version: nil, expected_md5: nil, # rubocop:disable Metrics/ParameterLists
                    max_retries: 3, delay_seconds: 0.5)
  with_retries(max_retries: max_retries, delay_seconds: delay_seconds) 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.

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:ab123cd4567’ OR ‘ab123cd4567’

Returns:

  • (Integer)

    the current version of the Preserved Object



53
54
55
# File 'lib/preservation/client/objects.rb', line 53

def current_version(druid)
  object(druid).current_version
end

#manifest(druid:, filepath:, version: nil) ⇒ Object

retrieve a manifest file from a Moab object

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:ab123cd4567’ OR ‘ab123cd4567’

  • filepath (String)
    • the path of the file relative to the moab manifest directory

  • version (String) (defaults to: nil)
    • the version of the file requested (defaults to nil for latest version)



100
101
102
# File 'lib/preservation/client/objects.rb', line 100

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

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:ab123cd4567’ OR ‘ab123cd4567’

  • filepath (String)
    • the path of the file relative to the moab metadata directory

  • version (String) (defaults to: nil)
    • the version of the file requested (defaults to nil for latest version)



108
109
110
# File 'lib/preservation/client/objects.rb', line 108

def (druid:, filepath:, version: nil)
  file(druid, 'metadata', filepath, version)
end

#object(druid) ⇒ Preservation::Client::Object

Returns attributes of the Preserved Object.

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:ab123cd4567’ OR ‘ab123cd4567’

Returns:



46
47
48
49
# File 'lib/preservation/client/objects.rb', line 46

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)

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:bb123cd4567’ OR ‘bb123cd4567’

  • content_metadata (String)
    • most recent contentMetadata.xml to be compared against latest version of Moab

Returns:

  • (Moab::FileGroupDifference)

    differences in content files that should be “shelved” (altered in stacks) (or nil if not found)



39
40
41
42
# File 'lib/preservation/client/objects.rb', line 39

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,

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:ab123cd4567’ OR ‘ab123cd4567’

Returns:

  • (Moab::SignatureCatalog)

    the manifest of all files previously ingested



124
125
126
# File 'lib/preservation/client/objects.rb', line 124

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

Parameters:

  • druid (String)
    • with or without prefix: ‘druid:ab123cd4567’ or ‘ab123cd4567’

Returns:

  • (String)

    “ok” when job queued

Raises:



117
118
119
# File 'lib/preservation/client/objects.rb', line 117

def validate_moab(druid:)
  get("objects/#{druid}/validate_moab", {}, on_data: nil)
end