Skip to content

Commit df9c37a

Browse files
committed
1 parent c658904 commit df9c37a

17 files changed

+181
-628
lines changed

app.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const express = require('express')
33
const esClient = require('./lib/elasticsearch/client')
44
const loadConfig = require('./lib/load-config')
55
const { preflightCheck } = require('./lib/preflight_check')
6-
const { loadNyplCoreData } = require('./lib/load_nypl_core')
76

87
const swaggerDocs = require('./swagger.v1.1.x.json')
98

@@ -21,7 +20,7 @@ app.set('trust proxy', 'loopback')
2120

2221
app.init = async () => {
2322
await loadConfig.loadConfig()
24-
await loadNyplCoreData()
23+
2524
preflightCheck()
2625

2726
// Load logger after running above to ensure we respect LOG_LEVEL if set

config/production.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NYPL_OAUTH_URL=https://isso.nypl.org/
1010
ENCRYPTED_NYPL_OAUTH_ID=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDMLKVUQA58B6vprNcAIBEIAoaz0lI9EL2M9NyTuEwT8JDmPBt6aXfMiFs027DEuwsCN0wS0qWeFL1g==
1111
ENCRYPTED_NYPL_OAUTH_SECRET=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAIcwgYQGCSqGSIb3DQEHBqB3MHUCAQAwcAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAyWz91LOP2YP5fg0q0CARCAQ9inO9SV1M8R0Pkkx84r7UdwlU1FxfXvIjk/z6Qs81KBAVELhby2iD5LawQyDrR9tjhuMbotS6QnydwwMR/p8+qJXHI=
1212

13-
NYPL_CORE_VERSION=v2.23
13+
NYPL_CORE_VERSION=v2.22
1414

1515
LOG_LEVEL=info
1616
FEATURES=on-site-edd

config/qa.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ NYPL_OAUTH_URL=https://isso.nypl.org/
1010
ENCRYPTED_NYPL_OAUTH_ID=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDMLKVUQA58B6vprNcAIBEIAoaz0lI9EL2M9NyTuEwT8JDmPBt6aXfMiFs027DEuwsCN0wS0qWeFL1g==
1111
ENCRYPTED_NYPL_OAUTH_SECRET=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAIcwgYQGCSqGSIb3DQEHBqB3MHUCAQAwcAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAyWz91LOP2YP5fg0q0CARCAQ9inO9SV1M8R0Pkkx84r7UdwlU1FxfXvIjk/z6Qs81KBAVELhby2iD5LawQyDrR9tjhuMbotS6QnydwwMR/p8+qJXHI=
1212

13-
NYPL_CORE_VERSION=v2.24
13+
NYPL_CORE_VERSION=v2.22
1414

1515
LOG_LEVEL=info
1616
FEATURES=on-site-edd

config/test.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ NYPL_OAUTH_URL=http://oauth.example.com
99
ENCRYPTED_NYPL_OAUTH_ID=encrypted-nypl-oauth-id
1010
ENCRYPTED_NYPL_OAUTH_SECRET=encrypted-nypl-oauth-id
1111

12-
NYPL_CORE_VERSION=v2.23
12+
NYPL_CORE_VERSION=v2.21
1313

1414
LOG_LEVEL=error
1515
FEATURES=on-site-edd

lib/available_delivery_location_types.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
const logger = require('./logger')
22
const { makeNyplDataApiClient } = require('./data-api-client')
3-
const nyplCore = require('./load_nypl_core')
43

54
class AvailableDeliveryLocationTypes {
65
static getScholarRoomByPatronId (patronID) {
76
// If patronID is falsy (i.e. patron is not logged in) they're just a Rearcher:
87
if (!patronID) return Promise.resolve(['Research'])
98

9+
const patronTypeMapping = require('@nypl/nypl-core-objects')('by-patron-type')
1010
return this._getPatronTypeOf(patronID)
1111
.then((patronType) => {
12-
if (this._isUnfamiliarPatronType(patronType)) {
12+
if (this._isUnfamiliarPatronType(patronTypeMapping, patronType)) {
1313
return
1414
}
15-
const patronTypeData = nyplCore.patronTypes()[patronType]
15+
const patronTypeData = patronTypeMapping[patronType]
1616
return patronTypeData.scholarRoom && patronTypeData.scholarRoom.code
1717
})
1818
}
@@ -38,8 +38,8 @@ class AvailableDeliveryLocationTypes {
3838
})
3939
}
4040

41-
static _isUnfamiliarPatronType (patronType) {
42-
if (!nyplCore.patronTypes()[patronType]) {
41+
static _isUnfamiliarPatronType (patronTypeMapping, patronType) {
42+
if (!patronTypeMapping[patronType]) {
4343
logger.info(`Found the Patron Type: ${patronType} is not recognizable.`)
4444
return true
4545
} else {
@@ -48,4 +48,8 @@ class AvailableDeliveryLocationTypes {
4848
}
4949
}
5050

51+
const patronTypeMapping = require('@nypl/nypl-core-objects')('by-patron-type')
52+
53+
AvailableDeliveryLocationTypes.patronTypeMapping = patronTypeMapping
54+
5155
module.exports = AvailableDeliveryLocationTypes

lib/delivery-locations-resolver.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
const { itemHasRecapHoldingLocation, barcodeFromItem } = require('./util')
22
const scsbClient = require('./scsb-client')
3-
const nyplCore = require('./load_nypl_core')
4-
3+
const recapCustomerCodes = require('@nypl/nypl-core-objects')('by-recap-customer-code')
4+
const sierraLocations = require('@nypl/nypl-core-objects')('by-sierra-location')
55
const logger = require('./logger')
66
const onsiteEddCriteria = require('../data/onsite-edd-criteria.json')
77
const { isItemNyplOwned } = require('./ownership_determination')
88

99
class DeliveryLocationsResolver {
1010
static nyplCoreLocation (locationCode) {
11-
return nyplCore.sierraLocations()[locationCode]
11+
return sierraLocations[locationCode]
1212
}
1313

1414
static requestableBasedOnHoldingLocation (item) {
15-
const locationCode = DeliveryLocationsResolver.extractLocationCode(item)
15+
const locationCode = this.extractLocationCode(item)
1616

1717
if (!DeliveryLocationsResolver.nyplCoreLocation(locationCode)) {
1818
logger.warn(`DeliveryLocationsResolver: Unrecognized holdingLocation for ${item.uri}: ${locationCode}`)
@@ -50,15 +50,21 @@ class DeliveryLocationsResolver {
5050

5151
// Fetch Sierra delivery locations by recap code
5252
static deliveryLocationsByRecapCustomerCode (customerCode) {
53-
if (nyplCore.recapCustomerCodes()[customerCode] && nyplCore.recapCustomerCodes()[customerCode].sierraDeliveryLocations) {
54-
return nyplCore.recapCustomerCodes()[customerCode].sierraDeliveryLocations
53+
if (recapCustomerCodes[customerCode] && recapCustomerCodes[customerCode].sierraDeliveryLocations) {
54+
return recapCustomerCodes[customerCode].sierraDeliveryLocations
5555
}
5656
}
5757

5858
// Fetch Sierra delivery locations by m2 customer code. Returns undefined if the m2 customer code is not requestable:
5959
static deliveryLocationsByM2CustomerCode (customerCode) {
60-
if (nyplCore.m2CustomerCodes()?.[customerCode]?.sierraDeliveryLocations) {
61-
const { sierraDeliveryLocations, requestable } = nyplCore.m2CustomerCodes()[customerCode]
60+
let m2CustomerCodes
61+
try {
62+
m2CustomerCodes = require('@nypl/nypl-core-objects')('by-m2-customer-code')
63+
} catch (e) {
64+
65+
}
66+
if (m2CustomerCodes && m2CustomerCodes[customerCode] && m2CustomerCodes[customerCode].sierraDeliveryLocations) {
67+
const { sierraDeliveryLocations, requestable } = m2CustomerCodes[customerCode]
6268
if (requestable) {
6369
return sierraDeliveryLocations
6470
} else return undefined
@@ -67,7 +73,7 @@ class DeliveryLocationsResolver {
6773

6874
// Determine eddRequestable by recap customer code:
6975
static __eddRequestableByCustomerCode (customerCode) {
70-
if (nyplCore.recapCustomerCodes()[customerCode]) return Boolean(nyplCore.recapCustomerCodes()[customerCode].eddRequestable)
76+
if (recapCustomerCodes[customerCode]) return Boolean(recapCustomerCodes[customerCode].eddRequestable)
7177
}
7278

7379
// Determine eddRequestable by on-site EDD requestability criteria (presumed on-site):
@@ -166,7 +172,7 @@ class DeliveryLocationsResolver {
166172
return {
167173
id: `loc:${location.code}`,
168174
label: location.label,
169-
sortPosition: DeliveryLocationsResolver.sortPosition(location)
175+
sortPosition: this.sortPosition(location)
170176
}
171177
})
172178
// Either way, sort deliveryLocation entries by name:
@@ -191,14 +197,14 @@ class DeliveryLocationsResolver {
191197
}
192198

193199
static attachRecapDeliveryInfo (item) {
194-
const info = DeliveryLocationsResolver.getRecapDeliveryInfo(item)
200+
const info = this.getRecapDeliveryInfo(item)
195201
item.eddRequestable = info.eddRequestable
196202
item.deliveryLocation = info.deliveryLocation
197203
return item
198204
}
199205

200206
static attachOnsiteDeliveryInfo (item) {
201-
const info = DeliveryLocationsResolver.getOnsiteDeliveryInfo(item)
207+
const info = this.getOnsiteDeliveryInfo(item)
202208
item.eddRequestable = info.eddRequestable
203209
item.deliveryLocation = info.deliveryLocation
204210
return item
@@ -212,15 +218,15 @@ class DeliveryLocationsResolver {
212218
const hasRecapCustomerCode = item.recapCustomerCode && item.recapCustomerCode[0]
213219
const nyplItem = isItemNyplOwned(item)
214220
if (!hasRecapCustomerCode) {
215-
const requestableBasedOnHoldingLocation = nyplItem ? DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item) : true
221+
const requestableBasedOnHoldingLocation = nyplItem ? this.requestableBasedOnHoldingLocation(item) : true
216222
// the length of the list of delivery locations is checked later to determine physical requestability
217223
// In case of an offsite item with no recap customer code, we want this to be based on holding location
218224
// so we put a placeholder '' in case it is requestable based on holding location
219225
deliveryLocation = requestableBasedOnHoldingLocation ? [''] : []
220226
eddRequestable = requestableBasedOnHoldingLocation
221-
} else if (!nyplItem || DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item)) {
222-
deliveryLocation = DeliveryLocationsResolver.deliveryLocationsByRecapCustomerCode(item.recapCustomerCode[0])
223-
eddRequestable = DeliveryLocationsResolver.__eddRequestableByCustomerCode(item.recapCustomerCode[0])
227+
} else if (!nyplItem || this.requestableBasedOnHoldingLocation(item)) {
228+
deliveryLocation = this.deliveryLocationsByRecapCustomerCode(item.recapCustomerCode[0])
229+
eddRequestable = this.__eddRequestableByCustomerCode(item.recapCustomerCode[0])
224230
} else {
225231
deliveryLocation = []
226232
eddRequestable = false
@@ -233,7 +239,7 @@ class DeliveryLocationsResolver {
233239
eddRequestable: false,
234240
deliveryLocation: []
235241
}
236-
const holdingLocationCode = DeliveryLocationsResolver.extractLocationCode(item)
242+
const holdingLocationCode = this.extractLocationCode(item)
237243
const sierraData = DeliveryLocationsResolver.nyplCoreLocation(holdingLocationCode)
238244
if (!sierraData) {
239245
// This case is mainly to satisfy a test which wants eddRequestable = false
@@ -243,15 +249,15 @@ class DeliveryLocationsResolver {
243249
}
244250
// if nypl core says it's unrequestable, it can still be eddRequestable,
245251
// but its definitely not phys requestable.
246-
deliveryInfo.eddRequestable = DeliveryLocationsResolver.eddRequestableByOnSiteCriteria(item)
247-
if (!DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item)) {
252+
deliveryInfo.eddRequestable = this.eddRequestableByOnSiteCriteria(item)
253+
if (!this.requestableBasedOnHoldingLocation(item)) {
248254
return deliveryInfo
249255
}
250256
// if nypl-core reports that a holding location's delivery locations
251257
// should be found by M2 code, but only if the item has an M2 customer code
252258
const deliverableToResolution = sierraData.deliverableToResolution
253259
if (deliverableToResolution === 'm2-customer-code' && item.m2CustomerCode && item.m2CustomerCode[0]) {
254-
deliveryInfo.deliveryLocation = DeliveryLocationsResolver.deliveryLocationsByM2CustomerCode(item.m2CustomerCode[0])
260+
deliveryInfo.deliveryLocation = this.deliveryLocationsByM2CustomerCode(item.m2CustomerCode[0])
255261
}
256262
// if no value, default to sierra location lookup
257263
if (!deliverableToResolution) {
@@ -275,15 +281,15 @@ class DeliveryLocationsResolver {
275281
}
276282

277283
/**
278-
* Given an array of items (ES hits), returns the same items with `eddRequestable` & `deliveryLocations`. We verify all recap customer codes because our indexed data may be stale.
284+
* Given an array of items (ES hits), returns the same items with `eddRequestable` & `deliveryLocations`
279285
*
280286
* @return Promise<Array<items>> A Promise that resolves and array of items, modified to include `eddRequestable` & `deliveryLocations`
281287
*/
282288
static attachDeliveryLocationsAndEddRequestability (items, scholarRoom) {
283289
// Extract ReCAP barcodes from items:
284-
const recapBarcodes = DeliveryLocationsResolver.extractRecapBarcodes(items)
290+
const recapBarcodes = this.extractRecapBarcodes(items)
285291
// Get a map from barcodes to ReCAP customercodes:
286-
return DeliveryLocationsResolver.__recapCustomerCodesByBarcodes(recapBarcodes)
292+
return this.__recapCustomerCodesByBarcodes(recapBarcodes)
287293
.then((barcodeToRecapCustomerCode) => {
288294
// Now map over items to affix deliveryLocations:
289295
return items.map((item) => {
@@ -292,15 +298,15 @@ class DeliveryLocationsResolver {
292298
item.recapCustomerCode = [barcodeToRecapCustomerCode[barcode]]
293299
// If recap has a customer code for this barcode, map it by recap cust code:
294300
if (item.recapCustomerCode[0]) {
295-
item = DeliveryLocationsResolver.attachRecapDeliveryInfo(item)
301+
item = this.attachRecapDeliveryInfo(item)
296302
// Otherwise, it's an onsite item
297303
} else {
298-
item = DeliveryLocationsResolver.attachOnsiteDeliveryInfo(item)
304+
item = this.attachOnsiteDeliveryInfo(item)
299305
}
300306
// Establish default for Electronic Document Delivery flag:
301307
item.eddRequestable = !!item.eddRequestable
302-
const filteredDeliveryLocationsWithScholarRoom = DeliveryLocationsResolver.filterLocations(item.deliveryLocation, scholarRoom)
303-
item.deliveryLocation = DeliveryLocationsResolver.formatLocations(filteredDeliveryLocationsWithScholarRoom)
308+
const filteredDeliveryLocationsWithScholarRoom = this.filterLocations(item.deliveryLocation, scholarRoom)
309+
item.deliveryLocation = this.formatLocations(filteredDeliveryLocationsWithScholarRoom)
304310
return item
305311
})
306312
})

lib/jsonld_serializers.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

3-
const nyplCore = require('./load_nypl_core')
3+
const locations = require('@nypl/nypl-core-objects')('by-sierra-location')
4+
const recordTypes = require('@nypl/nypl-core-objects')('by-record-types')
45
const NyplSourceMapper = require('research-catalog-indexer/lib/utils/nypl-source-mapper')
56

67
const util = require('./util.js')
@@ -286,7 +287,7 @@ class ResourceSerializer extends JsonLdItemSerializer {
286287
}
287288

288289
ResourceSerializer.getFormattedRecordType = function (recordTypeId) {
289-
const prefLabel = nyplCore.recordTypes()[recordTypeId]?.label
290+
const prefLabel = recordTypes[recordTypeId]?.label
290291
if (!prefLabel) return null
291292
return {
292293
'@id': recordTypeId,
@@ -498,10 +499,10 @@ class AggregationSerializer extends JsonLdItemSerializer {
498499
v.label = p[1]
499500
} else if (field === 'buildingLocation') {
500501
// Build buildingLocation agg labels from nypl-core:
501-
v.label = nyplCore.sierraLocations()[v.value]?.label
502+
v.label = locations[v.value]?.label
502503
} else if (field === 'recordType') {
503504
// Build recordType agg labels from nypl-core:
504-
v.label = nyplCore.recordTypes()[v.value]?.label
505+
v.label = recordTypes[v.value]?.label
505506
// Unknown recordType? Remove it:
506507
if (!v.label) return null
507508
} else {

lib/load_nypl_core.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/location_label_updater.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const nyplCore = require('./load_nypl_core')
1+
const sierraLocations = require('@nypl/nypl-core-objects')('by-sierra-location')
22

33
class LocationLabelUpdater {
44
constructor (responseReceived) {
@@ -10,22 +10,20 @@ class LocationLabelUpdater {
1010
const resp = this.elasticSearchResponse
1111
const updatedHits = resp.hits.hits.map((bib) => {
1212
// Update locations for items:
13-
const items = bib._source.items || []
14-
items.forEach((item) => {
13+
; (bib._source.items || []).forEach((item) => {
1514
if (item.holdingLocation && item.holdingLocation.length > 0) {
1615
item.holdingLocation = item.holdingLocation.map((loc) => {
17-
const nyplCoreEntry = nyplCore.sierraLocations()[loc.id.replace(/^loc:/, '')]
16+
const nyplCoreEntry = sierraLocations[loc.id.replace(/^loc:/, '')]
1817
if (nyplCoreEntry) loc.label = nyplCoreEntry.label
1918
return loc
2019
})
2120
}
2221
})
2322
// Update locations for holdings:
24-
const holdings = bib._source.holdings || []
25-
holdings.forEach((holding) => {
23+
; (bib._source.holdings || []).forEach((holding) => {
2624
if (holding.location && holding.location.length > 0) {
2725
holding.location = holding.location.map((loc) => {
28-
const nyplCoreEntry = nyplCore.sierraLocations()[loc.code.replace(/^loc:/, '')]
26+
const nyplCoreEntry = sierraLocations[loc.code.replace(/^loc:/, '')]
2927
if (nyplCoreEntry) loc.label = nyplCoreEntry.label
3028
return loc
3129
})

0 commit comments

Comments
 (0)