Class: Sdr::Client
- Inherits:
-
Object
- Object
- Sdr::Client
- Defined in:
- lib/dor/utils/sdr_client.rb
Class Method Summary collapse
- .client ⇒ Object
-
.current_version(druid) ⇒ Integer
The current version from SDR.
-
.get_content_diff(druid, current_content, subset = :all, version = nil) ⇒ Moab::FileInventoryDifference
The differences for the given content and subset.
- .get_preserved_file_content(druid, filename, version) ⇒ Object
-
.get_sdr_metadata(druid, dsname) ⇒ String
The datastream contents from the previous version of the digital object (fetched from SDR storage).
-
.get_signature_catalog(druid) ⇒ Moab::SignatureCatalog
The catalog of all files previously ingested.
Class Method Details
.client ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/dor/utils/sdr_client.rb', line 57 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.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dor/utils/sdr_client.rb', line 9 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.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dor/utils/sdr_client.rb', line 40 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
53 54 55 |
# File 'lib/dor/utils/sdr_client.rb', line 53 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).
24 25 26 27 28 |
# File 'lib/dor/utils/sdr_client.rb', line 24 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.
32 33 34 35 36 37 |
# File 'lib/dor/utils/sdr_client.rb', line 32 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 |