Skip to content

Commit 1ba7830

Browse files
Revert "Merge pull request #429 from NYPL/noref-nypl-core-objects-async"
This reverts commit c257110, reversing changes made to 9805396.
1 parent 5ad46d0 commit 1ba7830

12 files changed

+148
-104
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.23
13+
NYPL_CORE_VERSION=v2.22
1414

1515
LOG_LEVEL=info
1616
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: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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) {
@@ -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):

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)