This repository has been archived by the owner on Jan 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrights_metadata_datastream_indexer.rb
88 lines (73 loc) · 3.96 KB
/
rights_metadata_datastream_indexer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# frozen_string_literal: true
class RightsMetadataDatastreamIndexer
attr_reader :resource
def initialize(resource:)
@resource = resource
end
# @return [Hash] the partial solr document for rightsMetadata
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def to_solr
solr_doc = {
'copyright_ssim' => resource.rightsMetadata.copyright,
'use_statement_ssim' => resource.rightsMetadata.use_statement
}
dra = resource.rightsMetadata.dra_object
solr_doc['rights_primary_ssi'] = dra.index_elements[:primary]
solr_doc['rights_errors_ssim'] = dra.index_elements[:errors] unless dra.index_elements[:errors].empty?
solr_doc['rights_characteristics_ssim'] = dra.index_elements[:terms] unless dra.index_elements[:terms].empty?
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'] -= %w[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] if dra.index_elements[:obj_locations].present?
solr_doc['file_rights_locations_ssim'] = dra.index_elements[:file_locations] if dra.index_elements[:file_locations].present?
solr_doc['obj_rights_agents_ssim'] = dra.index_elements[:obj_agents] if dra.index_elements[:obj_agents].present?
solr_doc['file_rights_agents_ssim'] = dra.index_elements[:file_agents] if dra.index_elements[:file_agents].present?
# 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
solr_doc['use_license_machine_ssi'] = resource.rightsMetadata.use_license.first
# TODO: I don't think this is used in argo, and can be removed
solr_doc['use_licenses_machine_ssim'] = resource.rightsMetadata.use_license
solr_doc
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
end