dor_indexing 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +355 -0
  4. data/Gemfile +16 -0
  5. data/Gemfile.lock +218 -0
  6. data/README.md +33 -0
  7. data/Rakefile +11 -0
  8. data/dor_indexing.gemspec +40 -0
  9. data/lib/dor_indexing/builders/all_search_text_builder.rb +58 -0
  10. data/lib/dor_indexing/builders/author_builder.rb +31 -0
  11. data/lib/dor_indexing/builders/collection_rights_description_builder.rb +29 -0
  12. data/lib/dor_indexing/builders/document_builder.rb +106 -0
  13. data/lib/dor_indexing/builders/event_date_builder.rb +71 -0
  14. data/lib/dor_indexing/builders/event_place_builder.rb +73 -0
  15. data/lib/dor_indexing/builders/geographic_builder.rb +82 -0
  16. data/lib/dor_indexing/builders/name_builder.rb +70 -0
  17. data/lib/dor_indexing/builders/orcid_builder.rb +62 -0
  18. data/lib/dor_indexing/builders/publisher_name_builder.rb +53 -0
  19. data/lib/dor_indexing/builders/temporal_builder.rb +56 -0
  20. data/lib/dor_indexing/builders/topic_builder.rb +96 -0
  21. data/lib/dor_indexing/cocina_repository.rb +24 -0
  22. data/lib/dor_indexing/indexers/administrative_tag_indexer.rb +69 -0
  23. data/lib/dor_indexing/indexers/collection_title_indexer.rb +27 -0
  24. data/lib/dor_indexing/indexers/composite_indexer.rb +36 -0
  25. data/lib/dor_indexing/indexers/content_metadata_indexer.rb +69 -0
  26. data/lib/dor_indexing/indexers/data_indexer.rb +66 -0
  27. data/lib/dor_indexing/indexers/default_object_rights_indexer.rb +36 -0
  28. data/lib/dor_indexing/indexers/descriptive_metadata_indexer.rb +226 -0
  29. data/lib/dor_indexing/indexers/embargo_metadata_indexer.rb +32 -0
  30. data/lib/dor_indexing/indexers/identifiable_indexer.rb +92 -0
  31. data/lib/dor_indexing/indexers/identity_metadata_indexer.rb +85 -0
  32. data/lib/dor_indexing/indexers/process_indexer.rb +63 -0
  33. data/lib/dor_indexing/indexers/releasable_indexer.rb +62 -0
  34. data/lib/dor_indexing/indexers/rights_metadata_indexer.rb +59 -0
  35. data/lib/dor_indexing/indexers/role_metadata_indexer.rb +31 -0
  36. data/lib/dor_indexing/indexers/workflow_indexer.rb +51 -0
  37. data/lib/dor_indexing/indexers/workflows_indexer.rb +40 -0
  38. data/lib/dor_indexing/marc_country.rb +359 -0
  39. data/lib/dor_indexing/selectors/event_selector.rb +112 -0
  40. data/lib/dor_indexing/selectors/pub_year_selector.rb +119 -0
  41. data/lib/dor_indexing/version.rb +5 -0
  42. data/lib/dor_indexing/workflow_fields.rb +63 -0
  43. data/lib/dor_indexing/workflow_solr_document.rb +93 -0
  44. data/lib/dor_indexing.rb +19 -0
  45. metadata +173 -0
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DorIndexing
4
+ # Represents that part of the solr document that holds workflow data
5
+ class WorkflowSolrDocument
6
+ WORKFLOW_SOLR = 'wf_ssim'
7
+ # field that indexes workflow name, process status then process name
8
+ WORKFLOW_WPS_SOLR = 'wf_wps_ssim'
9
+ # field that indexes workflow name, process name then process status
10
+ WORKFLOW_WSP_SOLR = 'wf_wsp_ssim'
11
+ # field that indexes process status, workflowname then process name
12
+ WORKFLOW_SWP_SOLR = 'wf_swp_ssim'
13
+ WORKFLOW_ERROR_SOLR = 'wf_error_ssim'
14
+ WORKFLOW_STATUS_SOLR = 'workflow_status_ssim'
15
+
16
+ KEYS_TO_MERGE = [
17
+ WORKFLOW_SOLR,
18
+ WORKFLOW_WPS_SOLR,
19
+ WORKFLOW_WSP_SOLR,
20
+ WORKFLOW_SWP_SOLR,
21
+ WORKFLOW_STATUS_SOLR,
22
+ WORKFLOW_ERROR_SOLR
23
+ ].freeze
24
+
25
+ def initialize
26
+ @data = empty_document
27
+ yield self if block_given?
28
+ end
29
+
30
+ def name=(wf_name)
31
+ data[WORKFLOW_SOLR] += [wf_name]
32
+ data[WORKFLOW_WPS_SOLR] += [wf_name]
33
+ data[WORKFLOW_WSP_SOLR] += [wf_name]
34
+ end
35
+
36
+ def status=(status)
37
+ data[WORKFLOW_STATUS_SOLR] += [status]
38
+ end
39
+
40
+ def error=(message)
41
+ data[WORKFLOW_ERROR_SOLR] += [message]
42
+ end
43
+
44
+ # Add to the field that indexes workflow name, process status then process name
45
+ def add_wps(*messages)
46
+ data[WORKFLOW_WPS_SOLR] += messages
47
+ end
48
+
49
+ # Add to the field that indexes workflow name, process name then process status
50
+ def add_wsp(*messages)
51
+ data[WORKFLOW_WSP_SOLR] += messages
52
+ end
53
+
54
+ # Add to the field that indexes process status, workflow name then process name
55
+ def add_swp(*messages)
56
+ data[WORKFLOW_SWP_SOLR] += messages
57
+ end
58
+
59
+ # Add the processes data_time attribute to the solr document
60
+ # @param [String] wf_name
61
+ # @param [String] process_name
62
+ # @param [Time] time
63
+ def add_process_time(wf_name, process_name, time)
64
+ data["wf_#{wf_name}_#{process_name}_dttsi"] = time.utc.iso8601
65
+ end
66
+
67
+ def to_h
68
+ KEYS_TO_MERGE.each { |k| data[k].uniq! }
69
+ data
70
+ end
71
+
72
+ delegate :except, :[], to: :data
73
+
74
+ # @param [WorkflowSolrDocument] doc
75
+ def merge!(doc)
76
+ # This is going to get the date fields, e.g. `wf_assemblyWF_jp2-create_dttsi'
77
+ @data.merge!(doc.except(*KEYS_TO_MERGE))
78
+
79
+ # Combine the non-unique fields together
80
+ KEYS_TO_MERGE.each do |k|
81
+ data[k] += doc[k]
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ attr_reader :data
88
+
89
+ def empty_document
90
+ KEYS_TO_MERGE.index_with { |_k| [] }
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zeitwerk'
4
+ require 'stanford-mods'
5
+ require 'cocina/models'
6
+ require 'solrizer'
7
+ require 'marc/vocab'
8
+ require 'honeybadger'
9
+
10
+ Zeitwerk::Loader.for_gem.setup
11
+
12
+ # Builds solr documents for indexing.
13
+ class DorIndexing
14
+ # @return [Hash] the solr document
15
+ def self.build(cocina_with_metadata:, workflow_client:, cocina_repository:)
16
+ Honeybadger.context({ identifier: cocina_with_metadata.externalIdentifier })
17
+ DorIndexing::Builders::DocumentBuilder.for(model: cocina_with_metadata, workflow_client:, cocina_repository:).to_solr
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dor_indexing
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Littman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cocina-models
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.93.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.93.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: honeybadger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: marc-vocab
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: solrizer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: stanford-mods
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: zeitwerk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Library for creating Solr documents for SDR indexing.
98
+ email:
99
+ - justinlittman@stanford.edu
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".rspec"
105
+ - ".rubocop.yml"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - README.md
109
+ - Rakefile
110
+ - dor_indexing.gemspec
111
+ - lib/dor_indexing.rb
112
+ - lib/dor_indexing/builders/all_search_text_builder.rb
113
+ - lib/dor_indexing/builders/author_builder.rb
114
+ - lib/dor_indexing/builders/collection_rights_description_builder.rb
115
+ - lib/dor_indexing/builders/document_builder.rb
116
+ - lib/dor_indexing/builders/event_date_builder.rb
117
+ - lib/dor_indexing/builders/event_place_builder.rb
118
+ - lib/dor_indexing/builders/geographic_builder.rb
119
+ - lib/dor_indexing/builders/name_builder.rb
120
+ - lib/dor_indexing/builders/orcid_builder.rb
121
+ - lib/dor_indexing/builders/publisher_name_builder.rb
122
+ - lib/dor_indexing/builders/temporal_builder.rb
123
+ - lib/dor_indexing/builders/topic_builder.rb
124
+ - lib/dor_indexing/cocina_repository.rb
125
+ - lib/dor_indexing/indexers/administrative_tag_indexer.rb
126
+ - lib/dor_indexing/indexers/collection_title_indexer.rb
127
+ - lib/dor_indexing/indexers/composite_indexer.rb
128
+ - lib/dor_indexing/indexers/content_metadata_indexer.rb
129
+ - lib/dor_indexing/indexers/data_indexer.rb
130
+ - lib/dor_indexing/indexers/default_object_rights_indexer.rb
131
+ - lib/dor_indexing/indexers/descriptive_metadata_indexer.rb
132
+ - lib/dor_indexing/indexers/embargo_metadata_indexer.rb
133
+ - lib/dor_indexing/indexers/identifiable_indexer.rb
134
+ - lib/dor_indexing/indexers/identity_metadata_indexer.rb
135
+ - lib/dor_indexing/indexers/process_indexer.rb
136
+ - lib/dor_indexing/indexers/releasable_indexer.rb
137
+ - lib/dor_indexing/indexers/rights_metadata_indexer.rb
138
+ - lib/dor_indexing/indexers/role_metadata_indexer.rb
139
+ - lib/dor_indexing/indexers/workflow_indexer.rb
140
+ - lib/dor_indexing/indexers/workflows_indexer.rb
141
+ - lib/dor_indexing/marc_country.rb
142
+ - lib/dor_indexing/selectors/event_selector.rb
143
+ - lib/dor_indexing/selectors/pub_year_selector.rb
144
+ - lib/dor_indexing/version.rb
145
+ - lib/dor_indexing/workflow_fields.rb
146
+ - lib/dor_indexing/workflow_solr_document.rb
147
+ homepage: https://github.com/sul-dlss/dor_indexing
148
+ licenses: []
149
+ metadata:
150
+ homepage_uri: https://github.com/sul-dlss/dor_indexing
151
+ source_code_uri: https://github.com/sul-dlss/dor_indexing
152
+ changelog_uri: https://github.com/sul-dlss/folio_client/releases
153
+ rubygems_mfa_required: 'true'
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 3.2.0
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubygems_version: 3.4.14
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Library for creating Solr documents for SDR indexing.
173
+ test_files: []