Class: Dor::RightsMetadataDS

Inherits:
ActiveFedora::OmDatastream
  • Object
show all
Defined in:
lib/dor/datastreams/rights_metadata_ds.rb

Constant Summary collapse

RIGHTS_TYPE_CODES =
{
  'world' => 'World',
  'world-nd' => 'World (no-download)',
  'stanford' => 'Stanford',
  'stanford-nd' => 'Stanford (no-download)',
  'loc:spec' => 'Location: Special Collections',
  'loc:music' => 'Location: Music Library',
  'loc:ars' => 'Location: Archive of Recorded Sound',
  'loc:art' => 'Location: Art Library',
  'loc:hoover' => 'Location: Hoover Library',
  'loc:m&m' => 'Location: Media & Microtext',
  'dark' => 'Dark (Preserve Only)',
  'none' => 'Citation Only'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.upd_rights_xml_for_rights_type(rights_xml, rights_type) ⇒ Object

a helper method for setting up well-structured rights_xml based on a rights type code

Parameters:

  • rights_xml (ng_xml)

    a nokogiri xml (ruby) object that represents the rights xml for a DOR object

  • rights_type (string)

    a recognized rights type code (‘world’, ‘dark’, ‘loc:spec’, etc)



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 91

def self.upd_rights_xml_for_rights_type(rights_xml, rights_type)
  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

  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)
    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) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 84

def self.valid_rights_type?(rights)
  RightsMetadataDS.valid_rights_types.include? rights
end

.valid_rights_typesObject

key is the rights type code, used by e.g. RightsMetadataDS#set_read_rights and Editable#default_rights= value is the human-readable string, used for indexing, and for things like building select lists in the argo UI.



80
81
82
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 80

def self.valid_rights_types
  RIGHTS_TYPE_CODES.keys
end

.xml_templateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 31

def self.xml_template
  Nokogiri::XML::Builder.new do |xml|
    xml. {
      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', :uri => '')
        xml.human(:type => 'openDataCommons')
        xml.machine(:type => 'openDataCommons', :uri => '')
      }
      xml.copyright { xml.human }
    }
  end.doc
end

Instance Method Details

#content=(xml) ⇒ Object

just a wrapper to invalidate @dra_object



69
70
71
72
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 69

def content=(xml)
  @dra_object = nil
  super
end

#dra_objectObject



74
75
76
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 74

def dra_object
  @dra_object ||= Dor::RightsAuth.parse(ng_xml, true)
end

#prefixObject

maintain AF < 8 indexing behavior



215
216
217
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 215

def prefix
  ''
end

#set_read_rights(rights) ⇒ Object

Moved from Governable slight misnomer: also sets discover rights! TODO: convert xpath reads to dra_object calls

Parameters:

  • rights (string)

    archetypical rights to assign: ‘world’, ‘stanford’, ‘none’, ‘dark’, etc

Raises:

  • (ArgumentError)


125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 125

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

#to_solr(solr_doc = {}, *args) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 139

def to_solr(solr_doc = {}, *args)
  solr_doc = super(solr_doc, *args)
  dra = 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

  solr_doc['rights_descriptions_ssim'] = [
    dra.index_elements[:primary],

    (dra.index_elements[:obj_locations_qualified] || []).map do |rights_info|
      rule_suffix = rights_info[:rule] ? " (#{rights_info[:rule]})" : ''
      "location: #{rights_info[:location]}#{rule_suffix}"
    end,
    (dra.index_elements[:file_locations_qualified] || []).map do |rights_info|
      rule_suffix = rights_info[:rule] ? " (#{rights_info[:rule]})" : ''
      "location: #{rights_info[:location]} (file)#{rule_suffix}"
    end,

    (dra.index_elements[:obj_agents_qualified] || []).map do |rights_info|
      rule_suffix = rights_info[:rule] ? " (#{rights_info[:rule]})" : ''
      "agent: #{rights_info[:agent]}#{rule_suffix}"
    end,
    (dra.index_elements[:file_agents_qualified] || []).map do |rights_info|
      rule_suffix = rights_info[:rule] ? " (#{rights_info[:rule]})" : ''
      "agent: #{rights_info[:agent]} (file)#{rule_suffix}"
    end,

    (dra.index_elements[:obj_groups_qualified] || []).map do |rights_info|
      rule_suffix = rights_info[:rule] ? " (#{rights_info[:rule]})" : ''
      "#{rights_info[:group]}#{rule_suffix}"
    end,
    (dra.index_elements[:file_groups_qualified] || []).map do |rights_info|
      rule_suffix = rights_info[:rule] ? " (#{rights_info[:rule]})" : ''
      "#{rights_info[:group]} (file)#{rule_suffix}"
    end,

    (dra.index_elements[:obj_world_qualified] || []).map do |rights_info|
      rule_suffix = rights_info[:rule] ? " (#{rights_info[:rule]})" : ''
      "world#{rule_suffix}"
    end,
    (dra.index_elements[:file_world_qualified] || []).map do |rights_info|
      rule_suffix = rights_info[:rule] ? " (#{rights_info[:rule]})" : ''
      "world (file)#{rule_suffix}"
    end
  ].flatten.uniq

  # these two values are returned by index_elements[:primary], but are just a less granular version of
  # what the other more specific fields return, so discard them
  solr_doc['rights_descriptions_ssim'] -= ['access_restricted', 'access_restricted_qualified', 'world_qualified']
  solr_doc['rights_descriptions_ssim'] += ['dark (file)'] if dra.index_elements[:terms].include? 'none_read_file'

  solr_doc['obj_rights_locations_ssim'] = dra.index_elements[:obj_locations] unless dra.index_elements[:obj_locations].blank?
  solr_doc['file_rights_locations_ssim'] = dra.index_elements[:file_locations] unless dra.index_elements[:file_locations].blank?
  solr_doc['obj_rights_agents_ssim'] = dra.index_elements[:obj_agents] unless dra.index_elements[:obj_agents].blank?
  solr_doc['file_rights_agents_ssim'] = dra.index_elements[:file_agents] unless dra.index_elements[:file_agents].blank?

  # suppress empties
  %w(use_statement_ssim copyright_ssim).each do |key|
    solr_doc[key] = solr_doc[key].reject(&:blank?).flatten unless solr_doc[key].nil?
  end
  add_solr_value(solr_doc, 'use_license_machine', use_license.first, :string, [:stored_sortable])
  add_solr_value(solr_doc, 'use_licenses_machine', use_license, :symbol, [:stored_searchable])

  solr_doc
end

#use_licenseObject



206
207
208
209
210
211
212
# File 'lib/dor/datastreams/rights_metadata_ds.rb', line 206

def use_license
  use_license = []
  use_license += Array(creative_commons)
  use_license += Array(open_data_commons)

  use_license.reject(&:blank?)
end