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

pulibrary / orangelight / 4c391e0e-519a-40cb-8ad3-354445f4ce03

12 Aug 2025 08:47PM UTC coverage: 85.348% (-10.0%) from 95.335%
4c391e0e-519a-40cb-8ad3-354445f4ce03

push

circleci

web-flow
[#5143] Use access restriction note as Aeon ItemInfo1 if available (#5173)

With this commit, if a user visits a record with an access
restrictions note and presses the Reading Room Request
button, they will get to an Aeon form with the 'Restrictions'
field pre-filled with the restriction note.

If the record does not have an access restrictions note,
the field will be pre-filled with 'Reading Room Access Only',
as it has been previously.

Closes #5143

5493 of 6436 relevant lines covered (85.35%)

251.82 hits per line

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

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

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

13
    def initialize(enum: nil, chron: nil, call_number: nil)
1✔
14
      @enum = enum
2,265✔
15
      @chron = chron
2,265✔
16
      @call_number = call_number
2,265✔
17
    end
18

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

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

33
    private
1✔
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.
39
      def illiad_query_parameters(referrer:, referent:, metadata:, note:)
1✔
40
        qp = map_metdata(referrer:, referent:, metadata:)
×
41
        qp['notes'] = note
×
42
        qp.compact_blank!
×
43
        qp.to_query
×
44
      end
45

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

50
        qp = au_params(metadata:, qp:)
114✔
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.
53
        qp['title'] = [metadata['jtitle'], metadata['btitle'], metadata['title']].find(&:present?)
114✔
54
        qp['volume'] = enum
114✔
55
        qp['issue']  = chron
114✔
56
        qp['sid'] = sid_for_illiad(referrer)
114✔
57
        qp['rft_id'] = get_oclcnum(referent)
114✔
58
        qp['rft.callnum'] = call_number
114✔
59
        qp['rft.oclcnum'] = get_oclcnum(referent)
114✔
60
        qp['genre'] = genere(format: referent.format, qp:)
114✔
61
        qp['CitedIn'] = catalog_url(referent)
114✔
62
        qp
114✔
63
      end
64

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

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

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

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

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

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

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

120
      # Genre normalization. ILLiad pays a lot of attention to `&genre`, but
121
      # doesn't use actual OpenURL rft_val_fmt
122
      def genere(format:, qp:)
1✔
123
        if format == "dissertation"
114✔
124
          'dissertation'
×
125
        elsif qp['isbn'].present? && qp['genre'] == 'book' && qp['atitle'] && qp['issn'].blank?
114✔
126
          # actually a book chapter, not a book, fix it.
127
          'bookitem'
×
128
        elsif qp['issn'].present? && qp['atitle'].present?
114✔
129
          # Otherwise, if there is an ISSN, we force genre to 'article', seems
130
          # to work best.
131
          'article'
48✔
132
        elsif qp['genre'] == 'unknown' && qp['atitle'].blank?
66✔
133
          # WorldCat likes to send these, ILLiad is happier considering them 'book'
134
          "book"
×
135
        else
136
          qp['genre']
66✔
137
        end
138
      end
139
  end
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