Class: Fedora::FedoraObject
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
end
|
Instance Attribute Details
#target_repository ⇒ Object
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
142
143
144
|
# File 'lib/fedora/fedora_object.rb', line 142
def self.object_xml(pid=pid)
Fedora::Repository.instance.fetch_custom(pid, :objectXML)
end
|
Instance Method Details
#create_date ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/fedora/fedora_object.rb', line 52
def create_date
if attributes[:create_date]
return attributes[:create_date]
elsif !new_object?
properties_from_fedora[:create_date]
else
return nil
end
end
|
#label ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/fedora/fedora_object.rb', line 99
def label
if attributes[:label]
return attributes[:label]
elsif !new_object?
properties_from_fedora[:label]
else
return nil
end
end
|
#label=(new_label) ⇒ Object
109
110
111
|
# File 'lib/fedora/fedora_object.rb', line 109
def label=(new_label)
self.attributes[:label] = new_label
end
|
#load_attributes_from_fedora ⇒ Object
30
31
32
33
|
# File 'lib/fedora/fedora_object.rb', line 30
def load_attributes_from_fedora
attributes.merge!(properties_from_fedora)
end
|
#modified_date ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/fedora/fedora_object.rb', line 62
def modified_date
if attributes[:modified_date]
return attributes[:modified_date]
elsif !new_object?
properties_from_fedora[:modified_date]
else
return nil
end
end
|
#object_xml ⇒ Object
138
139
140
|
# File 'lib/fedora/fedora_object.rb', line 138
def object_xml
Fedora::Repository.instance.fetch_custom(pid, :objectXML)
end
|
#owner_id ⇒ Object
Get the object and read its @ownerId from the profile
114
115
116
117
118
119
120
121
122
|
# File 'lib/fedora/fedora_object.rb', line 114
def owner_id
if attributes[:owner_id]
return attributes[:owner_id]
elsif !new_object?
properties_from_fedora[:owner_id]
else
return nil
end
end
|
#owner_id=(new_owner_id) ⇒ Object
124
125
126
|
# File 'lib/fedora/fedora_object.rb', line 124
def owner_id=(new_owner_id)
self.attributes.merge!({:ownerID => new_owner_id})
end
|
#pid ⇒ Object
73
74
75
|
# File 'lib/fedora/fedora_object.rb', line 73
def pid
self.attributes[:pid]
end
|
#pid=(new_pid) ⇒ Object
77
78
79
|
# File 'lib/fedora/fedora_object.rb', line 77
def pid=(new_pid)
self.attributes.merge!({:pid => new_pid})
end
|
#profile ⇒ Object
128
129
130
131
132
133
134
135
136
|
# File 'lib/fedora/fedora_object.rb', line 128
def profile
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
|
#properties_from_fedora ⇒ Object
Reads all object properties from the object’s FOXML into a hash. Provides slightly more info than .profile, including the object state.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/fedora/fedora_object.rb', line 36
def properties_from_fedora
object_rexml = REXML::Document.new(object_xml)
properties = {
:pid => object_rexml.root.attributes["PID"],
:state => object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/model#state']"].attributes["VALUE"],
:create_date => object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/model#createdDate']"].attributes["VALUE"],
:modified_date => object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/view#lastModifiedDate']"].attributes["VALUE"],
:owner_id => object_rexml.root.elements['//foxml:property[@NAME="info:fedora/fedora-system:def/model#ownerId"]'].attributes['VALUE']
}
label_element = object_rexml.root.elements["//foxml:property[@NAME='info:fedora/fedora-system:def/model#label']"]
if label_element
properties.merge!({:label => label_element.attributes["VALUE"]})
end
return properties
end
|
#state ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'lib/fedora/fedora_object.rb', line 81
def state
if attributes[:state]
return attributes[:state]
elsif !new_object?
properties_from_fedora[:state]
else
return nil
end
end
|
#state=(new_state) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/fedora/fedora_object.rb', line 91
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
|
#uri ⇒ Object
147
148
149
|
# File 'lib/fedora/fedora_object.rb', line 147
def uri
"fedora:info/#{pid}"
end
|
#url ⇒ Object
152
153
154
155
|
# File 'lib/fedora/fedora_object.rb', line 152
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
|