Class: PrimoSource

Inherits:
PrimoService show all
Defined in:
lib/service_adaptors/primo_source.rb

Overview

Overview

PrimoSource is a PrimoService that converts primo_source service types into Primo source holdings. This mechanism allows linking to original data sources and expanded holdings information based on those sources and can be implemented per source. To create a Primo source holding, you first must create a local class representing the source in module Exlibris::Primo::Source which extends Exlibris::Primo::Holding. Two methods are then available for overriding:

:expand -   expand holdings that may have been collapsed into a single availlibrary element 
            in Primo based on information from the source
            default: [self]
:dedup? -   if this data source contain duplicate holdings that need to be deduped, set to true
            default: false

The following properties can also be overridden in the initialize method

:record_id, :source_id, :original_source_id, :source_record_id,
:availlibrary, :institution_code, :institution, :library_code, :library,
:status_code, :status, :id_one, :id_two, :origin, :display_type, :coverage, :notes,
:url, :request_url, :match_reliability, :request_link_supports_ajax_call, :source_data

PrimoSources are not for everyone as they require programming but they do allow further customization and functionality as necessary.

Further Documentation

Exlibris::Primo::Holding provides further documentation related to creating local sources.

Examples

Two examples of customized sources are:

  • Exlibris::Primo::Source::Aleph

  • Exlibris::Primo::Source::NYUAleph

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary

Attributes inherited from Service

#name, #priority, #request, #service_id, #session_id, #status, #task, #url

Instance Method Summary collapse

Methods inherited from PrimoService

#service_types_generated, #to_primo_source

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_to_view_data, #response_url, #service_types_generated, #view_data_from_service_type

Constructor Details

#initialize(config) ⇒ PrimoSource

Overwrites PrimoService#new.



31
32
33
34
35
# File 'lib/service_adaptors/primo_source.rb', line 31

def initialize(config)
  @service_types = ["holding"]
  @source_attributes = []
  super(config)
end

Instance Method Details

#handle(request) ⇒ Object

Overwrites PrimoService#handle.



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
# File 'lib/service_adaptors/primo_source.rb', line 38

def handle(request)
  primo_sources = request.get_service_type('primo_source', {})
  sources_seen = Array.new # for de-duplicating holdings from catalog.
  primo_sources.each do |primo_source|
    source = primo_source.view_data
    # There are some cases where source records may need to be de-duplicated against existing records
    # Check if we've already seen this record.
    seen_sources_key = source.source_id.to_s + source.source_record_id.to_s
    next if source.dedup? and sources_seen.include?(seen_sources_key)
    # If we get this far, record that we've seen this holding.
    sources_seen.push(seen_sources_key)
    # There may be multiple holdings mapped to one availlibrary here, 
    # so we get the additional holdings and add them.
    source.expand.each do |holding|
      service_data = {}
      @holding_attributes.each do |attr|
        service_data[attr] = holding.method(attr).call
      end
      @source_attributes.each do |attr|
        service_data[attr.to_sym] = holding.method(attr.to_sym).call if holding.respond_to?(attr.to_sym)
      end
      service_data.merge!({
        :call_number => holding.call_number, :collection => holding.collection,
        :collection_str => "#{holding.library} #{holding.collection}",
        :coverage_str => holding.coverage.join("<br />"),
        :coverage_str_array => holding.coverage,
				# :expired determines whether we show the holding in this service
				# Since this is fresh, the data has not yet expired.
				:expired => false, 
 				# :latest determines whether we show the holding in other services, e.g. txt and email.
				# It persists for one more cycle than :expired so services that run after
				# this one, but in the same resolution request have access to the latest holding data.
        :latest => true
      })
      request.add_service_response(
        service_data.merge(
          :service=>self,
          :service_type_value => "holding" 
        )
      )
    end
  end
  return request.dispatched(self, true)
end