Skip to content

Commit

Permalink
Merge pull request #122 from cul-it/dev
Browse files Browse the repository at this point in the history
Merge changes for v2.0.2
  • Loading branch information
Baroquem authored May 29, 2018
2 parents 90bc739 + c1b092f commit 77d1672
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def magic_request target=''
# Items are keyed by the associated holding record
holdings.each do |h, item_array|
item_array.each do |i|
items << Item.new(h, i)
items << Item.new(h, i, JSON.parse(@document['holdings_json']))
end
end
@ti = work_metadata.title
Expand Down Expand Up @@ -146,6 +146,16 @@ def magic_request target=''
sorted_methods = DeliveryMethod.sorted_methods(options)
fastest_method = sorted_methods[:fastest]
@alternate_methods = sorted_methods[:alternate]

# Add PDA if appropriate
pda_data = PDA.pda_data(@document)
if pda_data.present?
@alternate_methods.unshift fastest_method
fastest_method = {:method => PDA}.merge(pda_data)
end

Rails.logger.debug "mjc12test: fastest #{fastest_method}"
Rails.logger.debug "mjc12test: alternate #{@alternate_methods}"
# If no other methods are found (i.e., there are no item records to process, such as for
# an on-order record), ask a librarian
fastest_method[:method] ||= AskLibrarian
Expand Down
39 changes: 5 additions & 34 deletions app/models/blacklight_cornell_requests/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,7 @@ def self.time(options = {})
end

def self.available?(item, patron)
# L2L is available for both Cornell and Guest patrons when:
# (1) the status is NOT_CHARGED, and
# (2) loan type is regular or (day AND not in the list of no L2L day loan types)
if status == STATUSES[:not_charged]
return regular_loan?(loan_type) ||
(day_loan?(loan_type) && !no_l2l_day_loan_types?(loan_type))
else
return false
end
# Disabled for now - using the l2l_available? method in RequestController instead
end
end

Expand Down Expand Up @@ -219,19 +211,7 @@ def self.time(options = {})
end

def self.available?(item, patron)
# Items are available for hold under the following conditions:
# (1) status is charged and loan type is regular or day, OR
# (2) type is regular, patron type is cornell, and status is in transit
# TODO: ask Joanne about that condition. Should it matter for transit status
# whether patron is cornell-affiliated or not?
if regular_loan?(loan_type)
return true if status == STATUSES[:charged]
return patron_type == 'cornell' &&
(status == STATUSES[:in_transit_discharged] ||
status == STATUSES[:in_transit_on_hold])
elsif day_loan?(loan_type)
return status == STATUSES[:charged]
end
# Disabled for now - using the hold_available? method in RequestController instead
end

end
Expand All @@ -253,22 +233,13 @@ def self.time(options = {})
end

def self.available?(item, patron)
# Items are available for recall under the following conditions:
# (1) patron is cornell-affililated, loan type is regular, and
# status is charged or in-transit-discharged or in-transit-on-hold
if patron_type == 'cornell' && regular_loan?(loan_type)
return (status == STATUSES[:charged] ||
status == STATUSES[:in_transit_discharged] ||
status == STATUSES[:in_transit_on_hold])
else
return false
end
# Disabled for now - using the recall_available? method in RequestController instead
end
end

class PDA < DeliveryMethod

TemplateName = ''
TemplateName = 'pda'

def self.description
'Patron-driven acquisition'
Expand All @@ -279,7 +250,7 @@ def self.time(options = {})
end

def self.available?(item, patron)

item.nil?
end

def self.pda_data(solrdoc)
Expand Down
3 changes: 2 additions & 1 deletion app/models/blacklight_cornell_requests/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module BlacklightCornellRequests
class Item

attr_reader :id, :holding_id, :location, :type, :status, :circ_group
attr_reader :copy_number, :call_number, :enum_parts
attr_reader :copy_number, :call_number, :enum_parts, :excluded_locations

# Basic initializer
#
Expand All @@ -31,6 +31,7 @@ def initialize(holding_id, item_data, holdings_data = nil)
if holdings_data.present?
@call_number = holdings_data[holding_id]['call']
end
@excluded_locations = RequestPolicy.excluded_locations(@circ_group)
end

# Enumeration is the single-string concatenation of three fields
Expand Down
40 changes: 21 additions & 19 deletions app/models/blacklight_cornell_requests/r3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def initialize(bibid, netid, document)

def get_items
items = []
holdings = JSON.parse(@document['items_json'])
holding_json = JSON.parse(@document['holdings_json'])
holdings = @document['items_json'] && JSON.parse(@document['items_json'])
holding_json = @document['holdings_json'] && JSON.parse(@document['holdings_json'])
# Items are keyed by the associated holding record
holdings.each do |h, item_array|
holdings && holdings.each do |h, item_array|
item_array.each do |i|
items << Item.new(h, i, holding_json)
end
Expand Down Expand Up @@ -54,24 +54,26 @@ def report(item_id = '')
puts "First item:"
puts items[0].inspect
linebreak
puts "Voyager delivery methods valid for this item:"
puts RequestPolicy.policy(items[0].circ_group, @requester.group, items[0].type['id'])
linebreak
puts "Individual item report:"
puts "ID\t\tStatus\tAvailable\tL2L\tHold\tRecall\n"
policy_hash = {}
items.each do |i|
rp = { }
policy_key = "#{i.circ_group}-#{@requester.group}-#{i.type['id']}"
if policy_hash[policy_key]
rp = policy_hash[policy_key]
else
rp = RequestPolicy.policy(i.circ_group, @requester.group, i.type['id'])
policy_hash[policy_key] = rp
if items[0]
puts "Voyager delivery methods valid for this item:"
puts RequestPolicy.policy(items[0].circ_group, @requester.group, items[0].type['id'])
linebreak
puts "Individual item report:"
puts "ID\t\tStatus\tAvailable\tL2L\tHold\tRecall\n"
policy_hash = {}
items.each do |i|
rp = { }
policy_key = "#{i.circ_group}-#{@requester.group}-#{i.type['id']}"
if policy_hash[policy_key]
rp = policy_hash[policy_key]
else
rp = RequestPolicy.policy(i.circ_group, @requester.group, i.type['id'])
policy_hash[policy_key] = rp
end
puts "#{i.id}\t#{i.status['code'].keys[0]}\t#{i.status['available']}\t\t#{l2l_available?(i, rp)}\t#{hold_available?(i, rp)}\t#{recall_available?(i, rp)}"
end
puts "#{i.id}\t#{i.status['code'].keys[0]}\t#{i.status['available']}\t\t#{l2l_available?(i, rp)}\t#{hold_available?(i, rp)}\t#{recall_available?(i, rp)}"
linebreak
end
linebreak
end

def linebreak
Expand Down
21 changes: 21 additions & 0 deletions app/models/blacklight_cornell_requests/request_policy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'oci8'
module BlacklightCornellRequests
# @author Matt Connolly

Expand Down Expand Up @@ -63,6 +64,26 @@ def self.default_policy(circ_group, item_type)

end

def self.excluded_locations(circ_group)
connection = nil
begin
connection = OCI8.new(ENV['ORACLE_RDONLY_PASSWORD'], ENV['ORACLE_RDONLY_PASSWORD'], "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + ENV['ORACLE_HOST'] + ")(PORT=1521))(CONNECT_DATA=(SID=" + ENV['ORACLE_SID'] + ")))")
cursor = connection.parse('select location_id from circ_policy_locs where circ_group_id=:circgroup')
cursor.bind_param('circgroup', circ_group)
cursor.exec
records = []
while r = cursor.fetch()
records << r[0]
end

return records

rescue OCIError
Rails.logger.debug "mjc12test: ERROR - #{$!}"
return nil
end
end

end

end
10 changes: 3 additions & 7 deletions app/views/shared/_l2lac.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
.radio
%label{ :for => "copy-#{i.id}"}
-if (@items.length == 1)
%input(id="copy-#{i.id}" class="copy-select" type="radio" name="holding_id" value="#{i.id}" data-exclude-location="" checked)
%input(id="copy-#{i.id}" class="copy-select" type="radio" name="holding_id" value="#{i.id}" data-exclude-location="#{i.excluded_locations}" checked)
-else
%input(id="copy-#{i.id}" class="copy-select" type="radio" name="holding_id" value="#{i.id}" data-exclude-location="")
%input(id="copy-#{i.id}" class="copy-select" type="radio" name="holding_id" value="#{i.id}" data-exclude-location="#{i.excluded_locations}")
= "#{i.location['name']} #{i.enumeration} "
- if i.copy_number
= "c. #{i.copy_number} "
%span.copy-callnumber
= i.call_number
-if i.enumeration
%span.copy-chron.label
= i.enumeration
= " - #{i.location['name']}"
= " - #{i.call_number}"
2 changes: 1 addition & 1 deletion lib/blacklight_cornell_requests/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BlacklightCornellRequests
VERSION = "2.0.1"
VERSION = "2.0.2"
end
7 changes: 7 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Notes - blacklight-cornell-requests

## v2.0.2

### Bug fixes
- Delivery locations are now properly excluded in pickup location list (DISCOVERYACCESS-4241; also fixes DISCOVERYACCESS-4235)
- PDA is offered as an option when appropriate (DISCOVERYACCESS-4231)
- Fixed formatting of copy number (DISCOVERYACCESS-4242)

## v2.0.1
- Fixed a bug causing the volume select box to appear when it shouldn't (DISCOVERYACCESS-4224)

Expand Down

0 comments on commit 77d1672

Please sign in to comment.