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.
Constant Summary collapse
- CREATIVE_COMMONS_USE_LICENSES =
these hashes map short (“machine”) license codes to their corresponding URIs and human readable titles. they also allow for deprecated entries (via optional :deprecation_warning). clients that use these maps are advised to only display undeprecated entries, except where a deprecated entry is already in use by an object. e.g., an APO that already specifies “by_sa” for its default license code could continue displaying that in a list of license options for editing, preferably with the deprecation warning. but other deprecated entries would be omitted in such a selectbox. TODO: seems like Editable is not the most semantically appropriate place for these mappings? though they’re used by methods that live in Editable. TODO: need some way to do versioning. for instance, what happens when a new version of an existing license comes out, since it will presumably use the same license code, but a different title and URI?
{ 'by' => { :human_readable => 'Attribution 3.0 Unported', :uri => 'https://creativecommons.org/licenses/by/3.0/' }, 'by-sa' => { :human_readable => 'Attribution Share Alike 3.0 Unported', :uri => 'https://creativecommons.org/licenses/by-sa/3.0/' }, 'by_sa' => { :human_readable => 'Attribution Share Alike 3.0 Unported', :uri => 'https://creativecommons.org/licenses/by-sa/3.0/', :deprecation_warning => 'license code "by_sa" was a typo in argo, prefer "by-sa"' }, 'by-nd' => { :human_readable => 'Attribution No Derivatives 3.0 Unported', :uri => 'https://creativecommons.org/licenses/by-nd/3.0/' }, 'by-nc' => { :human_readable => 'Attribution Non-Commercial 3.0 Unported', :uri => 'https://creativecommons.org/licenses/by-nc/3.0/' }, 'by-nc-sa' => { :human_readable => 'Attribution Non-Commercial Share Alike 3.0 Unported', :uri => 'https://creativecommons.org/licenses/by-nc-sa/3.0/' }, 'by-nc-nd' => { :human_readable => 'Attribution Non-Commercial, No Derivatives 3.0 Unported', :uri => 'https://creativecommons.org/licenses/by-nc-nd/3.0/' }, 'pdm' => { :human_readable => 'Public Domain Mark 1.0', :uri => 'https://creativecommons.org/publicdomain/mark/1.0/'} }.freeze
- OPEN_DATA_COMMONS_USE_LICENSES =
{ 'pddl' => { :human_readable => 'Open Data Commons Public Domain Dedication and License 1.0', :uri => 'http://opendatacommons.org/licenses/pddl/1.0/' }, 'odc-by' => { :human_readable => 'Open Data Commons Attribution License 1.0', :uri => 'http://opendatacommons.org/licenses/by/1.0/' }, 'odc-odbl' => { :human_readable => 'Open Data Commons Open Database License 1.0', :uri => 'http://opendatacommons.org/licenses/odbl/1.0/' } }.freeze
Instance Method Summary collapse
-
#add_default_collection(val) ⇒ Object
Add a collection to the listing of collections for items governed by this apo.
-
#add_roleplayer(role, entity, type = :workgroup) ⇒ Object
Adds a person or group to a role in the APO role metadata datastream.
- #agreement ⇒ Object
- #agreement=(val) ⇒ Object
- #copyright_statement ⇒ Object
- #copyright_statement=(val) ⇒ Object
- #creative_commons_license ⇒ Object
- #creative_commons_license=(use_license_machine) ⇒ Object
- #creative_commons_license_human ⇒ Object
- #creative_commons_license_human=(use_license_human) ⇒ Object
-
#default_collections ⇒ Array
get all collections listed for this APO, used during registration.
-
#default_rights ⇒ String
A description of the rights defined in the default object rights datastream.
-
#default_rights=(rights) ⇒ Object
Set the rights in default object rights.
-
#default_workflow=(wf) ⇒ Object
set a single default workflow.
-
#default_workflows ⇒ Array
List of default workflows, used to provide choices at registration.
- #desc_metadata_format ⇒ Object
- #desc_metadata_format=(format) ⇒ Object
- #desc_metadata_source ⇒ Object
- #desc_metadata_source=(source) ⇒ Object
- #metadata_source ⇒ Object
- #metadata_source=(val) ⇒ Object
- #mods_title ⇒ Object
- #mods_title=(val) ⇒ Object
- #open_data_commons_license ⇒ Object
- #open_data_commons_license=(use_license_machine) ⇒ Object
- #open_data_commons_license_human ⇒ Object
- #open_data_commons_license_human=(use_license_human) ⇒ Object
-
#purge_roles ⇒ Object
remove all people groups and roles from the APO role metadata datastream.
- #remove_default_collection(val) ⇒ Object
-
#roles ⇒ Hash
Get all roles defined in the role metadata, and the people or groups in those roles.
- #to_solr(solr_doc = {}, *args) ⇒ Object
- #use_license ⇒ Object
-
#use_license=(use_license_machine) ⇒ Object
If set to ‘:none` then Use License is removed.
- #use_license_human ⇒ Object
- #use_license_uri ⇒ Object
- #use_statement ⇒ Object
- #use_statement=(val) ⇒ Object
Instance Method Details
#add_default_collection(val) ⇒ Object
Add a collection to the listing of collections for items governed by this apo.
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/dor/models/editable.rb', line 107 def add_default_collection(val) xml = administrativeMetadata.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) administrativeMetadata.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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/dor/models/editable.rb', line 61 def add_roleplayer(role, entity, type = :workgroup) xml = roleMetadata.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 roleMetadata.content = xml.to_s end |
#agreement ⇒ Object
326 327 328 |
# File 'lib/dor/models/editable.rb', line 326 def agreement agreement_object ? agreement_object.pid : '' end |
#agreement=(val) ⇒ Object
329 330 331 332 |
# File 'lib/dor/models/editable.rb', line 329 def agreement=(val) fail ArgumentError, 'agreement must have a valid druid' if val.blank? self.agreement_object = Dor::Item.find val.to_s, :cast => true end |
#copyright_statement ⇒ Object
155 156 157 |
# File 'lib/dor/models/editable.rb', line 155 def copyright_statement defaultObjectRights.copyright.first end |
#copyright_statement=(val) ⇒ Object
158 159 160 |
# File 'lib/dor/models/editable.rb', line 158 def copyright_statement=(val) defaultObjectRights.update_term!(:copyright, val.nil? ? '' : val) end |
#creative_commons_license ⇒ Object
162 163 164 |
# File 'lib/dor/models/editable.rb', line 162 def creative_commons_license defaultObjectRights.creative_commons.first end |
#creative_commons_license=(use_license_machine) ⇒ Object
192 193 194 195 196 |
# File 'lib/dor/models/editable.rb', line 192 def creative_commons_license=(use_license_machine) defaultObjectRights.initialize_term!(:creative_commons) defaultObjectRights.creative_commons = use_license_machine defaultObjectRights.creative_commons.uri = CREATIVE_COMMONS_USE_LICENSES[use_license_machine][:uri] end |
#creative_commons_license_human ⇒ Object
165 166 167 |
# File 'lib/dor/models/editable.rb', line 165 def creative_commons_license_human defaultObjectRights.creative_commons_human.first end |
#creative_commons_license_human=(use_license_human) ⇒ Object
197 198 199 200 |
# File 'lib/dor/models/editable.rb', line 197 def creative_commons_license_human=(use_license_human) defaultObjectRights.initialize_term!(:creative_commons_human) defaultObjectRights.creative_commons_human = use_license_human end |
#default_collections ⇒ Array
get all collections listed for this APO, used during registration
102 103 104 |
# File 'lib/dor/models/editable.rb', line 102 def default_collections administrativeMetadata.term_values(:registration, :default_collection) end |
#default_rights ⇒ String
Returns A description of the rights defined in the default object rights datastream. Can be ‘Stanford’, ‘World’, ‘Dark’ or ‘None’.
233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/dor/models/editable.rb', line 233 def default_rights xml = 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
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/dor/models/editable.rb', line 247 def default_rights=(rights) rights = rights.downcase rights_xml = 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' 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
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/dor/models/editable.rb', line 307 def default_workflow=(wf) fail ArgumentError, 'Must have a valid workflow for default' if wf.blank? xml = administrativeMetadata.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_workflows ⇒ Array
List of default workflows, used to provide choices at registration
302 303 304 |
# File 'lib/dor/models/editable.rb', line 302 def default_workflows administrativeMetadata.term_values(:registration, :workflow_id) end |
#desc_metadata_format ⇒ Object
278 279 280 |
# File 'lib/dor/models/editable.rb', line 278 def administrativeMetadata..first end |
#desc_metadata_format=(format) ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/dor/models/editable.rb', line 281 def (format) # create the node if it isnt there already unless administrativeMetadata..first administrativeMetadata.add_child_node(administrativeMetadata.ng_xml.root, :metadata_format) end administrativeMetadata.update_values({[:metadata_format] => format}) end |
#desc_metadata_source ⇒ Object
289 290 291 |
# File 'lib/dor/models/editable.rb', line 289 def administrativeMetadata..first end |
#desc_metadata_source=(source) ⇒ Object
292 293 294 295 296 297 298 |
# File 'lib/dor/models/editable.rb', line 292 def (source) # create the node if it isnt there already unless administrativeMetadata..first administrativeMetadata.add_child_node(administrativeMetadata.ng_xml.root, :metadata_source) end administrativeMetadata.update_values({[:metadata_source] => format}) end |
#metadata_source ⇒ Object
138 139 140 |
# File 'lib/dor/models/editable.rb', line 138 def administrativeMetadata..first end |
#metadata_source=(val) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/dor/models/editable.rb', line 141 def (val) if administrativeMetadata.descMetadata.nil? administrativeMetadata.add_child_node(administrativeMetadata, :descMetadata) end administrativeMetadata.update_values({[:descMetadata, :source] => val}) end |
#mods_title ⇒ Object
93 94 95 |
# File 'lib/dor/models/editable.rb', line 93 def mods_title descMetadata.term_values(:title_info, :main_title).first end |
#mods_title=(val) ⇒ Object
96 97 98 |
# File 'lib/dor/models/editable.rb', line 96 def mods_title=(val) descMetadata.update_values({[:title_info, :main_title] => val}) end |
#open_data_commons_license ⇒ Object
169 170 171 |
# File 'lib/dor/models/editable.rb', line 169 def open_data_commons_license defaultObjectRights.open_data_commons.first end |
#open_data_commons_license=(use_license_machine) ⇒ Object
202 203 204 205 206 |
# File 'lib/dor/models/editable.rb', line 202 def open_data_commons_license=(use_license_machine) defaultObjectRights.initialize_term!(:open_data_commons) defaultObjectRights.open_data_commons = use_license_machine defaultObjectRights.open_data_commons.uri = OPEN_DATA_COMMONS_USE_LICENSES[use_license_machine][:uri] end |
#open_data_commons_license_human ⇒ Object
172 173 174 |
# File 'lib/dor/models/editable.rb', line 172 def open_data_commons_license_human defaultObjectRights.open_data_commons_human.first end |
#open_data_commons_license_human=(use_license_human) ⇒ Object
207 208 209 210 |
# File 'lib/dor/models/editable.rb', line 207 def open_data_commons_license_human=(use_license_human) defaultObjectRights.initialize_term!(:open_data_commons_human) defaultObjectRights.open_data_commons_human = use_license_human end |
#purge_roles ⇒ Object
remove all people groups and roles from the APO role metadata datastream
87 88 89 90 91 |
# File 'lib/dor/models/editable.rb', line 87 def purge_roles roleMetadata.ng_xml.search('/roleMetadata/role').each do |node| node.remove end end |
#remove_default_collection(val) ⇒ Object
119 120 121 122 123 |
# File 'lib/dor/models/editable.rb', line 119 def remove_default_collection(val) xml = administrativeMetadata.ng_xml xml.search('//administrativeMetadata/registration/collection[@id=\'' + val + '\']').remove administrativeMetadata.content = xml.to_s end |
#roles ⇒ Hash
Get all roles defined in the role metadata, and the people or groups in those roles. Groups are prefixed with ‘workgroup:’
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dor/models/editable.rb', line 127 def roles roles = {} roleMetadata.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 = {}, *args) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/dor/models/editable.rb', line 48 def to_solr(solr_doc = {}, *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 add_solr_value(solr_doc, 'default_use_license_machine', use_license, :string, [:stored_sortable]) solr_doc end |
#use_license ⇒ Object
176 177 178 179 180 |
# File 'lib/dor/models/editable.rb', line 176 def use_license return creative_commons_license unless ['', nil].include?(creative_commons_license) return open_data_commons_license unless ['', nil].include?(open_data_commons_license) '' end |
#use_license=(use_license_machine) ⇒ Object
If set to ‘:none` then Use License is removed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/dor/models/editable.rb', line 214 def use_license=(use_license_machine) if use_license_machine.blank? || use_license_machine == :none # delete use license by directly removing the XML used to define the use license defaultObjectRights.update_term!(:creative_commons, ' ') defaultObjectRights.update_term!(:creative_commons_human, ' ') defaultObjectRights.update_term!(:open_data_commons, ' ') defaultObjectRights.update_term!(:open_data_commons_human, ' ') elsif CREATIVE_COMMONS_USE_LICENSES.include? use_license_machine self.creative_commons_license = use_license_machine self.creative_commons_license_human = CREATIVE_COMMONS_USE_LICENSES[use_license_machine][:human_readable] elsif OPEN_DATA_COMMONS_USE_LICENSES.include? use_license_machine self.open_data_commons_license = use_license_machine self.open_data_commons_license_human = OPEN_DATA_COMMONS_USE_LICENSES[use_license_machine][:human_readable] else fail ArgumentError, "'#{use_license_machine}' is not a valid license code" end end |
#use_license_human ⇒ Object
186 187 188 189 190 |
# File 'lib/dor/models/editable.rb', line 186 def use_license_human return creative_commons_license_human unless ['', nil].include?(creative_commons_license_human) return open_data_commons_license_human unless ['', nil].include?(open_data_commons_license_human) '' end |
#use_license_uri ⇒ Object
181 182 183 184 185 |
# File 'lib/dor/models/editable.rb', line 181 def use_license_uri return defaultObjectRights.creative_commons.uri.first unless ['', nil].include?(defaultObjectRights.creative_commons.uri) return defaultObjectRights.open_data_commons.uri.first unless ['', nil].include?(defaultObjectRights.open_data_commons.uri) '' end |
#use_statement ⇒ Object
148 149 150 |
# File 'lib/dor/models/editable.rb', line 148 def use_statement defaultObjectRights.use_statement.first end |
#use_statement=(val) ⇒ Object
151 152 153 |
# File 'lib/dor/models/editable.rb', line 151 def use_statement=(val) defaultObjectRights.update_term!(:use_statement, val.nil? ? '' : val) end |