Class: Sdr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/utils/sdr_client.rb

Class Method Summary collapse

Class Method Details

.clientObject



54
55
56
57
58
59
60
61
62
# File 'lib/dor/utils/sdr_client.rb', line 54

def client
  if Dor::Config.sdr.url
    Dor::Config.sdr.rest_client
  elsif Dor::Config.dor_services.url
    Dor::Config.dor_services.rest_client['v1/sdr']
  else
    raise Dor::ParameterError, 'Missing Dor::Config.sdr and/or Dor::Config.dor_services configuration'
  end
end

.current_version(druid) ⇒ Integer

Returns the current version from SDR.

Parameters:

  • druid (String)

    id of the object you want the version of

Returns:

  • (Integer)

    the current version from SDR



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dor/utils/sdr_client.rb', line 7

def current_version(druid)
  xml = client["objects/#{druid}/current_version"].get

  begin
    doc = Nokogiri::XML xml
    raise if doc.root.name != 'currentVersion'
    return Integer(doc.text)
  rescue
    raise "Unable to parse XML from SDR current_version API call: #{xml}"
  end
end

.get_content_diff(druid, current_content, subset = :all, version = nil) ⇒ Moab::FileInventoryDifference

Returns the differences for the given content and subset.

Returns:

  • (Moab::FileInventoryDifference)

    the differences for the given content and subset



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dor/utils/sdr_client.rb', line 37

def get_content_diff(druid, current_content, subset = :all, version = nil)
  unless %w(all shelve preserve publish).include?(subset.to_s)
    raise Dor::ParameterError, "Invalid subset value: #{subset}"
  end

  query_string = { :subset => subset.to_s }
  query_string[:version] = version.to_s unless version.nil?
  query_string = URI.encode_www_form(query_string)
  sdr_query = "objects/#{druid}/cm-inv-diff?#{query_string}"
  response = client[sdr_query].post(current_content, :content_type => 'application/xml')
  Moab::FileInventoryDifference.parse(response)
end

.get_preserved_file_content(druid, filename, version) ⇒ Object



50
51
52
# File 'lib/dor/utils/sdr_client.rb', line 50

def get_preserved_file_content(druid, filename, version)
  client["objects/#{druid}/content/#{URI.encode(filename)}?version=#{version}"].get
end

.get_sdr_metadata(druid, dsname) ⇒ String

Returns The datastream contents from the previous version of the digital object (fetched from SDR storage).

Parameters:

  • dsname (String)

    The identifier of the metadata datastream

Returns:

  • (String)

    The datastream contents from the previous version of the digital object (fetched from SDR storage)



21
22
23
24
25
# File 'lib/dor/utils/sdr_client.rb', line 21

def (druid, dsname)
  client["objects/#{druid}/metadata/#{dsname}.xml"].get
rescue RestClient::ResourceNotFound
  return nil
end

.get_signature_catalog(druid) ⇒ Moab::SignatureCatalog

Returns the catalog of all files previously ingested.

Parameters:

  • druid (String)

    The object identifier

Returns:

  • (Moab::SignatureCatalog)

    the catalog of all files previously ingested



29
30
31
32
33
34
# File 'lib/dor/utils/sdr_client.rb', line 29

def get_signature_catalog(druid)
  response = client["objects/#{druid}/manifest/signatureCatalog.xml"].get
  Moab::SignatureCatalog.parse(response)
rescue RestClient::ResourceNotFound
  Moab::SignatureCatalog.new(:digital_object_id => druid, :version_id => 0)
end