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



147
148
149
# File 'lib/fedora/fedora_object.rb', line 147

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

Instance Method Details

#create_dateObject



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

#labelObject



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_fedoraObject



30
31
32
33
# File 'lib/fedora/fedora_object.rb', line 30

def load_attributes_from_fedora
  #self.attributes.merge!(profile)
  attributes.merge!(profile)
end

#modified_dateObject



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_xmlObject



143
144
145
# File 'lib/fedora/fedora_object.rb', line 143

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

#owner_idObject

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

#pidObject



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

#profileObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fedora/fedora_object.rb', line 128

def profile
  # Use xmlsimple to slurp the attributes
  retrieved_profile = XmlSimple.xml_in(Fedora::Repository.instance.fetch_custom(self.pid, :profile))
  label = retrieved_profile["objLabel"].first unless retrieved_profile["objLabel"].first == {}
  profile_hash = Hash[:pid => retrieved_profile["pid"],
                        :owner_id => retrieved_profile["objOwnerId"].first,
                        :label => label,
                        :create_date =>  retrieved_profile["objCreateDate"].first,
                        :modified_date => retrieved_profile["objLastModDate"].first,
                        :methods_list_url => retrieved_profile["objDissIndexViewURL"].first,
                        :datastreams_list_url => retrieved_profile["objItemIndexViewURL"].first,
                        :state => retrieved_profile["objState"].first 
                      ]                           
end

#properties_from_fedoraObject

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 profile_hash[:label]
  # properties.merge!({:label => label_element.attributes["VALUE"]})
  #end
  return profile
end

#stateObject



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

#uriObject



152
153
154
# File 'lib/fedora/fedora_object.rb', line 152

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

#urlString

Returns url of the datastream in Fedora, without the repository userinfo.

Returns:

  • (String)

    url of the datastream in Fedora, without the repository userinfo



157
158
159
160
# File 'lib/fedora/fedora_object.rb', line 157

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