-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Illiad requests into requests page (#991)
* retrieving illiad requests to include in mylibrary * ensuring counts show up in other parts of the app, moving illiad request retrieval into patron * rubocop changes * incorporating illiad requests directly into patron requests, extending request template * fixing rubocop error * stubbing out illiad transaction request * adding and modifying tests * adding more tests * Additional updates, styling, adding ill URL to request * fixing tests * updating stylesheet and putting manage link in div * updating shared group self tab to correct requests number * updating based on suggestions
- Loading branch information
Showing
12 changed files
with
243 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,7 @@ | |
width: auto; | ||
} | ||
} | ||
.illiad-link { | ||
padding: 6px 12px 6px 0px; | ||
font-size: 1rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,5 +112,7 @@ def title | |
def to_partial_path | ||
'requests/borrow_direct_request' | ||
end | ||
|
||
def manage_request_link; end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,8 @@ def date_sort_key | |
] | ||
end | ||
|
||
def manage_request_link; end | ||
|
||
private | ||
|
||
def library_key | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# frozen_string_literal: true | ||
|
||
### | ||
# Class to handle creation of ILLiad OpenURL request | ||
### | ||
class IlliadRequests | ||
def initialize(user_id) | ||
@user_id = user_id | ||
end | ||
|
||
def requests | ||
request_user_transactions.map do |illiad_result| | ||
IlliadRequests::Request.new(illiad_result) | ||
end | ||
rescue StandardError => e | ||
Honeybadger.notify(e, error_message: "Unable to retrieve ILLIAD transactions with #{e}") | ||
[] | ||
end | ||
|
||
private | ||
|
||
def request_user_transactions | ||
url = "#{Settings.sul_illiad}ILLiadWebPlatform/Transaction/UserRequests/#{@user_id}" | ||
conn = Faraday.new(url: Settings.sul_illiad) do |req| | ||
req.headers['ApiKey'] = Settings.illiad_api_key | ||
req.headers['Accept'] = 'application/json; version=1' | ||
req.adapter Faraday.default_adapter | ||
end | ||
|
||
response = conn.get(url) | ||
JSON.parse(response.body) | ||
end | ||
|
||
class Request | ||
# illiad_result is a hash with the results from the Illiad Request | ||
def initialize(illiad_result) | ||
@illiad_result = illiad_result | ||
end | ||
|
||
def scan_type? | ||
@illiad_result['PhotoJournalTitle'].present? | ||
end | ||
|
||
def key | ||
@illiad_result['TransactionNumber'].to_s | ||
end | ||
|
||
# rubocop:disable Metrics/MethodLength | ||
def sort_key(key) | ||
sort_key = case key | ||
when :library | ||
[pickup_library, title, author, call_number] | ||
when :date | ||
[*date_sort_key, title, author, call_number] | ||
when :title | ||
[title, author, call_number] | ||
when :author | ||
[author, title, call_number] | ||
when :call_number | ||
[call_number] | ||
end | ||
sort_key.join('---') | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
|
||
def date_sort_key | ||
(expiration_date || Folio::Request::END_OF_DAYS).strftime('%FT%T') | ||
end | ||
|
||
def title | ||
scan_type? ? @illiad_result['PhotoJournalTitle'] : @illiad_result['LoanTitle'] | ||
end | ||
|
||
def call_number | ||
@illiad_result['CallNumber'] | ||
end | ||
|
||
def author | ||
scan_type? ? @illiad_result['PhotoArticleAuthor'] : @illiad_result['LoanAuthor'] | ||
end | ||
|
||
def placed_date | ||
Time.zone.parse(@illiad_result['CreationDate']) | ||
end | ||
|
||
def pickup_library | ||
@illiad_result['ItemInfo4'] | ||
end | ||
|
||
def expiration_date | ||
scan_type? ? placed_date + 2.months : Time.zone.parse(@illiad_result['NotWantedAfter']) | ||
end | ||
|
||
def fill_by_date; end | ||
|
||
def ready_for_pickup? | ||
ready_for_pickup_status = ['Media Microtext Checkout to Customer', | ||
'Special Collections Checked Out to Customer', | ||
'Customer Notified via E-Mail'] | ||
ready_for_pickup_status.include?(@illiad_result['TransactionStatus']) | ||
end | ||
|
||
def from_ill? | ||
true | ||
end | ||
|
||
def service_point_name | ||
Mylibrary::Application.config.library_map[pickup_library] || pickup_library | ||
end | ||
|
||
def waitlist_position; end | ||
|
||
def to_partial_path | ||
'requests/request' | ||
end | ||
|
||
def manage_request_link | ||
"https://sulils.stanford.edu/illiad.dll?Action=10&Form=72&Value=#{key}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe IlliadRequests do | ||
subject(:ill_request) { described_class.new(patron_sunet_id) } | ||
|
||
let(:patron_sunet_id) { 'sunet' } | ||
let(:hold_recall_result) do | ||
'{"TransactionNumber":347070, | ||
"Username":"sunet", | ||
"LoanAuthor":"Gilbert Roy", | ||
"LoanTitle":"Disney Motion Pictures", | ||
"CreationDate":"2023-10-11T10:49:41.783", | ||
"ItemInfo4":"GREEN", | ||
"NotWantedAfter":"2024-10-11", | ||
"CallNumber":"ABC"}' | ||
end | ||
let(:scan_result) do | ||
'{"TransactionNumber":12345, | ||
"Username":"sunet", | ||
"PhotoArticleAuthor":"Frederick Wright", | ||
"PhotoJournalTitle":"String Beans", | ||
"CreationDate":"2023-10-12T10:49:41.783", | ||
"ItemInfo4":"GREEN", | ||
"CallNumber":"DEF"}' | ||
end | ||
let(:transaction_results) do | ||
"[#{hold_recall_result},#{scan_result}]" | ||
end | ||
|
||
context 'when successful, it correctly retrieves transaction requests' do | ||
before do | ||
stub_request(:get, "#{Settings.sul_illiad}ILLiadWebPlatform/Transaction/UserRequests/#{patron_sunet_id}") | ||
.to_return(status: 200, body: transaction_results, headers: {}) | ||
end | ||
|
||
it 'correctly returns request objects' do | ||
expect(ill_request.requests.length).to be(2) | ||
end | ||
end | ||
|
||
describe 'IlliadRequests::Request' do | ||
context 'when the request is ILLIAD hold/recall' do | ||
subject(:hold) { IlliadRequests::Request.new(JSON.parse(hold_recall_result)) } | ||
|
||
it 'correctly identified hold recall result as not being type scan' do | ||
expect(hold.scan_type?).to be(false) | ||
end | ||
|
||
it 'correctly retrieves title for non-scan transaction' do | ||
expect(hold.title).to eq('Disney Motion Pictures') | ||
end | ||
|
||
it 'correctly retrieves author for non-scan transaction' do | ||
expect(hold.author).to eq('Gilbert Roy') | ||
end | ||
end | ||
|
||
context 'when the request is an ILLIAD scan request' do | ||
subject(:scan) { IlliadRequests::Request.new(JSON.parse(scan_result)) } | ||
|
||
it 'correctly identified scan result as type scan' do | ||
expect(scan.scan_type?).to be(true) | ||
end | ||
|
||
it 'correctly retrieves title for scan transaction' do | ||
expect(scan.title).to eq('String Beans') | ||
end | ||
|
||
it 'correctly retrieves author for scan transaction' do | ||
expect(scan.author).to eq('Frederick Wright') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters