Module: Dor::Editable

Extended by:
ActiveSupport::Concern
Included in:
AdminPolicyObject
Defined in:
lib/dor/models/editable.rb

Overview

This is basically used just by APOs. Arguably “editable” is the wrong name.

Instance Method Summary collapse

Instance Method Details

#add_default_collection(val) ⇒ Object

Add a collection to the listing of collections for items governed by this apo.



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

def add_default_collection val
  xml = self..ng_xml
  reg=xml.search('//administrativeMetadata/registration').first
  unless reg
    reg=Nokogiri::XML::Node.new('registration',xml)
    xml.search('/administrativeMetadata').first.add_child(reg)
  end
  node=Nokogiri::XML::Node.new('collection',xml)
  node['id']=val
  reg.add_child(node)
  self..content=xml.to_s
end

#add_roleplayer(role, entity, type = :workgroup) ⇒ Object

Adds a person or group to a role in the APO role metadata datastream



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dor/models/editable.rb', line 23

def add_roleplayer role, entity, type=:workgroup
  xml=self..ng_xml
  group = type == :workgroup ? 'group' : 'person'
  nodes = xml.search('/roleMetadata/role[@type=\''+role+'\']')
  if nodes.length > 0
    group_node=Nokogiri::XML::Node.new(group, xml)
    id_node=Nokogiri::XML::Node.new('identifier', xml)
    group_node.add_child(id_node)
    id_node.content=entity
    id_node['type']=type.to_s
    nodes.first.add_child(group_node)
  else
    node=Nokogiri::XML::Node.new('role', xml)
    node['type']=role
    group_node=Nokogiri::XML::Node.new(group, xml)
    node.add_child group_node
    id_node=Nokogiri::XML::Node.new('identifier', xml)
    group_node.add_child(id_node)
    id_node.content=entity
    id_node['type']=type.to_s
    xml.search('/roleMetadata').first.add_child(node)
  end
  self..content=xml.to_s
end

#agreementObject



240
241
242
# File 'lib/dor/models/editable.rb', line 240

def agreement
  agreement_object ? agreement_object.pid : ''
end

#agreement=(val) ⇒ Object



243
244
245
# File 'lib/dor/models/editable.rb', line 243

def agreement=(val)
  self.agreement_object = Dor::Item.find val.to_s, :cast => true
end


113
114
115
# File 'lib/dor/models/editable.rb', line 113

def copyright_statement
  self.defaultObjectRights.copyright.first
end


116
117
118
# File 'lib/dor/models/editable.rb', line 116

def copyright_statement=(val)
  self.defaultObjectRights.update_values({[:copyright] => val})
end

#creative_commons_licenseObject



119
120
121
# File 'lib/dor/models/editable.rb', line 119

def creative_commons_license
  self.defaultObjectRights.creative_commons.first
end

#creative_commons_license=(val) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/dor/models/editable.rb', line 125

def creative_commons_license=(val)
  (machine, human)=val
  if creative_commons_license.nil?
    self.defaultObjectRights.add_child_node(self.defaultObjectRights.ng_xml.root, :creative_commons)
  end
  self.defaultObjectRights.update_values({[:creative_commons] => val})
end

#creative_commons_license_humanObject



122
123
124
# File 'lib/dor/models/editable.rb', line 122

def creative_commons_license_human
  self.defaultObjectRights.creative_commons_human.first
end

#creative_commons_license_human=(val) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/dor/models/editable.rb', line 132

def creative_commons_license_human=(val)
  if creative_commons_license_human.nil?
    #add the nodes
   self.defaultObjectRights.add_child_node(self.defaultObjectRights.ng_xml.root, :creative_commons)
  end
  self.defaultObjectRights.update_values({[:creative_commons_human] => val})
end

#default_collectionsArray

get all collections listed for this APO, used during registration



63
64
65
# File 'lib/dor/models/editable.rb', line 63

def default_collections
  return .term_values(:registration, :default_collection)
end

#default_rightsString



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/dor/models/editable.rb', line 140

def default_rights
  xml=self.defaultObjectRights.ng_xml
  if xml.search('//rightsMetadata/access[@type=\'read\']/machine/group').length == 1
    'Stanford'
  elsif xml.search('//rightsMetadata/access[@type=\'read\']/machine/world').length ==1
    'World'
  elsif xml.search('//rightsMetadata/access[@type=\'discover\']/machine/none').length == 1
    'Dark'
  else
    'None'
  end
end

#default_rights=(rights) ⇒ Object

Set the rights in default object rights



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/dor/models/editable.rb', line 154

def default_rights=(rights)
  rights=rights.downcase
  rights_xml = self.defaultObjectRights.ng_xml
  rights_xml.search('//rightsMetadata/access[@type=\'discover\']/machine').each do |node|
    node.children.remove
    world_node=Nokogiri::XML::Node.new((rights=='dark' ? 'none' : 'world'),rights_xml)
    node.add_child(world_node)
  end
  rights_xml.search('//rightsMetadata/access[@type=\'read\']').each do |node|
    node.children.remove
    machine_node=Nokogiri::XML::Node.new('machine',rights_xml)
    if rights == 'world'
      world_node=Nokogiri::XML::Node.new(rights,rights_xml)
      node.add_child(machine_node)
      machine_node.add_child(world_node)
    elsif rights == 'stanford'
      world_node=Nokogiri::XML::Node.new(rights,rights_xml)
      node.add_child(machine_node)
      group_node=Nokogiri::XML::Node.new('group',rights_xml)
      group_node.content="Stanford"
      node.add_child(machine_node)
      machine_node.add_child(group_node)
    elsif rights == 'none' || rights == 'dark'
      none_node=Nokogiri::XML::Node.new('none',rights_xml)
      node.add_child(machine_node)
      machine_node.add_child(none_node)
    else
      raise ArgumentError, "Unrecognized rights value '#{rights}'"
    end
  end
end

#default_workflow=(wf) ⇒ Object

set a single default workflow



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/dor/models/editable.rb', line 223

def default_workflow=(wf)
  xml = self..ng_xml
  nodes=xml.search('//registration/workflow')
  if nodes.first
    nodes.first['id']=wf
  else
    nodes=xml.search('//registration')
    unless nodes.first
      reg_node=Nokogiri::XML::Node.new('registration',xml)
      xml.root.add_child(reg_node)
    end
    nodes=xml.search('//registration')
    wf_node=Nokogiri::XML::Node.new('workflow',xml)
    wf_node['id']=wf
    nodes.first.add_child(wf_node)
  end
end

#default_workflowsArray

List of default workflows, used to provide choices at registration



208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/dor/models/editable.rb', line 208

def default_workflows
  xml=self..ng_xml
  nodes=self..term_values(:registration, :workflow_id)
  if nodes.length > 0
    wfs=[]
    nodes.each do |node|
      wfs << node
    end
    wfs
  else
    []
  end
end

#desc_metadata_formatObject



186
187
188
# File 'lib/dor/models/editable.rb', line 186

def 
  self...first
end

#desc_metadata_format=(format) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/dor/models/editable.rb', line 189

def (format)
  #create the node if it isnt there already
  unless self...first
    self..add_child_node(self..ng_xml.root, :metadata_format)
  end
  self..update_values({[:metadata_format] => format})
end

#desc_metadata_sourceObject



196
197
198
# File 'lib/dor/models/editable.rb', line 196

def 
  self...first
end

#desc_metadata_source=(source) ⇒ Object



199
200
201
202
203
204
205
# File 'lib/dor/models/editable.rb', line 199

def (source)
  #create the node if it isnt there already
  unless self...first
    self..add_child_node(self..ng_xml.root, :metadata_source)
  end
  self..update_values({[:metadata_source] => format})
end

#metadata_sourceObject



98
99
100
# File 'lib/dor/models/editable.rb', line 98

def 
  self...first
end

#metadata_source=(val) ⇒ Object



101
102
103
104
105
106
# File 'lib/dor/models/editable.rb', line 101

def (val)
  if self...nil?
    self..add_child_node(self., :descMetadata)
  end
  self..update_values({[:descMetadata, :source] => val})
end

#mods_titleObject



55
56
57
# File 'lib/dor/models/editable.rb', line 55

def mods_title
  return self..term_values(:title_info, :main_title).first
end

#mods_title=(val) ⇒ Object



58
59
60
# File 'lib/dor/models/editable.rb', line 58

def mods_title=(val)
  self..update_values({[:title_info, :main_title] => val})
end

#purge_rolesObject

remove all people groups and roles from the APO role metadata datastream



49
50
51
52
53
# File 'lib/dor/models/editable.rb', line 49

def purge_roles
  self..ng_xml.search('/roleMetadata/role').each do |node|
    node.remove
  end
end

#remove_default_collection(val) ⇒ Object



81
82
83
84
85
# File 'lib/dor/models/editable.rb', line 81

def remove_default_collection val
  xml = self..ng_xml
  xml.search('//administrativeMetadata/registration/collection[@id=\''+val+'\']').remove
  self..content=xml.to_s
end

#rolesHash

Get all roles defined in the role metadata, and the people or groups in those roles. Groups are prefixed with ‘workgroup:’



88
89
90
91
92
93
94
95
96
97
# File 'lib/dor/models/editable.rb', line 88

def roles
  roles={}
  self..ng_xml.search('/roleMetadata/role').each do |role|
    roles[role['type']]=[]
    role.search('identifier').each do |entity|
      roles[role['type']] << entity['type'] + ':' + entity.text()
    end
  end
  roles
end

#to_solr(solr_doc = Hash.new, *args) ⇒ Object



11
12
13
14
15
16
# File 'lib/dor/models/editable.rb', line 11

def to_solr(solr_doc=Hash.new, *args)
  super(solr_doc, *args)
  add_solr_value(solr_doc, "default_rights", default_rights, :string, [:symbol])
  add_solr_value(solr_doc, "agreement", agreement, :string, [:symbol]) if agreement_object
  solr_doc
end

#use_statementObject



107
108
109
# File 'lib/dor/models/editable.rb', line 107

def use_statement
  self.defaultObjectRights.use_statement.first
end

#use_statement=(val) ⇒ Object



110
111
112
# File 'lib/dor/models/editable.rb', line 110

def use_statement=(val)
  self.defaultObjectRights.update_values({[:use_statement] => val})
end