Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scc 4345/add record type #422

Merged
merged 11 commits into from
Dec 6, 2024
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.21
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.21
NYPL_CORE_VERSION=v2.22

LOG_LEVEL=info
FEATURES=on-site-edd
Expand Down
1 change: 1 addition & 0 deletions lib/elasticsearch/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const SEARCH_SCOPES = {
}

const FILTER_CONFIG = {
recordType: { operator: 'match', field: 'recordTypeId', repeatable: true },
owner: { operator: 'match', field: 'items.owner_packed', repeatable: true, path: 'items' },
subjectLiteral: { operator: 'match', field: 'subjectLiteral_exploded', repeatable: true },
holdingLocation: { operator: 'match', field: 'items.holdingLocation_packed', repeatable: true, path: 'items' },
Expand Down
20 changes: 18 additions & 2 deletions lib/jsonld_serializers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

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 @@ -76,8 +77,9 @@ class JsonLdItemSerializer extends JsonLdSerializer {
if (Array.isArray(v)) return v.map(formatVal)
else if (v && typeof v === 'object') {
const formatted = v
// Reassign id to @id, type to @type, value to @value
;['id', 'type', 'value'].forEach((specialProp) => {
const properties = ['id', 'type', 'value']
// Reassign id to @id, type to @type, value to @value
properties.forEach((specialProp) => {
if (formatted[specialProp]) {
formatted[`@${specialProp}`] = formatted[specialProp]
delete formatted[specialProp]
Expand Down Expand Up @@ -268,6 +270,10 @@ class ResourceSerializer extends JsonLdItemSerializer {
stmts.hasItemDates = this.body.numItemDatesParsed[0] / numItems >= parseFloat(process.env.BIB_HAS_DATES_THRESHOLD)
}
}
if (this.body.recordTypeId) {
stmts.recordType = ResourceSerializer.getFormattedRecordType(this.body.recordTypeId)
delete stmts.recordTypeId
}

// DFE depends on this being set to an empty array when null:
stmts.electronicResources = stmts.electronicResources || []
Expand All @@ -280,6 +286,13 @@ class ResourceSerializer extends JsonLdItemSerializer {
}
}

ResourceSerializer.getFormattedRecordType = function (recordTypeId) {
return {
'@id': recordTypeId,
prefLabel: recordTypes[recordTypeId].label
}
}

ResourceSerializer.formatElectronicResourceBlankNode = function (link, rdfsType) {
// Get the link label (fall back on prefLabel if serialization moved it there)
const label = link.label || link.prefLabel
Expand Down Expand Up @@ -485,6 +498,9 @@ class AggregationSerializer extends JsonLdItemSerializer {
} else if (field === 'buildingLocation') {
// Build buildingLocation agg labels from nypl-core:
v.label = locations[v.value]?.label
} else if (field === 'recordType') {
// Build recordType agg labels from nypl-core:
v.label = recordTypes[v.value]?.label
} else {
v.label = v.value
}
Expand Down
1 change: 1 addition & 0 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const ITEM_FILTER_AGGREGATIONS = {

// Configures aggregations:
const AGGREGATIONS_SPEC = {
recordType: { terms: { field: 'recordTypeId' } },
buildingLocation: { terms: { field: 'buildingLocationIds' } },
owner: { nested: { path: 'items' }, aggs: { _nested: { terms: { field: 'items.owner_packed' } } } },
subjectLiteral: { terms: { field: 'subjectLiteral.raw' } },
Expand Down
4 changes: 2 additions & 2 deletions swagger.v1.1.x.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{
"name": "filters[*]",
"in": "query",
"description": "Specify a hash of filters to apply, where key is: 'buildingLocation', 'owner', 'subjectLiteral', 'holdingLocation', 'deliveryLocation', 'language', 'materialType', 'mediaType', 'carrierType', 'publisher', 'contributor', 'creator', 'issuance', 'createdYear', 'dateAfter', or 'dateBefore'",
"description": "Specify a hash of filters to apply, where key is: 'recordType', 'buildingLocation', 'owner', 'subjectLiteral', 'holdingLocation', 'deliveryLocation', 'language', 'materialType', 'mediaType', 'carrierType', 'publisher', 'contributor', 'creator', 'issuance', 'createdYear', 'dateAfter', or 'dateBefore'",
"required": false,
"type": "string"
},
Expand Down Expand Up @@ -924,4 +924,4 @@
}
}
}
}
}
Loading
Loading