• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / orangelight / 0e37073d-109c-440c-949f-49d2aa86311b

18 Aug 2025 09:05PM UTC coverage: 0.482% (-94.9%) from 95.343%
0e37073d-109c-440c-949f-49d2aa86311b

push

circleci

web-flow
Replace per_page_options_for_select with custom component to avoid deprecation issue (#5186)

* Start creating new component to address deprecaton warning

* Replace per_page_options_for_select with custom component to avoid deprecation issue

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

---------

Co-authored-by: Ryan Jensen <rj1044@princeton.edu>
Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>

0 of 33 new or added lines in 1 file covered. (0.0%)

9374 existing lines in 213 files now uncovered.

47 of 9753 relevant lines covered (0.48%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/models/requests/illiad.rb
1
# frozen_string_literal: true
UNCOV
2
module Requests
×
3
  # ILL related helpers
UNCOV
4
  class Illiad
×
UNCOV
5
    attr_reader :enum, :chron, :call_number
×
6

UNCOV
7
    METADATA_MAPPING = {
×
UNCOV
8
      "genre" => "genre", "issn" => "issn", "isbn" => "isbn", "stitle" => "stitle", "date" => "rft.date", "atitle" => "atitle",
×
UNCOV
9
      "pub" => "rft.pub", "place" => "rft.place", "edition" => "rft.edition"
×
UNCOV
10
    }.freeze
×
UNCOV
11
    private_constant :METADATA_MAPPING
×
12

UNCOV
13
    def initialize(enum: nil, chron: nil, call_number: nil)
×
UNCOV
14
      @enum = enum
×
UNCOV
15
      @chron = chron
×
UNCOV
16
      @call_number = call_number
×
UNCOV
17
    end
×
18

19
    # accepts a @solr_open_url_context object and formats it appropriately for ILL
UNCOV
20
    def illiad_request_url(solr_open_url_context, note: nil)
×
UNCOV
21
      query_params = illiad_query_parameters(referrer: solr_open_url_context.referrer, referent: solr_open_url_context.referent,
×
UNCOV
22
                                             metadata: solr_open_url_context.referent.metadata, note:)
×
UNCOV
23
      "#{Requests.config[:ill_base]}?#{query_params}"
×
UNCOV
24
    end
×
25

UNCOV
26
    def illiad_request_parameters(solr_open_url_context, note: nil)
×
UNCOV
27
      mapping = map_metdata(referrer: solr_open_url_context.referrer, referent: solr_open_url_context.referent,
×
UNCOV
28
                            metadata: solr_open_url_context.referent.metadata)
×
UNCOV
29
      mapping[:note] = note
×
UNCOV
30
      mapping
×
UNCOV
31
    end
×
32

UNCOV
33
    private
×
34

35
      ## below take from Umlaut's illiad service adaptor
36
      # https://github.com/team-umlaut/umlaut/blob/master/app/service_adaptors/illiad.rb
37
      # takes an existing openURL and illiad-izes it.
38
      # also attempts to handle the question of enumeration.
UNCOV
39
      def illiad_query_parameters(referrer:, referent:, metadata:, note:)
×
UNCOV
40
        qp = map_metdata(referrer:, referent:, metadata:)
×
UNCOV
41
        qp['notes'] = note
×
UNCOV
42
        qp.compact_blank!
×
UNCOV
43
        qp.to_query
×
UNCOV
44
      end
×
45

UNCOV
46
      def map_metdata(referrer:, referent:, metadata:)
×
UNCOV
47
        qp = {}
×
UNCOV
48
        METADATA_MAPPING.each { |metadata_key, illiad_key| qp[illiad_key] = metadata[metadata_key.to_s] }
×
49

UNCOV
50
        qp = au_params(metadata:, qp:)
×
51
        # ILLiad always wants 'title', not the various title keys that exist in OpenURL
52
        # For some reason these go to ILLiad prefixed with rft.
UNCOV
53
        qp['title'] = [metadata['jtitle'], metadata['btitle'], metadata['title']].find(&:present?)
×
UNCOV
54
        qp['volume'] = enum
×
UNCOV
55
        qp['issue']  = chron
×
UNCOV
56
        qp['sid'] = sid_for_illiad(referrer)
×
UNCOV
57
        qp['rft_id'] = get_oclcnum(referent)
×
UNCOV
58
        qp['rft.callnum'] = call_number
×
UNCOV
59
        qp['rft.oclcnum'] = get_oclcnum(referent)
×
UNCOV
60
        qp['genre'] = genere(format: referent.format, qp:)
×
UNCOV
61
        qp['CitedIn'] = catalog_url(referent)
×
UNCOV
62
        qp
×
UNCOV
63
      end
×
64

65
      # Grab a source label out of `sid` or `rfr_id`, add on our suffix.
UNCOV
66
      def sid_for_illiad(referrer)
×
UNCOV
67
        sid = referrer.identifiers.first || ""
×
UNCOV
68
        sid = sid.gsub(%r{\Ainfo\:sid/}, '')
×
UNCOV
69
        "#{sid}#{@sid_suffix}"
×
UNCOV
70
      end
×
71

72
      ## From https://github.com/team-umlaut/umlaut/blob/master/app/mixin_logic/metadata_helper.rb
UNCOV
73
      def get_oclcnum(rft)
×
UNCOV
74
        get_identifier(:info, "oclcnum", rft)
×
UNCOV
75
      end
×
76

UNCOV
77
      def catalog_url(referent)
×
UNCOV
78
        bibidata_url = URI(referent.identifiers.first)
×
UNCOV
79
        bibid = bibidata_url.path.split('/').last
×
UNCOV
80
        "#{Requests.config[:pulsearch_base]}/catalog/#{bibid}"
×
UNCOV
81
      end
×
82

UNCOV
83
      def get_identifier(type, sub_scheme, referent, options = {})
×
UNCOV
84
        options[:multiple] ||= false
×
UNCOV
85
        identifiers = identifiers_for_type(type:, sub_scheme:, referent:)
×
UNCOV
86
        if identifiers.blank? && ['lccn', 'oclcnum', 'isbn', 'issn', 'doi', 'pmid'].include?(sub_scheme)
×
87

UNCOV
88
          from_rft = referent.metadata[sub_scheme]
×
UNCOV
89
          identifiers = [from_rft] if from_rft.present?
×
UNCOV
90
        end
×
UNCOV
91
        if options[:multiple]
×
92
          identifiers
×
UNCOV
93
        elsif identifiers[0].blank?
×
UNCOV
94
          nil
×
UNCOV
95
        else
×
UNCOV
96
          identifiers[0]
×
UNCOV
97
        end
×
UNCOV
98
      end
×
99
      ### end code from umlaut
100

UNCOV
101
      def identifiers_for_type(type:, sub_scheme:, referent:)
×
UNCOV
102
        raise Exception, "type must be :urn or :info" unless (type == :urn) || (type == :info)
×
UNCOV
103
        prefix = case type
×
UNCOV
104
                 when :info then "info:#{sub_scheme}/"
×
105
                 when :urn  then "urn:#{sub_scheme}:"
×
UNCOV
106
                 end
×
UNCOV
107
        referent.identifiers.collect { |id| Regexp.last_match(1) if id =~ /^#{prefix}(.*)/ }.compact
×
UNCOV
108
      end
×
109

UNCOV
110
      def au_params(metadata:, qp:)
×
UNCOV
111
        if metadata['aulast']
×
112
          qp["rft.aulast"] = metadata['aulast']
×
113
          qp["rft.aufirst"] = [metadata['aufirst'], metadata["auinit"]].find(&:present?)
×
UNCOV
114
        else
×
UNCOV
115
          qp["rft.au"] = metadata["au"]
×
UNCOV
116
        end
×
UNCOV
117
        qp
×
UNCOV
118
      end
×
119

120
      # Genre normalization. ILLiad pays a lot of attention to `&genre`, but
121
      # doesn't use actual OpenURL rft_val_fmt
UNCOV
122
      def genere(format:, qp:)
×
UNCOV
123
        if format == "dissertation"
×
124
          'dissertation'
×
UNCOV
125
        elsif qp['isbn'].present? && qp['genre'] == 'book' && qp['atitle'] && qp['issn'].blank?
×
126
          # actually a book chapter, not a book, fix it.
127
          'bookitem'
×
UNCOV
128
        elsif qp['issn'].present? && qp['atitle'].present?
×
129
          # Otherwise, if there is an ISSN, we force genre to 'article', seems
130
          # to work best.
UNCOV
131
          'article'
×
UNCOV
132
        elsif qp['genre'] == 'unknown' && qp['atitle'].blank?
×
133
          # WorldCat likes to send these, ILLiad is happier considering them 'book'
UNCOV
134
          "book"
×
UNCOV
135
        else
×
UNCOV
136
          qp['genre']
×
UNCOV
137
        end
×
UNCOV
138
      end
×
UNCOV
139
  end
×
UNCOV
140
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc