Class: Dor::RightsMetadataDS
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Dor::RightsMetadataDS
- Defined in:
- lib/dor/datastreams/rights_metadata_ds.rb
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#content=(xml) ⇒ Object
just a wrapper to invalidate @dra_object.
-
#set_read_rights(rights) ⇒ Object
Moved from Governable slight misnomer: also sets discover rights! TODO: convert xpath reads to dra_object calls.
- #to_solr(solr_doc = Hash.new, *args) ⇒ Object
Instance Attribute Details
#dra_object ⇒ Object
59 60 61 |
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 59 def dra_object @dra_object ||= Dor::RightsAuth.parse(self.ng_xml, true) end |
Class Method Details
.xml_template ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 34 def self.xml_template Nokogiri::XML::Builder.new do |xml| xml.rightsMetadata{ xml.access(:type => 'discover'){ xml.machine{ xml.none } } xml.access(:type => 'read'){ xml.machine{ xml.none } # dark default } xml.use{ xml.human(:type => 'useAndReproduction') xml.human(:type => "creativeCommons") xml.machine(:type => "creativeCommons") } xml.copyright{ xml.human } } end.doc end |
Instance Method Details
#content=(xml) ⇒ Object
just a wrapper to invalidate @dra_object
54 55 56 57 |
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 54 def content=(xml) @dra_object = nil super end |
#set_read_rights(rights) ⇒ Object
Moved from Governable slight misnomer: also sets discover rights! TODO: convert xpath reads to dra_object calls
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 67 def set_read_rights(rights) raise(ArgumentError, "Argument '#{rights}' is not a recognized value") unless ['world','stanford','none','dark'].include? rights rights_xml = self.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 label = rights=='dark' ? 'none' : 'world' @dra_object = nil # until TODO complete, we'll expect to have to reparse after modification 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 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 == 'world' machine_node.add_child Nokogiri::XML::Node.new(rights,rights_xml) elsif rights == 'stanford' group_node = Nokogiri::XML::Node.new('group',rights_xml) group_node.content = "Stanford" machine_node.add_child(group_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 |
#to_solr(solr_doc = Hash.new, *args) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 95 def to_solr(solr_doc=Hash.new, *args) super(solr_doc, *args) dra = self.dra_object solr_doc['rights_primary_ssi'] = dra.index_elements[:primary] solr_doc['rights_errors_ssim'] = dra.index_elements[:errors] if dra.index_elements[:errors].size > 0 solr_doc['rights_characteristics_ssim'] = dra.index_elements[:terms] if dra.index_elements[:terms].size > 0 # suppress empties %w[use_statement_ssim copyright_ssim].each do |key| solr_doc[key] = solr_doc[key].reject{ |val| val.nil? || val == '' }.flatten unless solr_doc[key].nil? end solr_doc end |