Class: Hip3Service

Inherits:
Service show all
Includes:
MarcHelper, MetadataHelper
Defined in:
app/service_adaptors/hip3_service.rb

Direct Known Subclasses

HipHoldingSearch

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary collapse

Attributes inherited from Service

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

Instance Method Summary collapse

Methods included from MarcHelper

#add_856_links, #edition_statement, #get_title, #get_years, #gmd_values, #service_type_for_856, #should_skip_856_link?, #strip_gmd

Methods included from MetadataHelper

#get_doi, #get_epage, #get_gpo_item_nums, #get_identifier, #get_isbn, #get_issn, #get_lccn, #get_month, #get_oclcnum, #get_pmid, #get_search_creator, #get_search_terms, #get_search_title, #get_spage, #get_sudoc, #get_top_level_creator, #get_year, #normalize_lccn, #normalize_title, #raw_search_title, title_is_serial?

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_url, #translate

Constructor Details

#initialize(config) ⇒ Hip3Service

Returns a new instance of Hip3Service.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/service_adaptors/hip3_service.rb', line 14

def initialize(config)
  # defaults
  @map_856_to_service = 'fulltext'
  # If you are sending an OpenURL from a library service, you may
  # have the HIP bibnum, and include it in the OpenURL as, eg.
  # rft_id=http://catalog.library.jhu.edu/bib/343434 (except URL-encoded)
  # Then you'd set rft_id_bibnum_prefix to http://catalog.library.jhu.edu/bib/
  @rft_id_bibnum_prefix = nil
  @profile = "general"
  super(config)

  # Trim question-mark from base_url, if given
  @base_path.chop! if (@base_path.rindex('?') ==  @base_path.length)     
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



9
10
11
# File 'app/service_adaptors/hip3_service.rb', line 9

def base_path
  @base_path
end

Instance Method Details

#add_copies(request, bib_array, options = {}) ⇒ Object

Takes an array of Hip3::Bib objects believed to be exact matches for the citation querried, and adds response objects for them Returns a hash of arrays of ServiceResponses added.



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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/service_adaptors/hip3_service.rb', line 57

def add_copies(request, bib_array, options = {})
  #debugger
  
  # default    
  options[:match_reliability] ||= ServiceResponse::MatchExact

  responses_added = Hash.new

  

  
  #Okay, we actually want to make each _copy_ into a service response.
  #A bib may have multiple copies. We are merging bibs, and just worrying
  #about the aggregated list of copies.
  holdings = bib_array.collect { |bib| bib.holdings }.flatten
  bib_array.each do |bib|
    
  
    bib.holdings.each do |holding|

    
      next if holding.dummy?

      
      
      service_data = {}
      service_data[:url] = holding.bib.http_url
      service_data[:source_name] = holding.collection_str unless holding.collection_str.nil?
      service_data[:call_number] = holding.call_no
      service_data[:status] = holding.status_str
      service_data[:location] = holding.location_str
      service_data[:collection_str] = holding.collection_str
      service_data[:copy_str] = holding.copy_str
      service_data[:coverage_str] = holding.coverage_str
      service_data[:coverage_str_array] = holding.coverage_str_to_a 
      service_data[:notes] = holding.notes
      # If it's not a serial copy, we can add a direct request url.
      unless ( holding.kind_of?(Hip3::SerialCopy) )
        service_data[:request_url] = self.base_path + "?profile=#{@profile}&menu=request&aspect=none&bibkey=#{holding.bib.bibNum}&itemkey=#{holding.id}"
      end

      # Need to say it's not an exact match neccesarily?
      
      unless ( options[:match_reliability] == ServiceResponse::MatchExact )
          service_data[:match_reliability] = options[:match_reliability]
          
          service_data[:edition_str] = edition_statement(bib.marc_xml)
      end
      
      display_text = ""
      #display_text << (holding.location_str + ' ')unless holding.location_str.nil?
      display_text << (holding.copy_str + ' ') unless holding.copy_str.nil?

      # coverage strings, may be multiple
      holding.coverage_str_to_a.each {|s| display_text << (s + ' ')}

      display_text << holding.notes unless holding.notes.nil?
      service_data[:display_text] = display_text
      
      response = request.add_service_response(
        service_data.merge(
          :service=>self, 
          :service_type_value => 'holding'  )
        )

      responses_added['holding'] ||= Array.new
      responses_added['holding'].push( response )

    end
  end

  return responses_added
end

#get_bibnum(rft) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'app/service_adaptors/hip3_service.rb', line 135

def get_bibnum(rft)
  return nil unless @rft_id_bibnum_prefix

  identifier = rft.identifiers.find do |id| 
    id[0, @rft_id_bibnum_prefix.length] == @rft_id_bibnum_prefix
  end

  if ( identifier )
    return identifier[@rft_id_bibnum_prefix.length, identifier.length]
  else
    return nil
  end
  
end

#handle(request) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/service_adaptors/hip3_service.rb', line 38

def handle(request)    
  bib_searcher = Hip3::BibSearcher.new(@base_path)
  
  bib_searcher.issn = request.referent.issn 
  bib_searcher.isbn = request.referent.isbn
  bib_searcher.sudoc = get_sudoc(request.referent)

  results = bib_searcher.search

  add_856_links(request, results.collect {|b| b.marc_xml})
  add_copies(request, results)

  return request.dispatched(self, true)

end

#service_types_generatedObject

Standard method, used by background service updater. See Service docs.



30
31
32
33
34
35
# File 'app/service_adaptors/hip3_service.rb', line 30

def service_types_generated
  # We generate full text and holdings types, right now.
  types = [ ServiceTypeValue[:fulltext], ServiceTypeValue[:holding], ServiceTypeValue[:table_of_contents] ]
  
  return types
end

#url_service_type(field) ⇒ Object



131
132
133
# File 'app/service_adaptors/hip3_service.rb', line 131

def url_service_type( field )
  return service_type_for_856(field, :default_service_type =>  @map_856_to_service)            
end