Module: Dor::Editable

Extended by:
ActiveSupport::Concern
Includes:
ActiveFedora::Relationships
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



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

def add_default_collection val
  ds=self.
  xml=ds.ng_xml
  reg=xml.search('//administrativeMetadata/registration').first
  if not 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



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

def add_roleplayer role, entity, type=:workgroup
  xml=self..ng_xml
  group='person'
  if type == :workgroup
    group='group'
  end
  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



256
257
258
259
260
261
262
# File 'lib/dor/models/editable.rb', line 256

def agreement
  if agreement_object 
    agreement_object.pid
  else
    ''
  end
end

#agreement=(val) ⇒ Object



263
264
265
# File 'lib/dor/models/editable.rb', line 263

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


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

def copyright_statement
  self.defaultObjectRights.copyright.first
end


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

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

#creative_commons_licenseObject



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

def creative_commons_license
  self.defaultObjectRights.creative_commons.first
end

#creative_commons_license=(val) ⇒ Object



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

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



126
127
128
# File 'lib/dor/models/editable.rb', line 126

def creative_commons_license_human
  self.defaultObjectRights.creative_commons_human.first
end

#creative_commons_license_human=(val) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/dor/models/editable.rb', line 136

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



65
66
67
# File 'lib/dor/models/editable.rb', line 65

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’



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/dor/models/editable.rb', line 145

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



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
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/dor/models/editable.rb', line 163

def default_rights=(rights)
  rights=rights.downcase
  ds = self.defaultObjectRights
  rights_xml=ds.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)
    end
    if 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)
    end
    if 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’



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/dor/models/editable.rb', line 238

def default_workflow=(wf)
  ds=self.
  xml=ds.ng_xml
  nodes=xml.search('//registration/workflow')
  if nodes.first
    nodes.first['id']=wf
  else
    nodes=xml.search('//registration')
    if not 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’]



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

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



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

def 
  self...first
end

#desc_metadata_format=(format) ⇒ Object



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

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

#desc_metadata_sourceObject



211
212
213
# File 'lib/dor/models/editable.rb', line 211

def 
  self...first
end

#desc_metadata_source=(source) ⇒ Object



214
215
216
217
218
219
220
# File 'lib/dor/models/editable.rb', line 214

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

#metadata_sourceObject



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

def  
  self...first
end

#metadata_source=(val) ⇒ Object



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

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

#mods_titleObject



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

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

#mods_title=(val) ⇒ Object



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

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
54
55
# File 'lib/dor/models/editable.rb', line 49

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

#remove_default_collection(val) ⇒ Object



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

def remove_default_collection val
  ds=self.
  xml=ds.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”]



92
93
94
95
96
97
98
99
100
101
# File 'lib/dor/models/editable.rb', line 92

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



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

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



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

def use_statement
  self.defaultObjectRights.use_statement.first
end

#use_statement=(val) ⇒ Object



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

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