umlaut-primo 0.1.2 → 0.1.3
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.
- data/lib/umlaut_primo/primo_service.rb +105 -94
- data/lib/umlaut_primo/version.rb +2 -2
- data/test/dummy/log/test.log +2241 -0
- data/test/fixtures/referent_values.yml +23 -0
- data/test/fixtures/referents.yml +4 -0
- data/test/fixtures/requests.yml +4 -0
- data/test/unit/primo_service_test.rb +17 -1
- data/test/vcr_cassettes/demystifying_the_chinese_economy.yml +50 -0
- data/test/vcr_cassettes/digital_futures_living_in_a_dot_com_world.yml +236 -0
- metadata +33 -19
- checksums.yaml +0 -15
@@ -40,13 +40,13 @@
|
|
40
40
|
# - table_of_contents
|
41
41
|
# - referent_enhance
|
42
42
|
# - highlighted_link
|
43
|
-
#
|
43
|
+
#
|
44
44
|
# base_url:: _required_ host and port of Primo server; used for Primo web services, deep links and holding_search
|
45
45
|
# base_path:: *DEPRECATED* previous name of base_url
|
46
46
|
# vid:: _required_ view id for Primo deep links and holding_search.
|
47
47
|
# institution:: _required_ institution id for Primo institution; used for Primo web services
|
48
48
|
# base_view_id:: *DEPRECATED* previous name of vid
|
49
|
-
# holding_search_institution:: if service types include holding_search_ and the holding search institution is different from
|
49
|
+
# holding_search_institution:: if service types include holding_search_ and the holding search institution is different from
|
50
50
|
# institution to be used for the holding_search
|
51
51
|
# holding_search_text:: _optional_ text to display for the holding_search
|
52
52
|
# default holding search text:: "Search for this title."
|
@@ -102,7 +102,7 @@
|
|
102
102
|
# class_name: Source2Implementation (in exlibris/primo/sources or exlibris/primo/sources/local)
|
103
103
|
# source2_config_option1: source2_config_option1
|
104
104
|
# source2_config_option2: source2_config_option2
|
105
|
-
#
|
105
|
+
#
|
106
106
|
require 'exlibris-primo'
|
107
107
|
class PrimoService < Service
|
108
108
|
|
@@ -166,99 +166,79 @@ class PrimoService < Service
|
|
166
166
|
|
167
167
|
# Overwrites Service#handle.
|
168
168
|
def handle(request)
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
@genre = genre(request)
|
177
|
-
# Setup the Primo search object
|
178
|
-
search = Exlibris::Primo::Search.new.base_url!(@base_url).institution!(@institution)
|
179
|
-
# Search if we have a:
|
180
|
-
# Primo record id OR
|
181
|
-
# ISBN OR
|
182
|
-
# ISSN OR
|
183
|
-
# Title and author and genre
|
184
|
-
if((not @record_id.blank?))
|
185
|
-
search.record_id! @record_id
|
186
|
-
elsif((not @isbn.blank?))
|
187
|
-
search.isbn_is @isbn
|
188
|
-
elsif((not @issn.blank?))
|
189
|
-
search.isbn_is @issn
|
190
|
-
elsif((not @title.blank?) and (not @author.blank?) and (not @genre.blank?))
|
191
|
-
search.title_is(@title).creator_is(@author).any_is(@genre)
|
192
|
-
else # Don't do a search.
|
193
|
-
return request.dispatched(self, true)
|
194
|
-
end
|
195
|
-
|
196
|
-
begin
|
169
|
+
search = search(request)
|
170
|
+
return request.dispatched(self, true) if search.nil?
|
171
|
+
records = search.records
|
172
|
+
if records.blank? && /^dedupmrg/ === @record_id
|
173
|
+
@record_id = nil
|
174
|
+
search = search(request, true)
|
175
|
+
return request.dispatched(self, true) if search.nil?
|
197
176
|
records = search.records
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
end
|
236
|
-
# Add fulltext services
|
237
|
-
if @service_types.include?("fulltext")
|
238
|
-
# Get fulltexts from the returned Primo records
|
239
|
-
fulltexts = records.collect{|record| record.fulltexts}.flatten
|
240
|
-
# Add the fulltext services
|
241
|
-
add_fulltext_services(request, fulltexts) unless fulltexts.empty?
|
242
|
-
end
|
243
|
-
# Add table of contents services
|
244
|
-
if @service_types.include?("table_of_contents")
|
245
|
-
# Get tables of contents from the returned Primo records
|
246
|
-
tables_of_contents = records.collect{|record| record.tables_of_contents}.flatten
|
247
|
-
# Add the table of contents services
|
248
|
-
add_table_of_contents_services(request, tables_of_contents) unless tables_of_contents.empty?
|
249
|
-
end
|
250
|
-
if @service_types.include?("highlighted_link")
|
251
|
-
# Get related links from the returned Primo records
|
252
|
-
highlighted_links = records.collect{|record| record.related_links}.flatten
|
253
|
-
add_highlighted_link_services(request, highlighted_links) unless highlighted_links.empty?
|
177
|
+
end
|
178
|
+
# Enhance the referent with metadata from Primo Searcher if Primo record id, ISSN
|
179
|
+
# or ISBN is present i.e. if we did our search with a Primo ID number
|
180
|
+
if (@record_id.present? || @issn.present? || @isbn.present?) && @service_types.include?("referent_enhance")
|
181
|
+
# We'll take the first record, since there should only be one.
|
182
|
+
enhance_referent(request, records.first)
|
183
|
+
end
|
184
|
+
# Get cover image only if @record_id is defined
|
185
|
+
# TODO: make cover image service smarter and only
|
186
|
+
# include things that are actually URLs.
|
187
|
+
# if @record_id and @service_types.include?("cover_image")
|
188
|
+
# cover_image = primo_searcher.cover_image
|
189
|
+
# unless cover_image.nil?
|
190
|
+
# request.add_service_response(
|
191
|
+
# :service => self,
|
192
|
+
# :display_text => 'Cover Image',
|
193
|
+
# :key => 'medium',
|
194
|
+
# :url => cover_image,
|
195
|
+
# :size => 'medium',
|
196
|
+
# :service_type_value => :cover_image)
|
197
|
+
# end
|
198
|
+
# end
|
199
|
+
# Add holding services
|
200
|
+
if @service_types.include?("holding") || @service_types.include?("primo_source")
|
201
|
+
# Get holdings from the returned Primo records
|
202
|
+
holdings = records.collect{|record| record.holdings}.flatten
|
203
|
+
# Add the holding services
|
204
|
+
add_holding_services(request, holdings) unless holdings.empty?
|
205
|
+
# Provide title search functionality in the absence of available holdings.
|
206
|
+
# The logic below says only present the holdings search in the following case:
|
207
|
+
# We've configured to present holding search
|
208
|
+
# We didn't find any actual holdings
|
209
|
+
# We didn't come from Primo (prevent round trips since that would be weird)
|
210
|
+
# We have a title to search for.
|
211
|
+
if @service_types.include?("holding_search") and holdings.empty? and (not primo_identifier?) and (not @title.nil?)
|
212
|
+
# Add the holding search service
|
213
|
+
add_holding_search_service(request)
|
254
214
|
end
|
255
|
-
rescue Exception => e
|
256
|
-
# Log error and return finished
|
257
|
-
Rails.logger.error(
|
258
|
-
"Error in Exlibris::Primo::Search. "+
|
259
|
-
"Returning 0 Primo services for search #{search.inspect}. "+
|
260
|
-
"Exlibris::Primo::Search raised the following exception:\n#{e}\n#{e.backtrace.inspect}")
|
261
215
|
end
|
216
|
+
# Add fulltext services
|
217
|
+
if @service_types.include?("fulltext")
|
218
|
+
# Get fulltexts from the returned Primo records
|
219
|
+
fulltexts = records.collect{|record| record.fulltexts}.flatten
|
220
|
+
# Add the fulltext services
|
221
|
+
add_fulltext_services(request, fulltexts) unless fulltexts.empty?
|
222
|
+
end
|
223
|
+
# Add table of contents services
|
224
|
+
if @service_types.include?("table_of_contents")
|
225
|
+
# Get tables of contents from the returned Primo records
|
226
|
+
tables_of_contents = records.collect{|record| record.tables_of_contents}.flatten
|
227
|
+
# Add the table of contents services
|
228
|
+
add_table_of_contents_services(request, tables_of_contents) unless tables_of_contents.empty?
|
229
|
+
end
|
230
|
+
if @service_types.include?("highlighted_link")
|
231
|
+
# Get related links from the returned Primo records
|
232
|
+
highlighted_links = records.collect{|record| record.related_links}.flatten
|
233
|
+
add_highlighted_link_services(request, highlighted_links) unless highlighted_links.empty?
|
234
|
+
end
|
235
|
+
rescue Exception => e
|
236
|
+
# Log error and return finished
|
237
|
+
Rails.logger.error(
|
238
|
+
"Error in Exlibris::Primo::Search. "+
|
239
|
+
"Returning 0 Primo services for request #{request.inspect}. "+
|
240
|
+
"Exlibris::Primo::Search raised the following exception:\n#{e}\n#{e.backtrace.inspect}")
|
241
|
+
ensure
|
262
242
|
return request.dispatched(self, true)
|
263
243
|
end
|
264
244
|
|
@@ -287,6 +267,37 @@ class PrimoService < Service
|
|
287
267
|
end
|
288
268
|
protected :deep_link_search_url
|
289
269
|
|
270
|
+
def search(request, skip_id = false)
|
271
|
+
# Get the possible search params
|
272
|
+
@identifier = request.referrer_id
|
273
|
+
@record_id = record_id(request) unless skip_id
|
274
|
+
@isbn = isbn(request)
|
275
|
+
@issn = issn(request)
|
276
|
+
@title = title(request)
|
277
|
+
@author = author(request)
|
278
|
+
@genre = genre(request)
|
279
|
+
# Setup the Primo search object
|
280
|
+
search = Exlibris::Primo::Search.new.base_url!(@base_url).institution!(@institution)
|
281
|
+
# Search if we have a:
|
282
|
+
# Primo record id OR
|
283
|
+
# ISBN OR
|
284
|
+
# ISSN OR
|
285
|
+
# Title and author and genre
|
286
|
+
if(@record_id.present?)
|
287
|
+
search.record_id! @record_id
|
288
|
+
elsif(@isbn.present?)
|
289
|
+
search.isbn_is @isbn
|
290
|
+
elsif(@issn.present?)
|
291
|
+
search.isbn_is @issn
|
292
|
+
elsif(@title.present? && @author.present? && @genre.present?)
|
293
|
+
search.title_is(@title).creator_is(@author).any_is(@genre)
|
294
|
+
else
|
295
|
+
return nil
|
296
|
+
end
|
297
|
+
search
|
298
|
+
end
|
299
|
+
private :search
|
300
|
+
|
290
301
|
# Configure Primo if this is the first time through
|
291
302
|
def configure_primo
|
292
303
|
Exlibris::Primo.configure { |primo_config|
|
@@ -507,4 +518,4 @@ class PrimoService < Service
|
|
507
518
|
return @identifier.start_with?('info:sid/primo.exlibrisgroup.com')
|
508
519
|
end
|
509
520
|
private :primo_identifier?
|
510
|
-
end
|
521
|
+
end
|
data/lib/umlaut_primo/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module UmlautPrimo
|
2
|
-
VERSION = "0.1.
|
3
|
-
end
|
2
|
+
VERSION = "0.1.3"
|
3
|
+
end
|