class Dor::RightsMetadataDS
Constants
- RIGHTS_TYPE_CODES
Public Class Methods
upd_rights_xml_for_rights_type(rights_xml, rights_type)
click to toggle source
a helper method for setting up well-structured rights_xml based on a rights type code @param rights_xml [ng_xml] a nokogiri xml (ruby) object that represents the rights xml for a DOR object @param rights_type [string] a recognized rights type code ('world', 'dark', 'loc:spec', etc)
# File lib/dor/datastreams/rights_metadata_ds.rb, line 106 def self.upd_rights_xml_for_rights_type(rights_xml, rights_type) # Note: The discover node is either 'none' for a dark object or 'world' for any other rights option label = rights_type == 'dark' ? 'none' : 'world' rights_xml.search('//rightsMetadata/access[@type=\'discover\']/machine').each do |node| node.children.remove node.add_child Nokogiri::XML::Node.new(label, rights_xml) end # The read node varies by rights option rights_xml.search('//rightsMetadata/access[@type=\'read\']').each do |node| node.children.remove machine_node = Nokogiri::XML::Node.new('machine', rights_xml) node.add_child(machine_node) if rights_type.start_with?('world') world_node = Nokogiri::XML::Node.new('world', rights_xml) world_node.set_attribute('rule', 'no-download') if rights_type.end_with?('-nd') machine_node.add_child(world_node) elsif rights_type.start_with?('stanford') group_node = Nokogiri::XML::Node.new('group', rights_xml) group_node.content = 'stanford' group_node.set_attribute('rule', 'no-download') if rights_type.end_with?('-nd') machine_node.add_child(group_node) elsif rights_type.start_with?('loc:') loc_node = Nokogiri::XML::Node.new('location', rights_xml) loc_node.content = rights_type.split(':').last machine_node.add_child(loc_node) elsif rights_type.start_with?('cdl') cdl_node = Nokogiri::XML::Node.new('cdl', rights_xml) group_node = Nokogiri::XML::Node.new('group', cdl_node) group_node.content = 'stanford' group_node.set_attribute('rule', 'no-download') cdl_node.add_child(group_node) machine_node.add_child(cdl_node) else # we know it is none or dark by the argument filter (first line) machine_node.add_child Nokogiri::XML::Node.new('none', rights_xml) end end end
valid_rights_type?(rights)
click to toggle source
# File lib/dor/datastreams/rights_metadata_ds.rb, line 99 def self.valid_rights_type?(rights) RightsMetadataDS.valid_rights_types.include? rights end
valid_rights_types()
click to toggle source
key is the rights type code, used by e.g. RightsMetadataDS#set_read_rights
and AdminPolicyObject#default_rights= value is the human-readable string, used for indexing, and for things like building select lists in the argo UI.
# File lib/dor/datastreams/rights_metadata_ds.rb, line 95 def self.valid_rights_types RIGHTS_TYPE_CODES.keys end
xml_template()
click to toggle source
# File lib/dor/datastreams/rights_metadata_ds.rb, line 46 def self.xml_template Nokogiri::XML::Builder.new do |xml| xml.rightsMetadata do xml.access(type: 'discover') do xml.machine { xml.none } end xml.access(type: 'read') do xml.machine { xml.none } # dark default end xml.use do xml.human(type: 'useAndReproduction') xml.human(type: 'creativeCommons') xml.machine(type: 'creativeCommons', uri: '') xml.human(type: 'openDataCommons') xml.machine(type: 'openDataCommons', uri: '') end xml.copyright { xml.human } end end.doc end
Public Instance Methods
content=(xml)
click to toggle source
just a wrapper to invalidate @dra_object
Calls superclass method
# File lib/dor/datastreams/rights_metadata_ds.rb, line 84 def content=(xml) @dra_object = nil super end
dra_object()
click to toggle source
# File lib/dor/datastreams/rights_metadata_ds.rb, line 89 def dra_object @dra_object ||= Dor::RightsAuth.parse(ng_xml, true) end
rights()
click to toggle source
# File lib/dor/datastreams/rights_metadata_ds.rb, line 170 def rights xml = 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
set_read_rights(rights)
click to toggle source
@param rights [string] archetypical rights to assign: 'world', 'stanford', 'none', 'dark', etc slight misnomer: also sets discover rights! TODO: convert xpath reads to dra_object
calls
# File lib/dor/datastreams/rights_metadata_ds.rb, line 148 def set_read_rights(rights) raise(ArgumentError, "Argument '#{rights}' is not a recognized value") unless RightsMetadataDS.valid_rights_type? rights rights_xml = ng_xml if rights_xml.search('//rightsMetadata/access[@type=\'read\']').length == 0 raise('The rights metadata stream doesnt contain an entry for machine read permissions. Consider populating it from the APO before trying to change it.') end ng_xml_will_change! RightsMetadataDS.upd_rights_xml_for_rights_type(rights_xml, rights) @dra_object = nil # until TODO complete, we'll expect to have to reparse after modification end
use_license()
click to toggle source
# File lib/dor/datastreams/rights_metadata_ds.rb, line 162 def use_license use_license = [] use_license += Array(creative_commons) use_license += Array(open_data_commons) use_license.reject(&:blank?) end