Class: Rubydora::Fc3Service

Inherits:
Object
  • Object
show all
Includes:
AuditTrail, RestApiClient
Defined in:
lib/rubydora/fc3_service.rb

Overview

This class abstracts away all of the API details including XML parsing This allows the driver (Fc3Service) to be swapped out without having to modify the ORM layer (e.g. Datastream, DigitalObject, Repository)

Constant Summary

Constants included from RestApiClient

RestApiClient::DEFAULT_CONTENT_TYPE

Constants included from FedoraUrlHelpers

Rubydora::FedoraUrlHelpers::API_DOCUMENTATION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AuditTrail

#audit_trail

Methods included from RestApiClient

#add_datastream, #add_relationship, #client, #datastream, #datastream_dissemination, #datastream_versions, #datastreams, #describe, #dissemination, #export, #find_objects, #ingest, #logger, #mint_pid_and_ingest, #modify_datastream, #modify_object, #next_pid, #object, #object_versions, #object_xml, #purge_datastream, #purge_object, #purge_relationship, #relationships, #safe_subresource, #set_datastream_options

Methods included from FedoraUrlHelpers

#datastream_content_url, #datastream_history_url, #datastream_url, #datastreams_url, #describe_repository_url, #dissemination_url, #export_object_url, #find_objects_url, #new_object_relationship_url, #new_object_url, #next_pid_url, #object_relationship_url, #object_url, #object_versions_url, #object_xml_url, #url_for, #validate_object_url

Constructor Details

#initialize(config) ⇒ Fc3Service

Returns a new instance of Fc3Service.



10
11
12
# File 'lib/rubydora/fc3_service.rb', line 10

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/rubydora/fc3_service.rb', line 9

def config
  @config
end

Instance Method Details

#datastream_profile(pid, dsid, validateChecksum, asOfDateTime = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubydora/fc3_service.rb', line 51

def datastream_profile(pid, dsid, validateChecksum, asOfDateTime = nil)
  xml = begin
    options = {pid: pid, dsid: dsid}
    options[:validateChecksum] = validateChecksum if validateChecksum
    options[:asOfDateTime] = asOfDateTime if asOfDateTime
    options[:validateChecksum] = true if config[:validateChecksum]
    datastream(options)
  rescue RestClient::Unauthorized => e
    raise e
  rescue RestClient::ResourceNotFound
    # the datastream is new
    return {}
  end

  ProfileParser.parse_datastream_profile(xml)
end

#mint(options = {}) ⇒ Object

Reserve a new pid for the object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :namespace (String)

    the namespece for the pid



17
18
19
20
21
22
23
24
# File 'lib/rubydora/fc3_service.rb', line 17

def mint(options={})
  d = Nokogiri::XML(next_pid(options))
  if d.namespaces.values.include? 'http://www.fedora.info/definitions/1/0/management/'
    d.xpath('//fedora:pid', 'fedora' => 'http://www.fedora.info/definitions/1/0/management/').text
  else
    d.xpath('//pid').text
  end
end

#object_profile(pid, asOfDateTime = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/rubydora/fc3_service.rb', line 40

def object_profile(pid, asOfDateTime = nil)
  options = {pid: pid}
  options[:asOfDateTime] = asOfDateTime if asOfDateTime
  begin
    xml = object(options)
    ProfileParser.parse_object_profile(xml)
  rescue RestClient::ResourceNotFound
    {}
  end
end

#repository_profileHash

repository profile (from API-A-LITE data)

Returns:

  • (Hash)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rubydora/fc3_service.rb', line 28

def repository_profile
  profile_xml = self.describe.strip
  h = ProfileParser.parse_repository_profile(profile_xml)
  h.select { |key, value| value.length == 1 }.each do |key, value|
    next if key == 'objModels'
    h[key] = value.first
  end
  h
rescue
  nil
end

#versions_for_datastream(pid, dsid) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rubydora/fc3_service.rb', line 68

def versions_for_datastream(pid, dsid)
  versions_xml = datastream_versions(:pid => pid, :dsid => dsid)
  return {} if versions_xml.nil?
  versions_xml.gsub! '<datastreamProfile', '<datastreamProfile xmlns="http://www.fedora.info/definitions/1/0/management/"' unless versions_xml =~ /xmlns=/
  doc = Nokogiri::XML(versions_xml)
  versions = {}
  doc.xpath('//management:datastreamProfile', {'management' => "http://www.fedora.info/definitions/1/0/management/"} ).each do |ds|
    key = ds.xpath('management:dsCreateDate', 'management' => "http://www.fedora.info/definitions/1/0/management/").text
    versions[key] = ProfileParser.parse_datastream_profile(ds.to_s)
  end
  versions
end

#versions_for_object(pid) ⇒ Object



81
82
83
84
85
86
# File 'lib/rubydora/fc3_service.rb', line 81

def versions_for_object(pid)
  versions_xml = object_versions(:pid => pid)
  versions_xml.gsub! '<fedoraObjectHistory', '<fedoraObjectHistory xmlns="http://www.fedora.info/definitions/1/0/access/"' unless versions_xml =~ /xmlns=/
  doc = Nokogiri::XML(versions_xml)
  doc.xpath('//access:objectChangeDate', {'access' => 'http://www.fedora.info/definitions/1/0/access/' } ).map(&:text)
end