Skip to content

Commit 7ee942a

Browse files
Merge pull request #466 from NYPL/SCC-4549/phys-override-spec
Scc 4549/phys override spec
2 parents dab3106 + bf512bc commit 7ee942a

File tree

3 files changed

+60
-58
lines changed

3 files changed

+60
-58
lines changed

lib/requestability_resolver.js

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,73 @@ class RequestabilityResolver {
77
static fixItemRequestability (elasticSearchResponse) {
88
elasticSearchResponse.hits.hits
99
.forEach((hit) => {
10-
const parentBibHasFindingAid = !!hit._source.supplementaryContent?.find((el) => el.label.toLowerCase() === 'finding aid')
1110
hit._source.items = hit._source.items.map((item) => {
1211
if (item.electronicLocator) return item
13-
let deliveryInfo
1412
const itemIsInRecap = isInRecap(item)
15-
let physRequestableCriteria
16-
const hasRecapCustomerCode = item.recapCustomerCode?.[0]
17-
if (itemIsInRecap) {
18-
// recap items missing codes should default to true for phys and edd
19-
// requestable, unless it has a non-requestable holding location
20-
deliveryInfo = DeliveryLocationsResolver.getRecapDeliveryInfo(item)
21-
physRequestableCriteria = hasRecapCustomerCode
22-
? `${(deliveryInfo.deliveryLocation?.length) || 0} delivery locations.`
23-
: 'Missing customer code'
24-
} else if (!itemIsInRecap) {
25-
deliveryInfo = DeliveryLocationsResolver.getOnsiteDeliveryInfo(item)
26-
physRequestableCriteria = `${(deliveryInfo.deliveryLocation?.length) || 0} delivery locations.`
27-
}
28-
item.specRequestable = this.buildSpecRequestable(item, parentBibHasFindingAid)
29-
item.physRequestable = !!deliveryInfo.deliveryLocation?.length
13+
const deliveryInfo = itemIsInRecap
14+
? DeliveryLocationsResolver.getRecapDeliveryInfo(item)
15+
: DeliveryLocationsResolver.getOnsiteDeliveryInfo(item)
16+
const numDeliveryLocations = deliveryInfo.deliveryLocation?.length
17+
item.specRequestable = this.buildSpecRequestable(item)
18+
item.physRequestable = this.buildPhysRequestable(item, numDeliveryLocations)
3019
item.eddRequestable = !!deliveryInfo.eddRequestable && !item.specRequestable
31-
// items without barcodes should not be requestable
32-
const hasBarcode = (item.identifier || []).some((identifier) => /^(urn|bf):[bB]arcode:\w+/.test(identifier))
33-
if (isItemNyplOwned(item) && !hasBarcode) {
34-
physRequestableCriteria = 'NYPL item missing barcode'
35-
item.physRequestable = false
36-
}
37-
if (item.specRequestable && item.physRequestable) {
38-
item.physRequestable = false
39-
physRequestableCriteria = 'specRequestable overrides physRequestable location'
40-
}
41-
logger.debug(`item ${item.uri}: `, { physRequestable: item.physRequestable, physRequestableCriteria })
4220
item.requestable = [item.eddRequestable || item.physRequestable || item.specRequestable]
4321
return item
4422
})
4523
})
4624
return elasticSearchResponse
4725
}
4826

49-
static buildSpecRequestable (item, parentBibHasFindingAid) {
27+
static buildPhysRequestable (item, numDeliveryLocations) {
28+
let physRequestableCriteria
29+
let physRequestable
30+
const hasRecapCustomerCode = item.recapCustomerCode?.[0]
31+
const itemIsInRecapMissingRecapCustomerCode = isInRecap(item) && !hasRecapCustomerCode
32+
// items without barcodes should not be requestable
33+
const hasBarcode = (item.identifier || []).some((identifier) => /^(urn|bf):[bB]arcode:\w+/.test(identifier))
34+
if (isItemNyplOwned(item) && !hasBarcode) {
35+
physRequestable = false
36+
physRequestableCriteria = 'NYPL item missing barcode'
37+
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
38+
return physRequestable
39+
}
40+
if (isItemNyplOwned(item) && !DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item)) {
41+
physRequestableCriteria = 'Unrequestable holding location'
42+
physRequestable = false
43+
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
44+
return physRequestable
45+
}
46+
if (itemIsInRecapMissingRecapCustomerCode) {
47+
// recap items missing codes should default to true for phys and edd
48+
// requestable, if it has a requestable holding location.
49+
physRequestable = true
50+
physRequestableCriteria = 'Missing customer code'
51+
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
52+
return physRequestable
53+
}
54+
if (numDeliveryLocations === 0) {
55+
physRequestableCriteria = 'No delivery locations.'
56+
physRequestable = false
57+
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
58+
return physRequestable
59+
}
60+
if (numDeliveryLocations > 0) {
61+
physRequestableCriteria = `${numDeliveryLocations} delivery locations.`
62+
physRequestable = true
63+
this.logPhysRequestableInfo(physRequestable, physRequestableCriteria, item.uri)
64+
return physRequestable
65+
}
66+
}
67+
68+
static logPhysRequestableInfo (physRequestable, criteria, uri) {
69+
logger.debug(`item ${uri}: ${{ physRequestable, criteria }}`)
70+
}
71+
72+
static buildSpecRequestable (item) {
5073
const holdingLocation = DeliveryLocationsResolver.extractLocationCode(item)
5174
const nyplCoreLocation = DeliveryLocationsResolver.nyplCoreLocation(holdingLocation)
5275
const isSpecialCollectionsOnlyAccessType = !!(nyplCoreLocation?.collectionAccessType === 'special')
53-
return !!item.aeonUrl || parentBibHasFindingAid || isSpecialCollectionsOnlyAccessType
76+
return !!item.aeonUrl || isSpecialCollectionsOnlyAccessType
5477
}
5578
}
5679

test/fixtures/no_recap_response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ exports.fakeElasticSearchResponseNyplItem = () => {
305305
holdingLocation: [
306306
{
307307
label: 'OFFSITE - Request in Advance',
308-
id: 'loc:dya0f'
308+
id: 'loc:rcpt8'
309309
}
310310
],
311311
status_packed: [

test/requestability_resolver.test.js

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ const RequestabilityResolver = require('../lib/requestability_resolver')
22
const elasticSearchResponse = require('./fixtures/elastic_search_response.js')
33
const specRequestableElasticSearchResponse = require('./fixtures/specRequestable/specRequestable-es-response.js')
44
const eddElasticSearchResponse = require('./fixtures/edd_elastic_search_response')
5-
const findingAidElasticSearchResponse = require('./fixtures/specRequestable/findingAid-es-response.js')
65
const noBarcodeResponse = require('./fixtures/no_barcode_es_response')
76
const noRecapResponse = require('./fixtures/no_recap_response')
8-
const physRequestableOverride = require('./fixtures/specRequestable/phys-requestable-override.js')
9-
const DeliveryLocationsResolver = require('../lib/delivery-locations-resolver.js')
107

118
describe('RequestabilityResolver', () => {
129
describe('fixItemRequestability', function () {
@@ -19,17 +16,6 @@ describe('RequestabilityResolver', () => {
1916
const resp = RequestabilityResolver.fixItemRequestability(noBarcode)
2017
expect(resp.hits.hits[0]._source.items.every((item) => item.physRequestable === false)).to.equal(true)
2118
})
22-
it('specRequestable overrides physRequestable, when items have phys requestable holding location', () => {
23-
const esResponseItems = physRequestableOverride.hits.hits[0]._source.items
24-
const isPhysRequestable = (item) => !!item.deliveryLocation.length
25-
const resp = RequestabilityResolver.fixItemRequestability(physRequestableOverride)
26-
// verify that items are phys requestable based on location...
27-
expect(esResponseItems
28-
.map(DeliveryLocationsResolver.getOnsiteDeliveryInfo)
29-
.every(isPhysRequestable)).to.equal(true)
30-
// ...but overridden by specRequestability
31-
expect(resp.hits.hits[0]._source.items.every((item) => !item.physRequestable && item.specRequestable)).to.equal(true)
32-
})
3319

3420
it('will set requestable to false for an item not found in ReCAP', function () {
3521
const indexedButNotAvailableInSCSBURI = 'i22566485'
@@ -197,13 +183,6 @@ describe('RequestabilityResolver', () => {
197183
expect(specRequestableItem.specRequestable).to.equal(true)
198184
})
199185

200-
it('marks items as specRequestable when there is a finding aid on the parent bib', function () {
201-
const response = RequestabilityResolver.fixItemRequestability(findingAidElasticSearchResponse())
202-
203-
const items = response.hits.hits[0]._source.items
204-
expect(items.every((item) => item.specRequestable)).to.equal(true)
205-
})
206-
207186
it('leaves item as specRequestable false when there is no finding aid, aeon url, or special holding location', () => {
208187
const response = RequestabilityResolver.fixItemRequestability(elasticSearchResponse.fakeElasticSearchResponseNyplItem())
209188
const items = response.hits.hits[0]._source.items
@@ -248,16 +227,16 @@ describe('RequestabilityResolver', () => {
248227

249228
it('marks edd and physical requestability correctly', function () {
250229
const items = resolved.hits.hits[0]._source.items
251-
const firstItem = items.find((item) => {
230+
const requestableLocationNoRecapCode = items.find((item) => {
252231
return item.uri === 'i102836649'
253232
})
254-
const secondItem = items.find((item) => {
233+
const nonRequestableLocationNoRecapCode = items.find((item) => {
255234
return item.uri === 'i102836659'
256235
})
257-
expect(firstItem.physRequestable).to.equal(true)
258-
expect(firstItem.eddRequestable).to.equal(true)
259-
expect(secondItem.physRequestable).to.equal(false)
260-
expect(secondItem.eddRequestable).to.equal(false)
236+
expect(requestableLocationNoRecapCode.physRequestable).to.equal(true)
237+
expect(requestableLocationNoRecapCode.eddRequestable).to.equal(true)
238+
expect(nonRequestableLocationNoRecapCode.physRequestable).to.equal(false)
239+
expect(nonRequestableLocationNoRecapCode.eddRequestable).to.equal(false)
261240
})
262241
})
263242
})

0 commit comments

Comments
 (0)