Class: Stanford::StorageServices

Inherits:
Moab::StorageServices show all
Defined in:
lib/stanford/storage_services.rb

Overview

An interface class to support access to SDR storage via a RESTful server

Constant Summary collapse

@@repository =

Returns an instance of the interface to SDR storage.

Returns:

Stanford::StorageRepository.new

Class Method Summary collapse

Methods inherited from Moab::StorageServices

current_version, deposit_branch, deposit_trunk, find_storage_object, object_path, object_size, object_version_path, repository, retrieve_file, retrieve_file_group, retrieve_file_signature, retrieve_file_using_signature, search_storage_objects, storage_object, storage_roots, version_differences, version_metadata

Class Method Details

.cm_remediate(object_id, version_id = nil) ⇒ String

Returns a remediated copy of the contentMetadata with fixity data filled in

Parameters:

  • object_id (String)

    The digital object identifier of the object whose contentMetadata is to be remediated

  • version_id (Integer) (defaults to: nil)

    The ID of the version whose file data is to be used, if nil use latest version

Returns:

  • (String)

    Returns a remediated copy of the contentMetadata with fixity data filled in


58
59
60
61
62
# File 'lib/stanford/storage_services.rb', line 58

def self.cm_remediate(object_id, version_id = nil)
  cm = retrieve_file('metadata', 'contentMetadata.xml', object_id, version_id)
  group = retrieve_file_group('content', object_id, version_id)
  Stanford::ContentInventory.new.(cm, group)
end

.cm_version_additions(new_content_metadata, object_id, version_id = nil) ⇒ FileInventory

Returns The versionAddtions report showing which files are new or modified in the content metadata.

Parameters:

  • new_content_metadata (String)

    The content metadata to be compared to the current signtature catalog

  • object_id (String)

    The digital object identifier of the object whose signature catalog is to be used

  • version_id (Integer) (defaults to: nil)

    The ID of the version whose signature catalog is to be used, if nil use latest version

Returns:

  • (FileInventory)

    The versionAddtions report showing which files are new or modified in the content metadata


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/stanford/storage_services.rb', line 40

def self.cm_version_additions(, object_id, version_id = nil)
  new_inventory = Stanford::ContentInventory.new.inventory_from_cm(, object_id, 'preserve')
  begin
    # ObjectNotFoundException is raised if the object does not exist in storage
    version_id ||= current_version(object_id)
    storage_object_version = @@repository.storage_object(object_id).find_object_version(version_id)
    signature_catalog = storage_object_version.signature_catalog
  rescue Moab::ObjectNotFoundException
    storage_object = Moab::StorageObject.new(object_id, 'dummy')
    base_version = Moab::StorageObjectVersion.new(storage_object, 0)
    signature_catalog = base_version.signature_catalog
  end
  signature_catalog.version_additions(new_inventory)
end

.compare_cm_to_version(new_content_metadata, object_id, subset, base_version = nil) ⇒ FileInventoryDifference

Returns The report of differences between the content metadata and the specified version.

Parameters:

  • new_content_metadata (String)

    The content metadata to be compared to the base

  • object_id (String)

    The digital object identifier of the object whose version inventory is the basis of the comparison

  • subset (String)

    Speciifes which subset of files to list in the inventories extracted from the contentMetadata (all|preserve|publish|shelve)

  • base_version (Integer) (defaults to: nil)

    The ID of the version whose inventory is the basis of, if nil use latest version

Returns:

  • (FileInventoryDifference)

    The report of differences between the content metadata and the specified version


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stanford/storage_services.rb', line 16

def self.compare_cm_to_version(, object_id, subset, base_version = nil)
  new_inventory = Stanford::ContentInventory.new.inventory_from_cm(, object_id, subset)
  begin
    # ObjectNotFoundException is raised if the object does not exist in storage
    base_version ||= current_version(object_id)
    # FileNotFoundException is raised if object exists but has no contentMetadata file
    base_cm_pathname = retrieve_file('metadata', 'contentMetadata.xml', object_id, base_version)
    base_inventory = Stanford::ContentInventory.new.inventory_from_cm(base_cm_pathname.read, object_id, subset, base_version)
  rescue Moab::ObjectNotFoundException, Moab::FileNotFoundException
    # Create a skeletal FileInventory object, containing no file entries
    storage_object = Moab::StorageObject.new(object_id, 'dummy')
    base_version = Moab::StorageObjectVersion.new(storage_object, 0)
    base_inventory = base_version.file_inventory('version')
  end
  diff = Moab::FileInventoryDifference.new.compare(base_inventory, new_inventory)
   = diff.group_difference('metadata')
  diff.group_differences.delete() if 
  diff
end