<commit_before>require 'faraday'

module Requests
  class Recall
    include Requests::Voyager
    include Requests::Scsb
    include Requests::Bibdata

    def initialize(submission)
      @service_type = 'recall'
      @submission = submission
      @errors = []
      @sent = []
      handle
    end

    def handle
      items = @submission.filter_items_by_service(@service_type)
      scsb_params = {}
      items.each do |item|
        location = get_location(item['location_code'])
        if (scsb_locations.include? item['location_code']) || (location[:library][:code] == 'recap')
          params = scsb_param_mapping(@submission.bib, @submission.user, item)
          if scsb_params.empty?
            scsb_params = params
          else
            scsb_params[:itemBarcodes].push(item['barcode'])
          end
        else
          params = param_mapping(@submission.bib, @submission.user, item)
          payload = request_payload(item)
          r = put_response(params, payload)
          xml_response = Nokogiri::XML(r.body)
          unless xml_response.xpath("//reply-text").text() == 'ok'
            error_message = "Failed request: " + xml_response.xpath("//note").text()
            @errors << { bibid: params[:recordID], item: params[:itemID], user_name: @submission.user[:user_name], patron: params[:patron], error: error_message }
          else
            @sent << { bibid: params[:Bbid], item: params[:item], user_name: @submission.user[:user_name], patron: params[:patron] }
          end
        end
      end

      return false if scsb_params.empty?
      params = scsb_params
      # response = scsb_request(scsb_params)
      # if response.status != 200
      #   error_message = "Request failed because #{response.body}"
      #   @errors << { type: 'recall', bibid: params[:bibId], item: params[:itemBarcodes], user_name: @submission.user[:user_name], barcode: params[:patronBarcode], error: error_message }
      # else
      #   response = parse_scsb_response(response)
      #   if response[:success] == false
      #     @errors << { type: 'recall', bibid: params[:bibId], item: params[:itemBarcodes], user_name: @submission.user[:user_name], barcode: params[:patronBarcode], error: response[:screenMessage] }
      #   else
      @sent << { bibid: params[:bibId], item: params[:itemBarcodes], user_name: @submission.user[:user_name], barcode: params[:patronBarcode] }
      #   end
      # end
    end

    def submitted
      @sent
    end

    def errors
      @errors
    end
  end
end
<commit_msg>Allow all local pul items to pass through standard recall dialog.<commit_after>require 'faraday'

module Requests
  class Recall
    include Requests::Voyager
    include Requests::Scsb
    include Requests::Bibdata

    def initialize(submission)
      @service_type = 'recall'
      @submission = submission
      @errors = []
      @sent = []
      handle
    end

    def handle
      items = @submission.filter_items_by_service(@service_type)
      scsb_params = {}
      items.each do |item|
        # location = get_location(item['location_code'])
        if scsb_locations.include? item['location_code'] # || (location[:library][:code] == 'recap')
          params = scsb_param_mapping(@submission.bib, @submission.user, item)
          if scsb_params.empty?
            scsb_params = params
          else
            scsb_params[:itemBarcodes].push(item['barcode'])
          end
        else
          params = param_mapping(@submission.bib, @submission.user, item)
          payload = request_payload(item)
          r = put_response(params, payload)
          xml_response = Nokogiri::XML(r.body)
          unless xml_response.xpath("//reply-text").text() == 'ok'
            error_message = "Failed request: " + xml_response.xpath("//note").text()
            @errors << { bibid: params[:recordID], item: params[:itemID], user_name: @submission.user[:user_name], patron: params[:patron], error: error_message }
          else
            @sent << { bibid: params[:Bbid], item: params[:item], user_name: @submission.user[:user_name], patron: params[:patron] }
          end
        end
      end

      return false if scsb_params.empty?
      params = scsb_params
      # response = scsb_request(scsb_params)
      # if response.status != 200
      #   error_message = "Request failed because #{response.body}"
      #   @errors << { type: 'recall', bibid: params[:bibId], item: params[:itemBarcodes], user_name: @submission.user[:user_name], barcode: params[:patronBarcode], error: error_message }
      # else
      #   response = parse_scsb_response(response)
      #   if response[:success] == false
      #     @errors << { type: 'recall', bibid: params[:bibId], item: params[:itemBarcodes], user_name: @submission.user[:user_name], barcode: params[:patronBarcode], error: response[:screenMessage] }
      #   else
      @sent << { bibid: params[:bibId], item: params[:itemBarcodes], user_name: @submission.user[:user_name], barcode: params[:patronBarcode] }
      #   end
      # end
    end

    def submitted
      @sent
    end

    def errors
      @errors
    end
  end
end

{'fraction_non_alphanumeric': 0.12694401244167963, 'fraction_numerical': 0.0011664074650077762, 'mean_word_length': 2.828125, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1979654', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1541, 'n_words': 334}