Skip to content

Commit

Permalink
Merge changes for v2.2.0 (ReShare) to master (#95)
Browse files Browse the repository at this point in the history
* Merge changes for v2.1.6 (#92)

* DISCOVERYACCESS-7627 - for rbenv users

* DISCOVERYACCESS-7627 - rails 6 required for cornell-blacklight

* DISCOVERYACCESS-7627 - bump version number

* DISCOVERYACCESS-7627 - rails 6 for cornell-blacklight

* DISCOVERYACCESS-7627 - try rails 7

* DISCOVERYACCESS-7627 - back to rails 6.1

* DISCOVERYACCESS-7627 - bump version number

* DISCOVERYACCESS-7627 - forgot save all

* Update release notes

Co-authored-by: James Reidy <[email protected]>

* DISCOVERYACCESS-7838: update my account login page text

* Merge changes for v2.2.0 (ReShare) to dev (#94)

* WIP

* Eliminate ilsapi cgi script reference (talk directly to illiad6.cgi)

* Display pickup location for BD

* Differentiate pending and available ReShare requests

* Bump to v2.2.0

Co-authored-by: James Reidy <[email protected]>
Co-authored-by: Melissa Wallace <[email protected]>
  • Loading branch information
3 people authored Dec 13, 2022
1 parent 952f56f commit 30bedf6
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 58 deletions.
25 changes: 12 additions & 13 deletions app/assets/javascripts/my_account/account.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,23 @@ account =
available.push requestObj

# Do the same sorting with the Borrow Direct data
# BD entries look like this:
# {
# au: <author>
# iid: COR-<number>
# status: <status>
# system: "bd"
# tl: <title>
# }
#
# TODO: Handle other statuses once they're known
pendingStatuses = ['ENTERED', 'IN_PROCESS', 'SHIPPED']
availableStatuses = []
# BD entries come from ReShare and have one of 6 possible stages: PREPARING, LOCAL, ACTIVE,
# ACTIVE_PENDING_CONDITIONAL_ANSWER, ACTIVE_SHIPPED, COMPLETED. Anything other than COMPLETED
# means the request is still pending.

pendingStatuses = ['ENTERED', 'IN_PROCESS', 'REQ_SHIPPED', 'REQ_EXPECTS_TO_SUPPLY']
availableStatuses = ['REQ_CHECKED_IN']

bdData.forEach (entry) ->
# Olin Library's pickup location is actually '*Olin Library', so strip off the *
location = entry.lo.replace '*', ''
requestObj = {
iid: entry.iid, # N.B. The ID used here for FOLIO requests is the REQUEST ID, not the item ID!
tl: entry.tl,
system: 'bd'
system: 'bd',
lo: location
}

# This is a bit of a hack. An ON_LOAN item is really an available request, but at that point in
# the process it shows up as a FOLIO loan item; if we include this one in available_requests,
# we'll get a duplicate entry. So we'll ignore items with status ON_LOAN here.
Expand Down
102 changes: 76 additions & 26 deletions app/controllers/my_account/account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
module MyAccount

class AccountController < ApplicationController
#include Reshare

before_action :heading
before_action :authenticate_user, except: [:intro]

Expand Down Expand Up @@ -167,7 +169,10 @@ def get_illiad_data
# Rails.logger.debug "mjc12test: Start parsing"

begin
response = RestClient.get "#{ENV['MY_ACCOUNT_ILSAPI_URL']}?netid=#{netid}"
# NOTE: the key MY_ACCOUNT_ISLAPI_URL is a misomer now, because we've eliminated the ilsapi CGI
# script and are using the illiad6.cgi script, which ilsapi called, without the middleman. Probably
# the key should be renamed at some point.
response = RestClient.get "#{ENV['MY_ACCOUNT_ILSAPI_URL']}?netid=#{netid}&fmt=json&wrapper=n"
record = JSON.parse response.body
rescue => error
Rails.logger.error "MyAccount error: Could not find a patron entry for #{netid}"
Expand Down Expand Up @@ -215,8 +220,6 @@ def get_illiad_data
end
end

Rails.logger.debug "mjc12test: Done with parsing"

#bd_items = get_bd_requests netid
bd_items = []
#Rails.logger.debug "mjc12test: got bd_items #{bd_items}"
Expand Down Expand Up @@ -327,43 +330,90 @@ def get_bd_requests

# Using the BD API is an expensive operation, so use the Rails session to cache the
# response the first time a user accesses her account
Rails.logger.debug "mjc12test: Checking session #{session['mjc12_bd_items']}"
Rails.logger.debug "mjc12a: Checking session #{session['mjc12_bd_items']}"
#return session[netid + '_bd_items'] if session[netid + '_bd_items']
Rails.logger.debug "mjc12test: Can't use session value for BD items - doing full lookup #{}"

barcode = patron_barcode(netid)
#barcode = patron_barcode(netid)

# Set parameters for the Borrow Direct API
BorrowDirect::Defaults.library_symbol = 'CORNELL'
BorrowDirect::Defaults.find_item_patron_barcode = barcode
BorrowDirect::Defaults.timeout = ENV['BORROW_DIRECT_TIMEOUT'].to_i || 30 # (seconds)
BorrowDirect::Defaults.api_base = BorrowDirect::Defaults::PRODUCTION_API_BASE
BorrowDirect::Defaults.api_key = ENV['BORROW_DIRECT_PROD_API_KEY']

begin
items = BorrowDirect::RequestQuery.new(barcode).requests('open')
rescue BorrowDirect::Error => e
# The Borrow Direct gem doesn't differentiate among all of the BD API error types.
# In this case, PUBQR004 is an exception raised when there are no results for the query
# (why should that cause an exception??). We don't want to crash and burn just because
# the user doesn't have any BD requests in the system. But if it's anything else,
# raise it again -- that indicates a real problem.
if e.message.include? 'PUBAN003'
Rails.logger.error "MyAccount error: user could not be authenticated in Borrow Direct"
# BorrowDirect::Defaults.library_symbol = 'CORNELL'
# BorrowDirect::Defaults.find_item_patron_barcode = barcode
# BorrowDirect::Defaults.timeout = ENV['BORROW_DIRECT_TIMEOUT'].to_i || 30 # (seconds)
# BorrowDirect::Defaults.api_base = BorrowDirect::Defaults::PRODUCTION_API_BASE
# BorrowDirect::Defaults.api_key = ENV['BORROW_DIRECT_PROD_API_KEY']

begin
token = nil
response = CUL::FOLIO::Edge.authenticate(ENV['RESHARE_STATUS_URL'], ENV['RESHARE_TENANT'], ENV['RESHARE_USER'], ENV['RESHARE_PW'])
if response[:code] >= 300
Rails.logger.error "MyAccount error: Could not create a ReShare token for #{ENV['RESHARE_USER']}"
else
# TODO: Add better error handling. For now, BD is causing too many problems with flaky connections;
# we have to do something other than raise the errors here.
# raise unless e.message.include? 'PUBQR004'
end
token = response[:token]
end
# Note that the match/term query parameters are apparently undocumented in the APIs, but
# that's what ReShare is using internally to filter results in its apps.
url = "#{ENV['RESHARE_STATUS_URL']}/rs/patronrequests?match=patronIdentifier&term=#{netid}&perPage=1000&state.terminal==false"
headers = {
'X-Okapi-Tenant' => 'cornell',
'x-okapi-token' => token,
:accept => 'application/json',
}
response = RestClient.get(url, headers)
# TODO: check that response is in the proper form and there are no returned errors
items = JSON.parse(response)
items.each do |i|
Rails.logger.debug "mjc12testa: got BD results #{i['title']} with state #{i['state']['code']}"
end
rescue RestClient::Exception => e
# items = BorrowDirect::RequestQuery.new(barcode).requests('open')
# rescue BorrowDirect::Error => e
# # The Borrow Direct gem doesn't differentiate among all of the BD API error types.
# # In this case, PUBQR004 is an exception raised when there are no results for the query
# # (why should that cause an exception??). We don't want to crash and burn just because
# # the user doesn't have any BD requests in the system. But if it's anything else,
# # raise it again -- that indicates a real problem.
# if e.message.include? 'PUBAN003'
# Rails.logger.error "MyAccount error: user could not be authenticated in Borrow Direct"
# else
# # TODO: Add better error handling. For now, BD is causing too many problems with flaky connections;
# # we have to do something other than raise the errors here.
# # raise unless e.message.include? 'PUBQR004'
# end
items = []
Rails.logger.error "MyAccount error: Couldn\'t retrieve patron requests from ReShare (#{e})."
end
# Returns an array of BorrowDirect::RequestQuery::Item
cleaned_items = []
items.each do |item|
Rails.logger.debug "mjc12a: item data: HRID: #{item['hrid']} for patronIdentifier #{item['patronIdentifier']}"
Rails.logger.debug "mjc12a: state: #{item['state']['code']}, stage: #{item['state']['stage']}"

# HACK: This is a terrible way to obtain the item title. Unfortunately, this information isn't surfaced
# in the API response, but only provided as part of a marcxml description of the entire item record.
marc = XmlSimple.xml_in(item['bibRecord'])
f245 = marc['GetRecord'][0]['record'][0]['metadata'][0]['record'][0]['datafield'].find {|t| t['tag'] == '245'}
f245a = f245['subfield'].find { |sf| sf['code'] == 'a' }
f245b = f245['subfield'].find { |sf| sf['code'] == 'b' }
title = f245b ? "#{f245a['content']} #{f245b['content']}" : f245a['content']

# For the final item, we add a fake item ID number (iid) for compatibility with other items in the system
cleaned_items << { 'tl' => item.title, 'au' => '', 'system' => 'bd', 'status' => item.request_status, 'iid' => item.request_number }
# ReShare status *stages* are defined here:
# https://github.com/openlibraryenvironment/mod-rs/blob/master/service/src/main/groovy/org/olf/rs/statemodel/StatusStage.groovy
# and *states* are here:
# https://github.com/openlibraryenvironment/mod-rs/blob/master/doc/states.md
# I think we only need to worry about stage to distinguish between pending and available.
cleaned_items << {
'tl' => title,
'au' => '',
'system' => 'bd',
'status' => item['state']['code'],
'iid' => item['hrid'],
'lo' => item['pickupLocation']
}
end
session[netid + '_bd_items'] = cleaned_items
Rails.logger.debug "mjc12a: cleaned BD items: #{cleaned_items}"
render json: cleaned_items
end

Expand Down
27 changes: 10 additions & 17 deletions app/views/my_account/account/intro.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
%p Renew your books and check the status of your requests.
=link_to('Log in with your NetID or GuestID', '/myaccount', {:class => 'btn btn-danger btn-lg'})

%h3.mt-4 Interlibrary Loan
=link_to('Renew Interlibrary Loan items','https://cornell.hosts.atlas-sys.com/nonetid/home.html')

%h3.mt-4 Columbia University Borrowing Privileges
%p As a current student, staff or faculty member of Cornell University, you have the option to get a library borrowing card from Columbia University. This allows you to check out books from their collections when you visit Columbia.
%ul
%li
=link_to('More information about Columbia Library Borrowing Privileges', 'https://www.library.cornell.edu/services/borrow/2cul')
%li
=link_to('Apply for a Columbia Library card', 'https://www.library.cornell.edu/2cul-columbia-library-patron-borrowing-application')

%h3 Need assistance?
%h3.mt-5 Need assistance?
%p
Email the
=link_to('Library Public Services office', 'mailto:[email protected]')
or 
=link_to('Mann Library Circulation', 'mailto:[email protected]')
\.
Email your
=link_to('library', 'https://library.cornell.edu/libraries')
or
=link_to('[email protected]', 'mailto:[email protected]')
\.

%h3 Library fines
%p
The fine for recalled items is $3.00/day for every patron category. If unreturned, high cost and high demand items (such as laptops, equipment, reserves items) will be billed for replacement cost after two days. Regular items (such as books from the general circulating collection) will be billed for replacement cost after 27 days. When the billed amount reaches $300 for Cornell patrons (or $150 for others), the borrower’s access to the Library will be blocked until the item is returned.
2 changes: 1 addition & 1 deletion lib/my_account/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Engine < ::Rails::Engine
isolate_namespace MyAccount

config.autoload_paths += Dir["#{config.root}/spec/support"]

config.eager_load_paths += Dir["#{config.root}/lib"]
config.assets.paths << config.root.join('/engines/my_account/app/assets/javascripts')
config.assets.precompile << "my_account/application.js"
config.assets.precompile << "my_account/account.js.coffee"
Expand Down
11 changes: 11 additions & 0 deletions lib/my_account/reshare.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen-string-literal: true

# Interface to Project ReShare APIs
# APIs are documented here: https://3.basecamp.com/5319802/buckets/26606684/documents/5132521312
module Reshare
require 'rest-client'

def testrs
Rails.logger.debug "mjc12a: shazam!"
end
end
2 changes: 1 addition & 1 deletion lib/my_account/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MyAccount
VERSION = "2.1.6"
VERSION = "2.2.0"
end
5 changes: 5 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes - my-account

## v2.2.0
- Replace Borrow Direct with ReShare
- Eliminate reference to ilsapi.cgi script
- Update login page text (DISCOVERYACCESS-7838)

## v2.1.6
- Specify Rails 6.1.

Expand Down

0 comments on commit 30bedf6

Please sign in to comment.