11const { itemHasRecapHoldingLocation, barcodeFromItem } = require ( './util' )
22const scsbClient = require ( './scsb-client' )
3- const recapCustomerCodes = require ( '@nypl/nypl-core-objects' ) ( 'by-recap-customer-code ')
4- const sierraLocations = require ( '@nypl/nypl-core-objects' ) ( 'by-sierra-location' )
3+ const nyplCore = require ( './load_nypl_core ' )
4+
55const logger = require ( './logger' )
66const onsiteEddCriteria = require ( '../data/onsite-edd-criteria.json' )
77const { isItemNyplOwned } = require ( './ownership_determination' )
88
99class DeliveryLocationsResolver {
1010 static nyplCoreLocation ( locationCode ) {
11- return sierraLocations [ locationCode ]
11+ return nyplCore . sierraLocations ( ) [ locationCode ]
1212 }
1313
1414 static requestableBasedOnHoldingLocation ( item ) {
15- const locationCode = this . extractLocationCode ( item )
15+ const locationCode = DeliveryLocationsResolver . extractLocationCode ( item )
1616
1717 if ( ! DeliveryLocationsResolver . nyplCoreLocation ( locationCode ) ) {
1818 logger . warn ( `DeliveryLocationsResolver: Unrecognized holdingLocation for ${ item . uri } : ${ locationCode } ` )
@@ -50,21 +50,15 @@ class DeliveryLocationsResolver {
5050
5151 // Fetch Sierra delivery locations by recap code
5252 static deliveryLocationsByRecapCustomerCode ( customerCode ) {
53- if ( recapCustomerCodes [ customerCode ] && recapCustomerCodes [ customerCode ] . sierraDeliveryLocations ) {
54- return recapCustomerCodes [ customerCode ] . sierraDeliveryLocations
53+ if ( nyplCore . recapCustomerCodes ( ) [ customerCode ] && nyplCore . recapCustomerCodes ( ) [ customerCode ] . sierraDeliveryLocations ) {
54+ return nyplCore . 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- 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 ]
60+ if ( nyplCore . m2CustomerCodes ( ) ?. [ customerCode ] ?. sierraDeliveryLocations ) {
61+ const { sierraDeliveryLocations, requestable } = nyplCore . m2CustomerCodes ( ) [ customerCode ]
6862 if ( requestable ) {
6963 return sierraDeliveryLocations
7064 } else return undefined
@@ -73,7 +67,7 @@ class DeliveryLocationsResolver {
7367
7468 // Determine eddRequestable by recap customer code:
7569 static __eddRequestableByCustomerCode ( customerCode ) {
76- if ( recapCustomerCodes [ customerCode ] ) return Boolean ( recapCustomerCodes [ customerCode ] . eddRequestable )
70+ if ( nyplCore . recapCustomerCodes ( ) [ customerCode ] ) return Boolean ( nyplCore . recapCustomerCodes ( ) [ customerCode ] . eddRequestable )
7771 }
7872
7973 // Determine eddRequestable by on-site EDD requestability criteria (presumed on-site):
@@ -172,7 +166,7 @@ class DeliveryLocationsResolver {
172166 return {
173167 id : `loc:${ location . code } ` ,
174168 label : location . label ,
175- sortPosition : this . sortPosition ( location )
169+ sortPosition : DeliveryLocationsResolver . sortPosition ( location )
176170 }
177171 } )
178172 // Either way, sort deliveryLocation entries by name:
@@ -197,14 +191,14 @@ class DeliveryLocationsResolver {
197191 }
198192
199193 static attachRecapDeliveryInfo ( item ) {
200- const info = this . getRecapDeliveryInfo ( item )
194+ const info = DeliveryLocationsResolver . getRecapDeliveryInfo ( item )
201195 item . eddRequestable = info . eddRequestable
202196 item . deliveryLocation = info . deliveryLocation
203197 return item
204198 }
205199
206200 static attachOnsiteDeliveryInfo ( item ) {
207- const info = this . getOnsiteDeliveryInfo ( item )
201+ const info = DeliveryLocationsResolver . getOnsiteDeliveryInfo ( item )
208202 item . eddRequestable = info . eddRequestable
209203 item . deliveryLocation = info . deliveryLocation
210204 return item
@@ -218,15 +212,15 @@ class DeliveryLocationsResolver {
218212 const hasRecapCustomerCode = item . recapCustomerCode && item . recapCustomerCode [ 0 ]
219213 const nyplItem = isItemNyplOwned ( item )
220214 if ( ! hasRecapCustomerCode ) {
221- const requestableBasedOnHoldingLocation = nyplItem ? this . requestableBasedOnHoldingLocation ( item ) : true
215+ const requestableBasedOnHoldingLocation = nyplItem ? DeliveryLocationsResolver . requestableBasedOnHoldingLocation ( item ) : true
222216 // the length of the list of delivery locations is checked later to determine physical requestability
223217 // In case of an offsite item with no recap customer code, we want this to be based on holding location
224218 // so we put a placeholder '' in case it is requestable based on holding location
225219 deliveryLocation = requestableBasedOnHoldingLocation ? [ '' ] : [ ]
226220 eddRequestable = requestableBasedOnHoldingLocation
227- } else if ( ! nyplItem || this . requestableBasedOnHoldingLocation ( item ) ) {
228- deliveryLocation = this . deliveryLocationsByRecapCustomerCode ( item . recapCustomerCode [ 0 ] )
229- eddRequestable = this . __eddRequestableByCustomerCode ( item . recapCustomerCode [ 0 ] )
221+ } else if ( ! nyplItem || DeliveryLocationsResolver . requestableBasedOnHoldingLocation ( item ) ) {
222+ deliveryLocation = DeliveryLocationsResolver . deliveryLocationsByRecapCustomerCode ( item . recapCustomerCode [ 0 ] )
223+ eddRequestable = DeliveryLocationsResolver . __eddRequestableByCustomerCode ( item . recapCustomerCode [ 0 ] )
230224 } else {
231225 deliveryLocation = [ ]
232226 eddRequestable = false
@@ -239,7 +233,7 @@ class DeliveryLocationsResolver {
239233 eddRequestable : false ,
240234 deliveryLocation : [ ]
241235 }
242- const holdingLocationCode = this . extractLocationCode ( item )
236+ const holdingLocationCode = DeliveryLocationsResolver . extractLocationCode ( item )
243237 const sierraData = DeliveryLocationsResolver . nyplCoreLocation ( holdingLocationCode )
244238 if ( ! sierraData ) {
245239 // This case is mainly to satisfy a test which wants eddRequestable = false
@@ -249,15 +243,15 @@ class DeliveryLocationsResolver {
249243 }
250244 // if nypl core says it's unrequestable, it can still be eddRequestable,
251245 // but its definitely not phys requestable.
252- deliveryInfo . eddRequestable = this . eddRequestableByOnSiteCriteria ( item )
253- if ( ! this . requestableBasedOnHoldingLocation ( item ) ) {
246+ deliveryInfo . eddRequestable = DeliveryLocationsResolver . eddRequestableByOnSiteCriteria ( item )
247+ if ( ! DeliveryLocationsResolver . requestableBasedOnHoldingLocation ( item ) ) {
254248 return deliveryInfo
255249 }
256250 // if nypl-core reports that a holding location's delivery locations
257251 // should be found by M2 code, but only if the item has an M2 customer code
258252 const deliverableToResolution = sierraData . deliverableToResolution
259253 if ( deliverableToResolution === 'm2-customer-code' && item . m2CustomerCode && item . m2CustomerCode [ 0 ] ) {
260- deliveryInfo . deliveryLocation = this . deliveryLocationsByM2CustomerCode ( item . m2CustomerCode [ 0 ] )
254+ deliveryInfo . deliveryLocation = DeliveryLocationsResolver . deliveryLocationsByM2CustomerCode ( item . m2CustomerCode [ 0 ] )
261255 }
262256 // if no value, default to sierra location lookup
263257 if ( ! deliverableToResolution ) {
@@ -281,15 +275,15 @@ class DeliveryLocationsResolver {
281275 }
282276
283277 /**
284- * Given an array of items (ES hits), returns the same items with `eddRequestable` & `deliveryLocations`
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.
285279 *
286280 * @return Promise<Array<items>> A Promise that resolves and array of items, modified to include `eddRequestable` & `deliveryLocations`
287281 */
288282 static attachDeliveryLocationsAndEddRequestability ( items , scholarRoom ) {
289283 // Extract ReCAP barcodes from items:
290- const recapBarcodes = this . extractRecapBarcodes ( items )
284+ const recapBarcodes = DeliveryLocationsResolver . extractRecapBarcodes ( items )
291285 // Get a map from barcodes to ReCAP customercodes:
292- return this . __recapCustomerCodesByBarcodes ( recapBarcodes )
286+ return DeliveryLocationsResolver . __recapCustomerCodesByBarcodes ( recapBarcodes )
293287 . then ( ( barcodeToRecapCustomerCode ) => {
294288 // Now map over items to affix deliveryLocations:
295289 return items . map ( ( item ) => {
@@ -298,15 +292,15 @@ class DeliveryLocationsResolver {
298292 item . recapCustomerCode = [ barcodeToRecapCustomerCode [ barcode ] ]
299293 // If recap has a customer code for this barcode, map it by recap cust code:
300294 if ( item . recapCustomerCode [ 0 ] ) {
301- item = this . attachRecapDeliveryInfo ( item )
295+ item = DeliveryLocationsResolver . attachRecapDeliveryInfo ( item )
302296 // Otherwise, it's an onsite item
303297 } else {
304- item = this . attachOnsiteDeliveryInfo ( item )
298+ item = DeliveryLocationsResolver . attachOnsiteDeliveryInfo ( item )
305299 }
306300 // Establish default for Electronic Document Delivery flag:
307301 item . eddRequestable = ! ! item . eddRequestable
308- const filteredDeliveryLocationsWithScholarRoom = this . filterLocations ( item . deliveryLocation , scholarRoom )
309- item . deliveryLocation = this . formatLocations ( filteredDeliveryLocationsWithScholarRoom )
302+ const filteredDeliveryLocationsWithScholarRoom = DeliveryLocationsResolver . filterLocations ( item . deliveryLocation , scholarRoom )
303+ item . deliveryLocation = DeliveryLocationsResolver . formatLocations ( filteredDeliveryLocationsWithScholarRoom )
310304 return item
311305 } )
312306 } )
0 commit comments