base_indexer 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38640842f66474ab15158e56d03dba575a404438
4
- data.tar.gz: c895c3dc392459facdb39aacbd6dd97f703d036f
3
+ metadata.gz: 52a07e79fae26de30296699bf6e70f9699d4fc15
4
+ data.tar.gz: d0f06d3d351c58547673b56b6fde957c55d08d62
5
5
  SHA512:
6
- metadata.gz: 931badc9658d5e4325c6af2364335dec5cc9dc819b9885253d7f798599ee01c3aee9832dc3124d6ac760df9aecb96c125e381d139a8c694bc3c3cdc07509e845
7
- data.tar.gz: b956d00b7a49f4105808f05c801ad1b91a3a69b46bc26a6733a04e9fc20e9ca28a92128d9611400a82c7a38b0eea0496ddca036bc8522d80993aaa05d8504c81
6
+ metadata.gz: 15ea24fd20bcc51a446d479d87a23b9491b60055ca9099c109775116652a8334ba102a6713018688ac09cd60ac39a0d257ef36886edf063ece050e8d10909004
7
+ data.tar.gz: 268317e54af8bf08a714624d743e783b7b55ce7b53fe7d7f05975cdc50ef9b53b30256fcad2307d7efd0504d3c5c7d537bb0d6c701b23c7ea573eef911277597
@@ -1,41 +1,47 @@
1
1
  module BaseIndexer
2
-
2
+
3
3
  # It caches the collection information such as name and catkey
4
4
  class Collection
5
-
5
+
6
+ def initialize(collection_druid)
7
+ @collection_druid = collection_druid
8
+ end
9
+
6
10
  # Returns the collection name from cache, otherwise will fetch it from PURL.
7
11
  #
8
12
  # @param collection_druid [String] is the druid for a collection e.g., ab123cd4567
9
13
  # @return [Array<String>] the collection data or [] if there is no name and catkey or the object
10
14
  # is not a collection
11
- def self.get_collection_info(collection_druid)
12
-
13
- collection_info = get_from_cache(collection_druid)
14
- if collection_info.nil?
15
- collection_info = get_from_purl(collection_druid)
16
- end
17
- collection_info
15
+ def collection_info
16
+ from_cache || from_purl || {}
18
17
  end
19
-
18
+
19
+ private
20
+
20
21
  # @param [String] collection_druid is the druid for a collection e.g., ab123cd4567
21
22
  # @return [String] return the collection label from cache if available, nil otherwise
22
- def self.get_from_cache(collection_druid)
23
- Rails.cache.read(collection_druid)
23
+ def from_cache
24
+ Rails.cache.read(@collection_druid)
24
25
  end
25
-
26
+
26
27
  # @param [String] collection_druid is the druid for a collection e.g., ab123cd4567
27
28
  # @return [String] return the collection label from purl if available, nil otherwise
28
- def self.get_from_purl(collection_druid)
29
- begin
30
- purl_model =DiscoveryIndexer::InputXml::Purlxml.new(collection_druid).load()
31
- unless purl_model.nil? or (purl_model.label.nil? and purl_model.catkey.nil?) or not(purl_model.is_collection)
32
- Rails.cache.write(collection_druid, { label: purl_model.label, ckey: purl_model.catkey }, expires_in: 1.hours)
33
- { label: purl_model.label, ckey: purl_model.catkey }
34
- end
29
+ def from_purl
30
+ return nil unless purl_model
31
+ return nil unless purl_model.is_collection
32
+ return nil unless purl_model.label && purl_model.catkey
33
+ purl_data = { label: purl_model.label, ckey: purl_model.catkey }
34
+ Rails.cache.write(@collection_druid, purl_data, expires_in: 1.hours)
35
+ purl_data
36
+ end
37
+
38
+ def purl_model
39
+ @purl_model ||= begin
40
+ DiscoveryIndexer::InputXml::Purlxml.new(@collection_druid).load
35
41
  rescue => e
36
- Rails.logger.error "There is a problem in retrieving collection name and/or catkey for #{collection_druid}. #{e.inspect}\n#{e.message }\n#{e.backtrace}"
37
- return {}
42
+ Rails.logger.error "There is a problem in retrieving collection name and/or catkey for #{@collection_druid}. #{e.inspect}\n#{e.message }\n#{e.backtrace}"
43
+ nil
38
44
  end
39
45
  end
40
46
  end
41
- end
47
+ end
@@ -1,10 +1,9 @@
1
1
  require 'discovery-indexer'
2
2
  module BaseIndexer
3
-
4
3
  # It is responsible for performing the basic indexing steps, it includes reading
5
- # the input from PURL server, getting collection names, mapping it to solr doc hash,
6
- # and write it to SOLR core . It can also delete the object from all the registered
7
- #
4
+ # the input from PURL server, getting collection names, mapping it to solr doc hash,
5
+ # and write it to SOLR core . It can also delete the object from all the registered
6
+ #
8
7
  # @example Index with target list
9
8
  # indexer = BaseIndexer::MainIndexerEngine.new
10
9
  # indexer.index "ab123cd456", ["searchworks","revs"]
@@ -18,95 +17,93 @@ module BaseIndexer
18
17
  # indexer.delete "ab123cd456"
19
18
  class MainIndexerEngine
20
19
  include DiscoveryIndexer
21
-
20
+
22
21
  # It is the main indexing function
23
- #
22
+ #
24
23
  # @param druid [String] is the druid for an object e.g., ab123cd4567
25
- # @param targets [Array] is an array with the targets list to index towards,
24
+ # @param targets [Array] is an array with the targets list to index towards,
26
25
  # if it is nil, the method will read the target list from release_tags
27
26
  #
28
27
  # @raise it will raise erros if there is any problems happen in any level
29
- def index druid, targets=nil
28
+ def index(druid, targets = nil)
30
29
  # Read input mods and purl
31
30
  purl_model = read_purl(druid)
32
31
  mods_model = read_mods(druid)
33
- collection_data = get_collection_data(purl_model.collection_druids)
34
-
32
+ collection_data = collection_data(purl_model.collection_druids)
33
+
35
34
  # Map the input to solr_doc
36
- solr_doc = BaseIndexer.mapper_class_name.constantize.new(druid, mods_model, purl_model, collection_data).convert_to_solr_doc
37
-
35
+ solr_doc = BaseIndexer.mapper_class_name.constantize.new(druid, mods_model, purl_model, collection_data).convert_to_solr_doc
36
+
38
37
  # Get target list
39
- targets_hash={}
40
- if targets.nil? or targets.length == 0
41
- targets_hash = purl_model.release_tags_hash
38
+ targets_hash = {}
39
+ if targets.present?
40
+ targets_hash = targets_hash_from_param(targets)
42
41
  else
43
- targets_hash = get_targets_hash_from_param(targets)
42
+ targets_hash = purl_model.release_tags_hash
44
43
  end
45
-
44
+
46
45
  targets_hash = update_targets_before_write(targets_hash, purl_model)
47
-
46
+
48
47
  # Get SOLR configuration and write
49
48
  solr_targets_configs = BaseIndexer.solr_configuration_class_name.constantize.instance.get_configuration_hash
50
- BaseIndexer.solr_writer_class_name.constantize.new.process( druid, solr_doc, targets_hash, solr_targets_configs)
49
+ BaseIndexer.solr_writer_class_name.constantize.new.process(druid, solr_doc, targets_hash, solr_targets_configs)
51
50
  end
52
-
51
+
53
52
  # It deletes an item defined by druid from all registered solr core
54
53
  # @param druid [String] is the druid for an object e.g., ab123cd4567
55
- def delete druid
54
+ def delete(druid)
56
55
  solr_targets_configs = BaseIndexer.solr_configuration_class_name.constantize.instance.get_configuration_hash
57
- BaseIndexer.solr_writer_class_name.constantize.new.solr_delete_from_all( druid, solr_targets_configs)
56
+ BaseIndexer.solr_writer_class_name.constantize.new.solr_delete_from_all(druid, solr_targets_configs)
58
57
  end
59
-
60
- def read_purl druid
61
- return DiscoveryIndexer::InputXml::Purlxml.new(druid).load()
58
+
59
+ def read_purl(druid)
60
+ DiscoveryIndexer::InputXml::Purlxml.new(druid).load
62
61
  end
63
-
64
- def read_mods druid
65
- return DiscoveryIndexer::InputXml::Modsxml.new(druid).load()
62
+
63
+ def read_mods(druid)
64
+ DiscoveryIndexer::InputXml::Modsxml.new(druid).load
66
65
  end
67
-
66
+
68
67
  # It converts targets array to targets hash
69
68
  # @param targets [Array] a list of specfic targets
70
69
  # @return [Hash] a hash of targets with true value
71
70
  # @example convert target list
72
- # get_targets_hash_from_param( ["searchworks","revs"] )
71
+ # targets_hash_from_param( ["searchworks","revs"] )
73
72
  # {"searchworks"=>true, "revs"=>true}
74
- def get_targets_hash_from_param(targets)
73
+ def targets_hash_from_param(targets)
75
74
  targets_hash = {}
76
- unless targets.nil? then
75
+ unless targets.nil?
77
76
  targets.each do |target|
78
77
  targets_hash[target] = true
79
78
  end
80
79
  end
81
- return targets_hash
80
+ targets_hash
82
81
  end
83
-
82
+
84
83
  # It allows the consumer to modify the targets list before doing the final writing
85
84
  # to the solr core. Default behavior returns the targets_hash as it is
86
85
  # @param targets_hash [Hash] a hash of targets with true value
87
86
  # @param purl_model [DiscoveryIndexer::Reader::PurlxmlModel] represents the purlxml model
88
- # @return [Hash] a hash of targets
89
- def update_targets_before_write(targets_hash, purl_model)
90
- return targets_hash
87
+ # @return [Hash] a hash of targets
88
+ def update_targets_before_write(targets_hash, _purl_model)
89
+ targets_hash
91
90
  end
92
-
91
+
93
92
  # It converts collection_druids list to a hash with names. If the druid doesn't
94
93
  # have a collection name, it will be excluded from the hash
95
- # @param collection_druids [Array] a list of druids
94
+ # @param collection_druids [Array] a list of druids
96
95
  # !["ab123cd4567", "ef123gh4567"]
97
- # @return [Hash] a hash for collection druid and its name
96
+ # @return [Hash] a hash for collection druid and its name
98
97
  # !{"ab123cd4567"=>"Collection 1", "ef123gh4567"=>"Collection 2"}
99
- def get_collection_data collection_druids
98
+ def collection_data(collection_druids)
100
99
  collection_data = {}
101
-
102
- unless collection_druids.nil? then
100
+ unless collection_druids.nil?
103
101
  collection_druids.each do |cdruid|
104
- cdata = BaseIndexer::Collection.get_collection_info(cdruid)
105
- collection_data[cdruid] = cdata unless cdata.nil?
102
+ cdata = BaseIndexer::Collection.new(cdruid).collection_info
103
+ collection_data[cdruid] = cdata if cdata.present?
106
104
  end
107
105
  end
108
106
  collection_data
109
107
  end
110
-
111
108
  end
112
109
  end
@@ -1,3 +1,3 @@
1
1
  module BaseIndexer
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
metadata CHANGED
@@ -1,225 +1,226 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base_indexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmed Alsum
8
+ - Laney McGlohon
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-08-14 00:00:00.000000000 Z
12
+ date: 2015-10-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ~>
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
20
  version: '4.1'
20
- - - '>='
21
+ - - ">="
21
22
  - !ruby/object:Gem::Version
22
23
  version: 4.1.9
23
24
  type: :runtime
24
25
  prerelease: false
25
26
  version_requirements: !ruby/object:Gem::Requirement
26
27
  requirements:
27
- - - ~>
28
+ - - "~>"
28
29
  - !ruby/object:Gem::Version
29
30
  version: '4.1'
30
- - - '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: 4.1.9
33
34
  - !ruby/object:Gem::Dependency
34
35
  name: discovery-indexer
35
36
  requirement: !ruby/object:Gem::Requirement
36
37
  requirements:
37
- - - '>='
38
+ - - ">="
38
39
  - !ruby/object:Gem::Version
39
- version: 0.9.5
40
+ version: 0.9.9
40
41
  type: :runtime
41
42
  prerelease: false
42
43
  version_requirements: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - '>='
45
+ - - ">="
45
46
  - !ruby/object:Gem::Version
46
- version: 0.9.5
47
+ version: 0.9.9
47
48
  - !ruby/object:Gem::Dependency
48
49
  name: retries
49
50
  requirement: !ruby/object:Gem::Requirement
50
51
  requirements:
51
- - - '>='
52
+ - - ">="
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
54
55
  type: :runtime
55
56
  prerelease: false
56
57
  version_requirements: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - '>='
59
+ - - ">="
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
62
  - !ruby/object:Gem::Dependency
62
63
  name: is_it_working-cbeer
63
64
  requirement: !ruby/object:Gem::Requirement
64
65
  requirements:
65
- - - '>='
66
+ - - ">="
66
67
  - !ruby/object:Gem::Version
67
68
  version: '0'
68
69
  type: :runtime
69
70
  prerelease: false
70
71
  version_requirements: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - '>='
73
+ - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
76
  - !ruby/object:Gem::Dependency
76
77
  name: sqlite3
77
78
  requirement: !ruby/object:Gem::Requirement
78
79
  requirements:
79
- - - '>='
80
+ - - ">="
80
81
  - !ruby/object:Gem::Version
81
82
  version: '0'
82
83
  type: :development
83
84
  prerelease: false
84
85
  version_requirements: !ruby/object:Gem::Requirement
85
86
  requirements:
86
- - - '>='
87
+ - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  - !ruby/object:Gem::Dependency
90
91
  name: rspec
91
92
  requirement: !ruby/object:Gem::Requirement
92
93
  requirements:
93
- - - ~>
94
+ - - "~>"
94
95
  - !ruby/object:Gem::Version
95
96
  version: 3.1.0
96
97
  type: :development
97
98
  prerelease: false
98
99
  version_requirements: !ruby/object:Gem::Requirement
99
100
  requirements:
100
- - - ~>
101
+ - - "~>"
101
102
  - !ruby/object:Gem::Version
102
103
  version: 3.1.0
103
104
  - !ruby/object:Gem::Dependency
104
105
  name: rspec-rails
105
106
  requirement: !ruby/object:Gem::Requirement
106
107
  requirements:
107
- - - ~>
108
+ - - "~>"
108
109
  - !ruby/object:Gem::Version
109
110
  version: 3.1.0
110
111
  type: :development
111
112
  prerelease: false
112
113
  version_requirements: !ruby/object:Gem::Requirement
113
114
  requirements:
114
- - - ~>
115
+ - - "~>"
115
116
  - !ruby/object:Gem::Version
116
117
  version: 3.1.0
117
118
  - !ruby/object:Gem::Dependency
118
119
  name: capybara
119
120
  requirement: !ruby/object:Gem::Requirement
120
121
  requirements:
121
- - - '>='
122
+ - - ">="
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  type: :development
125
126
  prerelease: false
126
127
  version_requirements: !ruby/object:Gem::Requirement
127
128
  requirements:
128
- - - '>='
129
+ - - ">="
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  - !ruby/object:Gem::Dependency
132
133
  name: vcr
133
134
  requirement: !ruby/object:Gem::Requirement
134
135
  requirements:
135
- - - '>='
136
+ - - ">="
136
137
  - !ruby/object:Gem::Version
137
138
  version: '0'
138
139
  type: :development
139
140
  prerelease: false
140
141
  version_requirements: !ruby/object:Gem::Requirement
141
142
  requirements:
142
- - - '>='
143
+ - - ">="
143
144
  - !ruby/object:Gem::Version
144
145
  version: '0'
145
146
  - !ruby/object:Gem::Dependency
146
147
  name: webmock
147
148
  requirement: !ruby/object:Gem::Requirement
148
149
  requirements:
149
- - - '>='
150
+ - - ">="
150
151
  - !ruby/object:Gem::Version
151
152
  version: '0'
152
153
  type: :development
153
154
  prerelease: false
154
155
  version_requirements: !ruby/object:Gem::Requirement
155
156
  requirements:
156
- - - '>='
157
+ - - ">="
157
158
  - !ruby/object:Gem::Version
158
159
  version: '0'
159
160
  - !ruby/object:Gem::Dependency
160
161
  name: coveralls
161
162
  requirement: !ruby/object:Gem::Requirement
162
163
  requirements:
163
- - - '>='
164
+ - - ">="
164
165
  - !ruby/object:Gem::Version
165
166
  version: '0'
166
167
  type: :development
167
168
  prerelease: false
168
169
  version_requirements: !ruby/object:Gem::Requirement
169
170
  requirements:
170
- - - '>='
171
+ - - ">="
171
172
  - !ruby/object:Gem::Version
172
173
  version: '0'
173
174
  - !ruby/object:Gem::Dependency
174
175
  name: yard
175
176
  requirement: !ruby/object:Gem::Requirement
176
177
  requirements:
177
- - - '>='
178
+ - - ">="
178
179
  - !ruby/object:Gem::Version
179
180
  version: '0'
180
181
  type: :development
181
182
  prerelease: false
182
183
  version_requirements: !ruby/object:Gem::Requirement
183
184
  requirements:
184
- - - '>='
185
+ - - ">="
185
186
  - !ruby/object:Gem::Version
186
187
  version: '0'
187
188
  - !ruby/object:Gem::Dependency
188
189
  name: engine_cart
189
190
  requirement: !ruby/object:Gem::Requirement
190
191
  requirements:
191
- - - '>='
192
+ - - ">="
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  type: :development
195
196
  prerelease: false
196
197
  version_requirements: !ruby/object:Gem::Requirement
197
198
  requirements:
198
- - - '>='
199
+ - - ">="
199
200
  - !ruby/object:Gem::Version
200
201
  version: '0'
201
202
  - !ruby/object:Gem::Dependency
202
203
  name: jettywrapper
203
204
  requirement: !ruby/object:Gem::Requirement
204
205
  requirements:
205
- - - '>='
206
+ - - ">="
206
207
  - !ruby/object:Gem::Version
207
208
  version: '0'
208
209
  type: :development
209
210
  prerelease: false
210
211
  version_requirements: !ruby/object:Gem::Requirement
211
212
  requirements:
212
- - - '>='
213
+ - - ">="
213
214
  - !ruby/object:Gem::Version
214
215
  version: '0'
215
216
  description: Description of BaseIndexer.
216
217
  email:
217
218
  - aalsum@stanford.edu
219
+ - laneymcg@stanford.edu
218
220
  executables: []
219
221
  extensions: []
220
222
  extra_rdoc_files: []
221
223
  files:
222
- - MIT-LICENSE
223
224
  - README.rdoc
224
225
  - Rakefile
225
226
  - app/controllers/base_indexer/about_controller.rb
@@ -238,7 +239,6 @@ files:
238
239
  - lib/base_indexer/collection.rb
239
240
  - lib/base_indexer/engine.rb
240
241
  - lib/base_indexer/main_indexer_engine.rb
241
- - lib/base_indexer/message.rb
242
242
  - lib/base_indexer/solr/solr_configuration.rb
243
243
  - lib/base_indexer/solr/solr_configuration_from_file.rb
244
244
  - lib/base_indexer/version.rb
@@ -256,17 +256,17 @@ require_paths:
256
256
  - lib
257
257
  required_ruby_version: !ruby/object:Gem::Requirement
258
258
  requirements:
259
- - - '>='
259
+ - - ">="
260
260
  - !ruby/object:Gem::Version
261
261
  version: '0'
262
262
  required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  requirements:
264
- - - '>='
264
+ - - ">="
265
265
  - !ruby/object:Gem::Version
266
266
  version: '0'
267
267
  requirements: []
268
268
  rubyforge_project:
269
- rubygems_version: 2.2.2
269
+ rubygems_version: 2.4.5
270
270
  signing_key:
271
271
  specification_version: 4
272
272
  summary: Summary of BaseIndexer.
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2015 YOURNAME
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +0,0 @@
1
- module BaseIndexer
2
- class Message
3
- attr_accessor :status
4
- attr_accessor :text_message
5
- end
6
- end