Module: Dor::Editable

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

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.

Parameters:

  • val (String)

    pid of the collection, ex. druid:ab123cd4567



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dor/models/editable.rb', line 64

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

Parameters:

  • role (String)

    the role the group or person will be filed under, ex. dor-apo-manager

  • entity (String)

    the name of the person or group, ex dlss:developers or sunetid:someone

  • type (Symbol) (defaults to: :workgroup)

    :workgroup for a group or :person for a person



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

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



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

def agreement
  agreement_object ? agreement_object.pid : ''
end

#agreement=(val) ⇒ Object



247
248
249
# File 'lib/dor/models/editable.rb', line 247

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


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

def copyright_statement
  self.defaultObjectRights.copyright.first
end


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

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

#creative_commons_licenseObject



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

def creative_commons_license
  self.defaultObjectRights.creative_commons.first
end

#creative_commons_license=(val) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/dor/models/editable.rb', line 121

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



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

def creative_commons_license_human
  self.defaultObjectRights.creative_commons_human.first
end

#creative_commons_license_human=(val) ⇒ Object



128
129
130
131
132
133
134
135
# File 'lib/dor/models/editable.rb', line 128

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

Returns:

  • (Array)

    array of pids



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

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

#default_rightsString

Returns A description of the rights defined in the default object rights datastream. Can be ‘Stanford’, ‘World’, ‘Dark’ or ‘None’.

Returns:

  • (String)

    A description of the rights defined in the default object rights datastream. Can be ‘Stanford’, ‘World’, ‘Dark’ or ‘None’



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

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

#default_rights=(rights) ⇒ Object

Set the rights in default object rights

Parameters:

  • rights (String)

    Stanford, World, Dark, or None



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
185
186
187
188
# File 'lib/dor/models/editable.rb', line 155

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
    if rights=='dark'
        world_node=Nokogiri::XML::Node.new('none',rights_xml)
        node.add_child(world_node)
    else
        world_node=Nokogiri::XML::Node.new('world',rights_xml)
      node.add_child(world_node)
    end
  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)
    end
  end
end

#default_workflow=(wf) ⇒ Object

set a single default workflow

Parameters:

  • wf (String)

    the name of the workflow, ex. ‘digitizationWF’



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/dor/models/editable.rb', line 227

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

Returns:

  • (Array)

    and array of pids, ex [‘druid:ab123cd4567’]



212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/dor/models/editable.rb', line 212

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



190
191
192
# File 'lib/dor/models/editable.rb', line 190

def 
  self...first
end

#desc_metadata_format=(format) ⇒ Object



193
194
195
196
197
198
199
# File 'lib/dor/models/editable.rb', line 193

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



200
201
202
# File 'lib/dor/models/editable.rb', line 200

def 
  self...first
end

#desc_metadata_source=(source) ⇒ Object



203
204
205
206
207
208
209
# File 'lib/dor/models/editable.rb', line 203

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



94
95
96
# File 'lib/dor/models/editable.rb', line 94

def  
  self...first
end

#metadata_source=(val) ⇒ Object



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

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

#mods_titleObject



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

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

#mods_title=(val) ⇒ Object



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

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



45
46
47
48
49
# File 'lib/dor/models/editable.rb', line 45

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

#remove_default_collection(val) ⇒ Object



77
78
79
80
81
# File 'lib/dor/models/editable.rb', line 77

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:’

Returns:

  • (Hash)

    role => [‘person’,‘group’] ex. {“dor-apo-manager” => [“workgroup:dlss:developers”, “sunetid:lmcrae”]



84
85
86
87
88
89
90
91
92
93
# File 'lib/dor/models/editable.rb', line 84

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



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

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

#use_statementObject



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

def use_statement
  self.defaultObjectRights.use_statement.first
end

#use_statement=(val) ⇒ Object



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

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