From 3132c8f164e869c10359ec7c7ed76c5a3f1f7d59 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 28 Feb 2025 14:24:32 -0500 Subject: [PATCH] add format to discovery api response --- config/production.env | 2 +- config/qa.env | 2 +- lib/jsonld_serializers.js | 14 ++++++++++---- lib/load_nypl_core.js | 5 +++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config/production.env b/config/production.env index c0270a1..10eb54f 100644 --- a/config/production.env +++ b/config/production.env @@ -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.27 +NYPL_CORE_VERSION=v2.28 LOG_LEVEL=info FEATURES=on-site-edd diff --git a/config/qa.env b/config/qa.env index 9137e1a..d6b7da9 100644 --- a/config/qa.env +++ b/config/qa.env @@ -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.27 +NYPL_CORE_VERSION=v2.28 LOG_LEVEL=debug FEATURES=on-site-edd diff --git a/lib/jsonld_serializers.js b/lib/jsonld_serializers.js index 026d8f1..b3bc7bc 100644 --- a/lib/jsonld_serializers.js +++ b/lib/jsonld_serializers.js @@ -269,10 +269,16 @@ class ResourceSerializer extends JsonLdItemSerializer { stmts.hasItemDates = this.body.numItemDatesParsed[0] / numItems >= parseFloat(process.env.BIB_HAS_DATES_THRESHOLD) } } + // this value was indexed but is not being used for anything. if (this.body.recordTypeId) { - stmts.recordType = ResourceSerializer.getFormattedRecordType(this.body.recordTypeId) + stmts.recordType = ResourceSerializer.getFormattedMaterialLikeType(this.body.recordTypeId, 'recordTypes') delete stmts.recordTypeId } + // This is the value that we use to determine format for filtering + if (this.body.formatId) { + stmts.format = ResourceSerializer.getFormattedMaterialLikeType(this.body.recordTypeId, 'formats') + delete stmts.formatId + } // DFE depends on this being set to an empty array when null: stmts.electronicResources = stmts.electronicResources || [] @@ -285,11 +291,11 @@ class ResourceSerializer extends JsonLdItemSerializer { } } -ResourceSerializer.getFormattedRecordType = function (recordTypeId) { - const prefLabel = nyplCore.recordTypes()[recordTypeId]?.label +ResourceSerializer.getFormattedMaterialLikeType = function (id, property) { + const prefLabel = nyplCore[property]()[id]?.label if (!prefLabel) return null return { - '@id': recordTypeId, + '@id': id, prefLabel } } diff --git a/lib/load_nypl_core.js b/lib/load_nypl_core.js index 1206bde..8754804 100644 --- a/lib/load_nypl_core.js +++ b/lib/load_nypl_core.js @@ -1,13 +1,13 @@ const _data = {} const nyplCoreObjects = require('@nypl/nypl-core-objects') - const loadNyplCoreData = () => { const vocabularies = { sierraLocations: 'by-sierra-location', recordTypes: 'by-record-types', recapCustomerCodes: 'by-recap-customer-code', m2CustomerCodes: 'by-m2-customer-code', - patronTypes: 'by-patron-type' + patronTypes: 'by-patron-type', + formats: 'by-formats' } return Promise.all(Object.keys(vocabularies).map(async (vocab) => { const nyplCoreValues = await nyplCoreObjects(vocabularies[vocab]) @@ -17,6 +17,7 @@ const loadNyplCoreData = () => { module.exports = { loadNyplCoreData, + formats: () => _data.formats || {}, patronTypes: () => _data.patronTypes || {}, sierraLocations: () => _data.sierraLocations || {}, recapCustomerCodes: () => _data.recapCustomerCodes || {},