Skip to content

Commit

Permalink
i3574: Thesis and numismatics aeon requests need specific parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sandbergja committed May 24, 2023
1 parent 57af283 commit bab6a7f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 13 deletions.
5 changes: 3 additions & 2 deletions app/components/aeon_request_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# ViewComponent that displays an aeon request button on the show page
class AeonRequestButtonComponent < RequestButtonComponent
def initialize(document:, holding: nil)
def initialize(document:, holding: nil, url_class: Requests::AeonUrl)
@document = document
@holding = holding
@url_class = url_class
end

def label
Expand All @@ -16,6 +17,6 @@ def tooltip
end

def url
Requests::AeonUrl.new(document: @document, holding: @holding).to_s
@url_class.new(document: @document, holding: @holding).to_s
end
end
37 changes: 37 additions & 0 deletions app/models/requests/non_alma_aeon_url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true
module Requests
# Create a URL that creates an aeon request
class NonAlmaAeonUrl < AeonUrl
private

def aeon_basic_params
super.merge({
Action: 10,
Form: 21,
ItemTitle: aeon_title.truncate(247),
ItemAuthor: author,
ItemDate: @document[:pub_date_start_sort],
ItemVolume: @holding[:location],
genre:
}).compact
end

def aeon_title
"#{@document.first(:title_display)}#{title_genre}"
end

## Don T requested this be appended when present
def title_genre
" [ #{@document.first(:form_genre_display)} ]" unless @document[:form_genre_display].nil?
end

def genre
return 'numismatics' if holding[:call_number]&.downcase&.start_with?('coin')
'thesis'
end

def author
@document[:author_display]&.join(" AND ")
end
end
end
13 changes: 3 additions & 10 deletions app/services/physical_holdings_markup_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ def request_placeholder(adapter, holding_id, location_rules, holding)
# so that it will be "/request/#{doc_id}", where doc_id can be either the record page mms_id or the host id(s) if they exist.
doc_id = doc_id(holding)
view_base = ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil)
link = if display_direct_aeon_link?(location_rules, holding_id)
link = if holding_id == 'thesis' || self.class.numismatics?(holding_id)
AeonRequestButtonComponent.new(document: adapter.document, holding: { doc_id: holding }, url_class: Requests::NonAlmaAeonUrl).render_in(view_base)
elsif aeon_location?(location_rules)
AeonRequestButtonComponent.new(document: adapter.document, holding: { doc_id: holding }).render_in(view_base)
elsif self.class.scsb_location?(location_rules)
RequestButtonComponent.new(doc_id:, location: location_rules, holding:).render_in(view_base)
Expand All @@ -292,15 +294,6 @@ def request_placeholder(adapter, holding_id, location_rules, holding)
markup
end

def display_direct_aeon_link?(location_rules, holding_id)
return true if aeon_location?(location_rules)

# If it is not from SCSB or alma, it must be aeon
return true unless self.class.scsb_location?(location_rules) || adapter.alma_holding?(holding_id)

false
end

def request_url(doc_id:, aeon:, holding_id: nil)
query = if holding_id
{ mfhd: holding_id, aeon: aeon.to_s }.to_query
Expand Down
44 changes: 44 additions & 0 deletions spec/models/requests/non_alma_aeon_url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Requests::NonAlmaAeonUrl do
let(:holdings) do
{ "thesis" => {} }
end
let(:document) do
SolrDocument.new({
id: '9999999',
title_display: 'A book of poems',
form_genre_display: ['Poetry'],
author_display: ['Person 1', 'Person 2'],
holdings_1display: holdings.to_json.to_s
})
end
before do
stub_holding_locations
end
subject { described_class.new(document:, holding: holdings).to_s }
it 'uses Action 10' do
expect(subject).to include('Action=10')
end
it 'uses form 21' do
expect(subject).to include('Form=21')
end
it 'provides a title with the genre appended' do
expect(subject).to include('ItemTitle=A+book+of+poems+%5B+Poetry+%5D')
end
it 'concatenates a list of authors from the author_display field' do
expect(subject).to include('ItemAuthor=Person+1+AND+Person+2')
end
it 'defaults to the thesis genre' do
expect(subject).to include('genre=thesis')
end
context 'when the holdings has a coin call number' do
let(:holdings) do
{ "numismatics" => { "call_number": "Coin 11362" } }
end
it 'includes the numismatics genre' do
expect(subject).to include('genre=numismatics')
end
end
end
3 changes: 2 additions & 1 deletion spec/services/physical_holdings_markup_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,8 @@

def mock_solr_document
allow_any_instance_of(SolrDocument).to receive(:to_ctx).and_return(OpenURL::ContextObject.new)
allow(document).to receive(:[]).and_return('data')
allow(document).to receive(:[]).and_return(['data'])
allow(document).to receive(:to_ctx).and_return(OpenURL::ContextObject.new)
allow(document).to receive(:holdings_all_display).and_return({ 'host_id' => { 'items' => [{ 'barcode' => 'host123' }] } })
allow(document).to receive(:first)
end

0 comments on commit bab6a7f

Please sign in to comment.