11const { itemHasRecapHoldingLocation, barcodeFromItem } = require ( './util' )
22const 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' )
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 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 } )
0 commit comments