Class: Fedora::FedoraObject

Inherits:
BaseObject show all
Defined in:
lib/fedora/fedora_object.rb

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#attributes, #blob, #errors, #new_object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseObject

#[], #new_object?

Constructor Details

#initialize(attrs = nil) ⇒ FedoraObject

Parameters

attrs<Hash>

fedora object attributes (see below)

Attributes (attrs)

namespace<Symbol>
pid<Symbol>
state<Symbol>
label<Symbol>
contentModel<Symbol>
objectXMLFormat<Symbol>
ownerID<Symbol>

-



20
21
22
23
# File 'lib/fedora/fedora_object.rb', line 20

def initialize(attrs = nil)
  super
  # TODO: check for required attributes
end

Instance Attribute Details

#target_repositoryObject

Returns the value of attribute target_repository.



6
7
8
# File 'lib/fedora/fedora_object.rb', line 6

def target_repository
  @target_repository
end

Class Method Details

.object_xml(pid = pid) ⇒ Object



109
110
111
# File 'lib/fedora/fedora_object.rb', line 109

def self.object_xml(pid=pid)
  Fedora::Repository.instance.fetch_custom(pid, :objectXML)
end

Instance Method Details

#create_dateObject



47
48
49
50
# File 'lib/fedora/fedora_object.rb', line 47

def create_date
  profile[:create_date]
  #self.attributes[:cDate]
end

#labelObject



78
79
80
# File 'lib/fedora/fedora_object.rb', line 78

def label
  self.attributes[:label]
end

#label=(new_label) ⇒ Object



82
83
84
# File 'lib/fedora/fedora_object.rb', line 82

def label=(new_label)
  self.attributes[:label] = new_label
end

#modified_dateObject



52
53
54
55
# File 'lib/fedora/fedora_object.rb', line 52

def modified_date
  profile[:create_date]
  #self.attributes[:mDate]
end

#object_xmlObject



105
106
107
# File 'lib/fedora/fedora_object.rb', line 105

def object_xml
  Fedora::Repository.instance.fetch_custom(pid, :objectXML)
end

#owner_idObject

Get the object and read its @ownerId from the profile



87
88
89
# File 'lib/fedora/fedora_object.rb', line 87

def owner_id
  self.attributes[:ownerID]
end

#owner_id=(new_owner_id) ⇒ Object



91
92
93
# File 'lib/fedora/fedora_object.rb', line 91

def owner_id=(new_owner_id)
  self.attributes.merge!({:ownerID => new_owner_id})
end

#pidObject



58
59
60
# File 'lib/fedora/fedora_object.rb', line 58

def pid
  self.attributes[:pid]
end

#pid=(new_pid) ⇒ Object



62
63
64
# File 'lib/fedora/fedora_object.rb', line 62

def pid=(new_pid)
  self.attributes.merge!({:pid => new_pid})
end

#profileObject



95
96
97
98
99
100
101
102
103
# File 'lib/fedora/fedora_object.rb', line 95

def profile
  # Use xmlsimple to slurp the attributes
  retrieved_profile = XmlSimple.xml_in(Fedora::Repository.instance.fetch_custom(self.pid, :profile))
  profile_hash = Hash[:owner_id => retrieved_profile["objOwnerId"],
                        :label => retrieved_profile["objLabel"],
                        :create_date =>  retrieved_profile["objCreateDate"],
                        :modified_date => retrieved_profile["objLastModDate"]
                      ]                           
end

#retrieve_attr_from_fedoraObject

TODO: Create appropriate attribute accessors for these values.

Where applicable, make sure that attributes are written to and read from self.attributes

pid, label, create_date, modified_date, fedora_object_type, contentModel, state, ownerID, behavior_def, behavior_mech,

API-M Search Value Equivalents: [pid, label, cDate, mDate, fType, cModel, state, ownerId, bDef, bMech,] TODO: Mix In DC attribute finders/accessors TODO: Make sure that fedora_object_type and contentModel are juggled properly.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fedora/fedora_object.rb', line 35

def retrieve_attr_from_fedora
  self.attributes.merge!(profile)
  object_rexml = REXML::Document.new(object_xml)
  self.attributes.merge!({
       :state => object_rexml.root.elements["objectProperties/property[@NAME='info:fedora/fedora-system:def/model#state']"].attributes["value"],
       :create_date => object_rexml.root.elements["objectProperties/property[@NAME='info:fedora/fedora-system:def/model#createdDate']"].attributes["value"],
       :modified_date => object_rexml.root.elements["objectProperties/property[@NAME='info:fedora/fedora-system:def/model#lastModifiedDate']"].attributes["value"],
       :label => object_rexml.root.elements["objectProperties/property[@NAME='info:fedora/fedora-system:def/model#label']"].attributes["value"]
  })

end

#stateObject



66
67
68
# File 'lib/fedora/fedora_object.rb', line 66

def state
  self.attributes[:state]
end

#state=(new_state) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/fedora/fedora_object.rb', line 70

def state=(new_state)
  if ["I", "A", "D"].include? new_state
    self.attributes[:state]  = new_state
  else
    raise 'The object state of "' + new_state + '" is invalid. The allowed values for state are:  A (active), D (deleted), and I (inactive).'
  end
end

#uriObject



114
115
116
# File 'lib/fedora/fedora_object.rb', line 114

def uri
  "fedora:info/#{pid}"
end

#urlObject



119
120
121
122
# File 'lib/fedora/fedora_object.rb', line 119

def url
  repo_url = Fedora::Repository.instance.fedora_url
  return "#{repo_url.scheme}://#{repo_url.host}:#{repo_url.port}#{repo_url.path}/objects/#{pid}"
end