• 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/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
    # rubocop:disable Naming/PredicateMethod
14
    def handle
×
15
      items = submission.filter_items_by_service(service_type)
×
16
      items.each do |item|
×
17
        item_status = handle_item(item:)
×
18
        @sent << item_status if item_status.present?
×
19
      end
×
20
      return false if @errors.present?
×
21
    end
×
22
    # rubocop:enable Naming/PredicateMethod
23

24
    def duplicate?
×
25
      duplicate
×
26
    end
×
27

28
    def handle_item(item:)
×
29
      status = {}
×
30
      begin
×
31
        status = if item["user_supplied_enum"].present?
×
32
                   item # Alma can not create the correct hold.  This assumes the correct emails will go out during send_mail
×
33
                 else
×
34
                   place_hold(item)
×
35
                 end
×
36
      rescue Alma::BibRequest::ItemAlreadyExists
×
37
        status = item.merge(payload: payload(item), response: "DuplicateRequest")
×
38
        @duplicate = true
×
39
      rescue StandardError => invalid
×
40
        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
×
41
      end
×
42
      status
×
43
    end
×
44

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

53
    def send_mail
×
54
      return if duplicate?
×
55
      super
×
56
    end
×
57

58
    private
×
59

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

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

79
        { 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 }
×
80
      end
×
81
  end
×
82
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