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

pulibrary / orangelight / 62bad3f1-d46d-40af-822c-403d653da2a8

17 Jun 2025 05:30PM UTC coverage: 0.447% (-94.9%) from 95.337%
62bad3f1-d46d-40af-822c-403d653da2a8

push

circleci

maxkadel
Install chrome & chromedriver for smoke specs

43 of 9610 relevant lines covered (0.45%)

0.01 hits per line

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

0.0
/app/models/requests/submissions/hold_item.rb
1
# frozen_string_literal: true
2
require 'faraday'
×
3

4
module Requests::Submissions
×
5
  class HoldItem < Service
×
6
    attr_accessor :duplicate
×
7

8
    def initialize(submission, service_type: 'on_shelf')
×
9
      super
×
10
      @duplicate = false
×
11
    end
×
12

13
    def handle
×
14
      items = submission.filter_items_by_service(service_type)
×
15
      items.each do |item|
×
16
        item_status = handle_item(item:)
×
17
        @sent << item_status if item_status.present?
×
18
      end
×
19
      return false if @errors.present?
×
20
    end
×
21

22
    def duplicate?
×
23
      duplicate
×
24
    end
×
25

26
    def handle_item(item:)
×
27
      status = {}
×
28
      begin
×
29
        status = if item["user_supplied_enum"].present?
×
30
                   item # Alma can not create the correct hold.  This assumes the correct emails will go out during send_mail
×
31
                 else
×
32
                   place_hold(item)
×
33
                 end
×
34
      rescue Alma::BibRequest::ItemAlreadyExists
×
35
        status = item.merge(payload: payload(item), response: "DuplicateRequest")
×
36
        @duplicate = true
×
37
      rescue StandardError => invalid
×
38
        errors << { reply_text: "Can not create hold", create_hold: { note: "Hold can not be created", message: invalid.message } }.merge(submission.bib.to_h).merge(item.to_h).with_indifferent_access
×
39
      end
×
40
      status
×
41
    end
×
42

43
    def success_message
×
44
      if duplicate?
×
45
        I18n.t("requests.submit.duplicate")
×
46
      else
×
47
        I18n.t("requests.submit.#{service_type}_success", default: I18n.t('requests.submit.success'))
×
48
      end
×
49
    end
×
50

51
    def send_mail
×
52
      return if duplicate?
×
53
      super
×
54
    end
×
55

56
    private
×
57

58
      def place_hold(item)
×
59
        status = {}
×
60
        options = payload(item)
×
61
        response = Alma::ItemRequest.submit(options)
×
62
        if response.success?
×
63
          status = item.merge(payload: options, response: response.raw_response.parsed_response)
×
64
        else
×
65
          errors << reponse_json["response"].merge(submission.bib.to_h).merge(item.to_h).merge(type: service_type)
×
66
        end
×
67
        status
×
68
      end
×
69

70
      def payload(item)
×
71
        pick_up_library = if item["pick_up_location_code"] == "annex"
×
72
                            "firestone"
×
73
                          else
×
74
                            item["pick_up_location_code"]
×
75
                          end
×
76

77
        { mms_id: submission.bib['id'], holding_id: item["mfhd"], item_pid: item['item_id'], user_id: submission.patron.university_id, request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: pick_up_library }
×
78
      end
×
79
  end
×
80
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