Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const express = require('express')
const esClient = require('./lib/elasticsearch/client')
const loadConfig = require('./lib/load-config')
const { preflightCheck } = require('./lib/preflight_check')
const { loadNyplCoreData } = require('./lib/load_nypl_core')

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

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

app.init = async () => {
await loadConfig.loadConfig()
await loadNyplCoreData()

preflightCheck()

// Load logger after running above to ensure we respect LOG_LEVEL if set
Expand Down
2 changes: 1 addition & 1 deletion config/production.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NYPL_OAUTH_URL=https://isso.nypl.org/
ENCRYPTED_NYPL_OAUTH_ID=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDMLKVUQA58B6vprNcAIBEIAoaz0lI9EL2M9NyTuEwT8JDmPBt6aXfMiFs027DEuwsCN0wS0qWeFL1g==
ENCRYPTED_NYPL_OAUTH_SECRET=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAIcwgYQGCSqGSIb3DQEHBqB3MHUCAQAwcAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAyWz91LOP2YP5fg0q0CARCAQ9inO9SV1M8R0Pkkx84r7UdwlU1FxfXvIjk/z6Qs81KBAVELhby2iD5LawQyDrR9tjhuMbotS6QnydwwMR/p8+qJXHI=

NYPL_CORE_VERSION=v2.23
NYPL_CORE_VERSION=v2.22

LOG_LEVEL=info
FEATURES=on-site-edd
Expand Down
2 changes: 1 addition & 1 deletion config/qa.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NYPL_OAUTH_URL=https://isso.nypl.org/
ENCRYPTED_NYPL_OAUTH_ID=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDMLKVUQA58B6vprNcAIBEIAoaz0lI9EL2M9NyTuEwT8JDmPBt6aXfMiFs027DEuwsCN0wS0qWeFL1g==
ENCRYPTED_NYPL_OAUTH_SECRET=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAIcwgYQGCSqGSIb3DQEHBqB3MHUCAQAwcAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAyWz91LOP2YP5fg0q0CARCAQ9inO9SV1M8R0Pkkx84r7UdwlU1FxfXvIjk/z6Qs81KBAVELhby2iD5LawQyDrR9tjhuMbotS6QnydwwMR/p8+qJXHI=

NYPL_CORE_VERSION=v2.24
NYPL_CORE_VERSION=v2.22

LOG_LEVEL=info
FEATURES=on-site-edd
Expand Down
2 changes: 1 addition & 1 deletion config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NYPL_OAUTH_URL=http://oauth.example.com
ENCRYPTED_NYPL_OAUTH_ID=encrypted-nypl-oauth-id
ENCRYPTED_NYPL_OAUTH_SECRET=encrypted-nypl-oauth-id

NYPL_CORE_VERSION=v2.23
NYPL_CORE_VERSION=v2.21

LOG_LEVEL=error
FEATURES=on-site-edd
Expand Down
14 changes: 9 additions & 5 deletions lib/available_delivery_location_types.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const logger = require('./logger')
const { makeNyplDataApiClient } = require('./data-api-client')
const nyplCore = require('./load_nypl_core')

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

const patronTypeMapping = require('@nypl/nypl-core-objects')('by-patron-type')
return this._getPatronTypeOf(patronID)
.then((patronType) => {
if (this._isUnfamiliarPatronType(patronType)) {
if (this._isUnfamiliarPatronType(patronTypeMapping, patronType)) {
return
}
const patronTypeData = nyplCore.patronTypes()[patronType]
const patronTypeData = patronTypeMapping[patronType]
return patronTypeData.scholarRoom && patronTypeData.scholarRoom.code
})
}
Expand All @@ -38,8 +38,8 @@ class AvailableDeliveryLocationTypes {
})
}

static _isUnfamiliarPatronType (patronType) {
if (!nyplCore.patronTypes()[patronType]) {
static _isUnfamiliarPatronType (patronTypeMapping, patronType) {
if (!patronTypeMapping[patronType]) {
logger.info(`Found the Patron Type: ${patronType} is not recognizable.`)
return true
} else {
Expand All @@ -48,4 +48,8 @@ class AvailableDeliveryLocationTypes {
}
}

const patronTypeMapping = require('@nypl/nypl-core-objects')('by-patron-type')

AvailableDeliveryLocationTypes.patronTypeMapping = patronTypeMapping

module.exports = AvailableDeliveryLocationTypes
60 changes: 33 additions & 27 deletions lib/delivery-locations-resolver.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const { itemHasRecapHoldingLocation, barcodeFromItem } = require('./util')
const scsbClient = require('./scsb-client')
const nyplCore = require('./load_nypl_core')

const recapCustomerCodes = require('@nypl/nypl-core-objects')('by-recap-customer-code')
const sierraLocations = require('@nypl/nypl-core-objects')('by-sierra-location')
const logger = require('./logger')
const onsiteEddCriteria = require('../data/onsite-edd-criteria.json')
const { isItemNyplOwned } = require('./ownership_determination')

class DeliveryLocationsResolver {
static nyplCoreLocation (locationCode) {
return nyplCore.sierraLocations()[locationCode]
return sierraLocations[locationCode]
}

static requestableBasedOnHoldingLocation (item) {
const locationCode = DeliveryLocationsResolver.extractLocationCode(item)
const locationCode = this.extractLocationCode(item)

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

// Fetch Sierra delivery locations by recap code
static deliveryLocationsByRecapCustomerCode (customerCode) {
if (nyplCore.recapCustomerCodes()[customerCode] && nyplCore.recapCustomerCodes()[customerCode].sierraDeliveryLocations) {
return nyplCore.recapCustomerCodes()[customerCode].sierraDeliveryLocations
if (recapCustomerCodes[customerCode] && recapCustomerCodes[customerCode].sierraDeliveryLocations) {
return recapCustomerCodes[customerCode].sierraDeliveryLocations
}
}

// Fetch Sierra delivery locations by m2 customer code. Returns undefined if the m2 customer code is not requestable:
static deliveryLocationsByM2CustomerCode (customerCode) {
if (nyplCore.m2CustomerCodes()?.[customerCode]?.sierraDeliveryLocations) {
const { sierraDeliveryLocations, requestable } = nyplCore.m2CustomerCodes()[customerCode]
let m2CustomerCodes
try {
m2CustomerCodes = require('@nypl/nypl-core-objects')('by-m2-customer-code')
} catch (e) {

}
if (m2CustomerCodes && m2CustomerCodes[customerCode] && m2CustomerCodes[customerCode].sierraDeliveryLocations) {
const { sierraDeliveryLocations, requestable } = m2CustomerCodes[customerCode]
if (requestable) {
return sierraDeliveryLocations
} else return undefined
Expand All @@ -67,7 +73,7 @@ class DeliveryLocationsResolver {

// Determine eddRequestable by recap customer code:
static __eddRequestableByCustomerCode (customerCode) {
if (nyplCore.recapCustomerCodes()[customerCode]) return Boolean(nyplCore.recapCustomerCodes()[customerCode].eddRequestable)
if (recapCustomerCodes[customerCode]) return Boolean(recapCustomerCodes[customerCode].eddRequestable)
}

// Determine eddRequestable by on-site EDD requestability criteria (presumed on-site):
Expand Down Expand Up @@ -166,7 +172,7 @@ class DeliveryLocationsResolver {
return {
id: `loc:${location.code}`,
label: location.label,
sortPosition: DeliveryLocationsResolver.sortPosition(location)
sortPosition: this.sortPosition(location)
}
})
// Either way, sort deliveryLocation entries by name:
Expand All @@ -191,14 +197,14 @@ class DeliveryLocationsResolver {
}

static attachRecapDeliveryInfo (item) {
const info = DeliveryLocationsResolver.getRecapDeliveryInfo(item)
const info = this.getRecapDeliveryInfo(item)
item.eddRequestable = info.eddRequestable
item.deliveryLocation = info.deliveryLocation
return item
}

static attachOnsiteDeliveryInfo (item) {
const info = DeliveryLocationsResolver.getOnsiteDeliveryInfo(item)
const info = this.getOnsiteDeliveryInfo(item)
item.eddRequestable = info.eddRequestable
item.deliveryLocation = info.deliveryLocation
return item
Expand All @@ -212,15 +218,15 @@ class DeliveryLocationsResolver {
const hasRecapCustomerCode = item.recapCustomerCode && item.recapCustomerCode[0]
const nyplItem = isItemNyplOwned(item)
if (!hasRecapCustomerCode) {
const requestableBasedOnHoldingLocation = nyplItem ? DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item) : true
const requestableBasedOnHoldingLocation = nyplItem ? this.requestableBasedOnHoldingLocation(item) : true
// the length of the list of delivery locations is checked later to determine physical requestability
// In case of an offsite item with no recap customer code, we want this to be based on holding location
// so we put a placeholder '' in case it is requestable based on holding location
deliveryLocation = requestableBasedOnHoldingLocation ? [''] : []
eddRequestable = requestableBasedOnHoldingLocation
} else if (!nyplItem || DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item)) {
deliveryLocation = DeliveryLocationsResolver.deliveryLocationsByRecapCustomerCode(item.recapCustomerCode[0])
eddRequestable = DeliveryLocationsResolver.__eddRequestableByCustomerCode(item.recapCustomerCode[0])
} else if (!nyplItem || this.requestableBasedOnHoldingLocation(item)) {
deliveryLocation = this.deliveryLocationsByRecapCustomerCode(item.recapCustomerCode[0])
eddRequestable = this.__eddRequestableByCustomerCode(item.recapCustomerCode[0])
} else {
deliveryLocation = []
eddRequestable = false
Expand All @@ -233,7 +239,7 @@ class DeliveryLocationsResolver {
eddRequestable: false,
deliveryLocation: []
}
const holdingLocationCode = DeliveryLocationsResolver.extractLocationCode(item)
const holdingLocationCode = this.extractLocationCode(item)
const sierraData = DeliveryLocationsResolver.nyplCoreLocation(holdingLocationCode)
if (!sierraData) {
// This case is mainly to satisfy a test which wants eddRequestable = false
Expand All @@ -243,15 +249,15 @@ class DeliveryLocationsResolver {
}
// if nypl core says it's unrequestable, it can still be eddRequestable,
// but its definitely not phys requestable.
deliveryInfo.eddRequestable = DeliveryLocationsResolver.eddRequestableByOnSiteCriteria(item)
if (!DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item)) {
deliveryInfo.eddRequestable = this.eddRequestableByOnSiteCriteria(item)
if (!this.requestableBasedOnHoldingLocation(item)) {
return deliveryInfo
}
// if nypl-core reports that a holding location's delivery locations
// should be found by M2 code, but only if the item has an M2 customer code
const deliverableToResolution = sierraData.deliverableToResolution
if (deliverableToResolution === 'm2-customer-code' && item.m2CustomerCode && item.m2CustomerCode[0]) {
deliveryInfo.deliveryLocation = DeliveryLocationsResolver.deliveryLocationsByM2CustomerCode(item.m2CustomerCode[0])
deliveryInfo.deliveryLocation = this.deliveryLocationsByM2CustomerCode(item.m2CustomerCode[0])
}
// if no value, default to sierra location lookup
if (!deliverableToResolution) {
Expand All @@ -275,15 +281,15 @@ class DeliveryLocationsResolver {
}

/**
* 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.
* Given an array of items (ES hits), returns the same items with `eddRequestable` & `deliveryLocations`
*
* @return Promise<Array<items>> A Promise that resolves and array of items, modified to include `eddRequestable` & `deliveryLocations`
*/
static attachDeliveryLocationsAndEddRequestability (items, scholarRoom) {
// Extract ReCAP barcodes from items:
const recapBarcodes = DeliveryLocationsResolver.extractRecapBarcodes(items)
const recapBarcodes = this.extractRecapBarcodes(items)
// Get a map from barcodes to ReCAP customercodes:
return DeliveryLocationsResolver.__recapCustomerCodesByBarcodes(recapBarcodes)
return this.__recapCustomerCodesByBarcodes(recapBarcodes)
.then((barcodeToRecapCustomerCode) => {
// Now map over items to affix deliveryLocations:
return items.map((item) => {
Expand All @@ -292,15 +298,15 @@ class DeliveryLocationsResolver {
item.recapCustomerCode = [barcodeToRecapCustomerCode[barcode]]
// If recap has a customer code for this barcode, map it by recap cust code:
if (item.recapCustomerCode[0]) {
item = DeliveryLocationsResolver.attachRecapDeliveryInfo(item)
item = this.attachRecapDeliveryInfo(item)
// Otherwise, it's an onsite item
} else {
item = DeliveryLocationsResolver.attachOnsiteDeliveryInfo(item)
item = this.attachOnsiteDeliveryInfo(item)
}
// Establish default for Electronic Document Delivery flag:
item.eddRequestable = !!item.eddRequestable
const filteredDeliveryLocationsWithScholarRoom = DeliveryLocationsResolver.filterLocations(item.deliveryLocation, scholarRoom)
item.deliveryLocation = DeliveryLocationsResolver.formatLocations(filteredDeliveryLocationsWithScholarRoom)
const filteredDeliveryLocationsWithScholarRoom = this.filterLocations(item.deliveryLocation, scholarRoom)
item.deliveryLocation = this.formatLocations(filteredDeliveryLocationsWithScholarRoom)
return item
})
})
Expand Down
9 changes: 5 additions & 4 deletions lib/jsonld_serializers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

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

const util = require('./util.js')
Expand Down Expand Up @@ -286,7 +287,7 @@ class ResourceSerializer extends JsonLdItemSerializer {
}

ResourceSerializer.getFormattedRecordType = function (recordTypeId) {
const prefLabel = nyplCore.recordTypes()[recordTypeId]?.label
const prefLabel = recordTypes[recordTypeId]?.label
if (!prefLabel) return null
return {
'@id': recordTypeId,
Expand Down Expand Up @@ -498,10 +499,10 @@ class AggregationSerializer extends JsonLdItemSerializer {
v.label = p[1]
} else if (field === 'buildingLocation') {
// Build buildingLocation agg labels from nypl-core:
v.label = nyplCore.sierraLocations()[v.value]?.label
v.label = locations[v.value]?.label
} else if (field === 'recordType') {
// Build recordType agg labels from nypl-core:
v.label = nyplCore.recordTypes()[v.value]?.label
v.label = recordTypes[v.value]?.label
// Unknown recordType? Remove it:
if (!v.label) return null
} else {
Expand Down
25 changes: 0 additions & 25 deletions lib/load_nypl_core.js

This file was deleted.

12 changes: 5 additions & 7 deletions lib/location_label_updater.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const nyplCore = require('./load_nypl_core')
const sierraLocations = require('@nypl/nypl-core-objects')('by-sierra-location')

class LocationLabelUpdater {
constructor (responseReceived) {
Expand All @@ -10,22 +10,20 @@ class LocationLabelUpdater {
const resp = this.elasticSearchResponse
const updatedHits = resp.hits.hits.map((bib) => {
// Update locations for items:
const items = bib._source.items || []
items.forEach((item) => {
; (bib._source.items || []).forEach((item) => {
if (item.holdingLocation && item.holdingLocation.length > 0) {
item.holdingLocation = item.holdingLocation.map((loc) => {
const nyplCoreEntry = nyplCore.sierraLocations()[loc.id.replace(/^loc:/, '')]
const nyplCoreEntry = sierraLocations[loc.id.replace(/^loc:/, '')]
if (nyplCoreEntry) loc.label = nyplCoreEntry.label
return loc
})
}
})
// Update locations for holdings:
const holdings = bib._source.holdings || []
holdings.forEach((holding) => {
; (bib._source.holdings || []).forEach((holding) => {
if (holding.location && holding.location.length > 0) {
holding.location = holding.location.map((loc) => {
const nyplCoreEntry = nyplCore.sierraLocations()[loc.code.replace(/^loc:/, '')]
const nyplCoreEntry = sierraLocations[loc.code.replace(/^loc:/, '')]
if (nyplCoreEntry) loc.label = nyplCoreEntry.label
return loc
})
Expand Down
Loading
Loading