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

pulibrary / orangelight / 00dbc10b-d747-4ad7-b211-7b26d753abbb

14 Aug 2025 01:25PM UTC coverage: 0.483% (-94.9%) from 95.343%
00dbc10b-d747-4ad7-b211-7b26d753abbb

push

circleci

web-flow
Merge pull request #5181 from pulibrary/dependabot/bundler/activestorage-7.2.2.2

Bump activestorage from 7.2.2.1 to 7.2.2.2

47 of 9721 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
2
module Requests
×
3
  # ILL related helpers
4
  class Illiad
×
5
    attr_reader :enum, :chron, :call_number
×
6

7
    METADATA_MAPPING = {
×
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
×
12

13
    def initialize(enum: nil, chron: nil, call_number: nil)
×
14
      @enum = enum
×
15
      @chron = chron
×
16
      @call_number = call_number
×
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)
×
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)
×
27
      mapping = map_metdata(referrer: solr_open_url_context.referrer, referent: solr_open_url_context.referent,
×
28
                            metadata: solr_open_url_context.referent.metadata)
×
29
      mapping[:note] = note
×
30
      mapping
×
31
    end
×
32

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.
39
      def illiad_query_parameters(referrer:, referent:, metadata:, note:)
×
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:)
×
47
        qp = {}
×
48
        METADATA_MAPPING.each { |metadata_key, illiad_key| qp[illiad_key] = metadata[metadata_key.to_s] }
×
49

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

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

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

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

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

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

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

110
      def au_params(metadata:, qp:)
×
111
        if metadata['aulast']
×
112
          qp["rft.aulast"] = metadata['aulast']
×
113
          qp["rft.aufirst"] = [metadata['aufirst'], metadata["auinit"]].find(&:present?)
×
114
        else
×
115
          qp["rft.au"] = metadata["au"]
×
116
        end
×
117
        qp
×
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:)
×
123
        if format == "dissertation"
×
124
          'dissertation'
×
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'
×
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.
131
          'article'
×
132
        elsif qp['genre'] == 'unknown' && qp['atitle'].blank?
×
133
          # WorldCat likes to send these, ILLiad is happier considering them 'book'
134
          "book"
×
135
        else
×
136
          qp['genre']
×
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