From 99080b6e83afbf1519e5ab8c41c1f46220e8fd41 Mon Sep 17 00:00:00 2001 From: fo Date: Thu, 25 Jun 2026 14:45:46 +0000 Subject: [PATCH 1/3] Add support for changing MARC formats --- dctap-dancer | 2 +- ldpjs | 1 + util-service/routes/marc.js | 62 ++++++++++++++++++++++++++++++- util-service/routes/publishing.js | 2 +- 4 files changed, 64 insertions(+), 3 deletions(-) create mode 160000 ldpjs diff --git a/dctap-dancer b/dctap-dancer index 45dbd73..d9f5e13 160000 --- a/dctap-dancer +++ b/dctap-dancer @@ -1 +1 @@ -Subproject commit 45dbd73c280a6577ef1bf5daca7c104606f421c1 +Subproject commit d9f5e1393f585a5f3d1c83526c49952b872bec2b diff --git a/ldpjs b/ldpjs new file mode 160000 index 0000000..d7aee34 --- /dev/null +++ b/ldpjs @@ -0,0 +1 @@ +Subproject commit d7aee34f2b6acab26ccd714eed2c1e6925f6a642 diff --git a/util-service/routes/marc.js b/util-service/routes/marc.js index 89b7a62..4b4ce4e 100644 --- a/util-service/routes/marc.js +++ b/util-service/routes/marc.js @@ -1,8 +1,9 @@ /** - * MARC Preview Routes + * MARC Routes * * Handles MARC preview generation: * - POST /marcpreview/:type - Generate MARC preview from RDF + * - POST /marcformat - Generate MARC of 1 format from another format */ const express = require('express'); @@ -45,6 +46,8 @@ function runXsltproc(xsltPath, xmlContent) { * @returns {string} HTML formatted MARC */ function marcRecordHtmlify(data) { + console.info("generating HTML") + console.info("data: ", data) let formattedMarcRecord = ["
"]; let leader = "
" + data['leader'].replace(/ /g, ' ') + '
'; formattedMarcRecord.push(leader); @@ -88,6 +91,41 @@ function marcRecordHtmlify(data) { return formattedMarcRecord.join('\r\n'); } +/** + * + * @param {*} marcxml MARC record as XML that will be changed + * @param {string} sourceType Type of the incoming MARC, type record is {'leader': <....>, 'fields': [...]} + * @param {string} targetType Type of the outgoing MARC + * @returns + */ +function marcChangeFormat(marc, sourceType, targetType){ + console.info("swap format") + let sourceTypeList = [ 'iso2709', 'marcxml', 'mij', 'record'] + let targetTypeList = [ 'iso2709', 'marcxml', 'mij', 'Ttext', 'json', 'html'] + + if (!sourceTypeList.includes(sourceType)){ + return [false, 'source', sourceTypeList] + } + if (!targetTypeList.includes(targetType)){ + return [false, 'target', targetTypeList] + } + + let formatted + if (targetType != 'html'){ + const record = Marc.parse(marc, sourceType); + formatted = Marc.format(record, targetType) + } else { + if (sourceType == 'record'){ + formatted = marcRecordHtmlify(marc) + } else { + formatted = Marc.parse(marc, 'marcxml') + formatted = marcRecordHtmlify(formatted) + } + } + + return [true, true, formatted] +} + /** * Create MARC routes * @returns {Router} Express router @@ -148,6 +186,28 @@ function createMarcRoutes() { res.json(results); }); + /** + * POST /marcformat - Generate MARC of 1 format from another format + */ + router.post('/marcformat', async (req, res) => { + console.info("formatting") + let marc = req.body.mrc; + const sourceType = req.body.sourceType; + const targetType = req.body.targetType; + + if (sourceType != 'record'){ + marc = marc.replaceAll('marcxml:', '') + } + let recordFormatted = marcChangeFormat(marc, sourceType, targetType) + if (!recordFormatted[0]){ + let message = 'Failed to match ' + recordFormatted[1] + ' format. Available formats: ' + recordFormatted[2].join(", ") + + return res.status(500).json({ msg: 'Error: ' + message }); + } else { + return res.status(200).json({ result: recordFormatted[2] }); + } + }); + return router; } diff --git a/util-service/routes/publishing.js b/util-service/routes/publishing.js index 5cb22e1..d241c0b 100644 --- a/util-service/routes/publishing.js +++ b/util-service/routes/publishing.js @@ -472,7 +472,7 @@ function createPublishingRoutes(options) { console.log('validating against: ', url); const loc = req.params.loc; if (loc == 'stage') { - url = url.replace('preprod', 'preprod-8299'); + // url = url.replace('preprod', 'preprod-8299'); } const postLogEntry = { From d7a3fb9c4b9f6aff02f503f47303b93406549321 Mon Sep 17 00:00:00 2001 From: fo Date: Thu, 25 Jun 2026 14:51:53 +0000 Subject: [PATCH 2/3] cleanup --- util-service/routes/marc.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/util-service/routes/marc.js b/util-service/routes/marc.js index 4b4ce4e..33e3b04 100644 --- a/util-service/routes/marc.js +++ b/util-service/routes/marc.js @@ -46,8 +46,6 @@ function runXsltproc(xsltPath, xmlContent) { * @returns {string} HTML formatted MARC */ function marcRecordHtmlify(data) { - console.info("generating HTML") - console.info("data: ", data) let formattedMarcRecord = ["
"]; let leader = "
" + data['leader'].replace(/ /g, ' ') + '
'; formattedMarcRecord.push(leader); @@ -99,9 +97,8 @@ function marcRecordHtmlify(data) { * @returns */ function marcChangeFormat(marc, sourceType, targetType){ - console.info("swap format") let sourceTypeList = [ 'iso2709', 'marcxml', 'mij', 'record'] - let targetTypeList = [ 'iso2709', 'marcxml', 'mij', 'Ttext', 'json', 'html'] + let targetTypeList = [ 'iso2709', 'marcxml', 'mij', 'text', 'json', 'html'] if (!sourceTypeList.includes(sourceType)){ return [false, 'source', sourceTypeList] @@ -190,7 +187,6 @@ function createMarcRoutes() { * POST /marcformat - Generate MARC of 1 format from another format */ router.post('/marcformat', async (req, res) => { - console.info("formatting") let marc = req.body.mrc; const sourceType = req.body.sourceType; const targetType = req.body.targetType; From bbdb7d16d481482ebf09336d8e89c0faa51715c8 Mon Sep 17 00:00:00 2001 From: fo Date: Fri, 26 Jun 2026 18:02:36 +0000 Subject: [PATCH 3/3] Remove comment --- util-service/routes/publishing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util-service/routes/publishing.js b/util-service/routes/publishing.js index d241c0b..5cb22e1 100644 --- a/util-service/routes/publishing.js +++ b/util-service/routes/publishing.js @@ -472,7 +472,7 @@ function createPublishingRoutes(options) { console.log('validating against: ', url); const loc = req.params.loc; if (loc == 'stage') { - // url = url.replace('preprod', 'preprod-8299'); + url = url.replace('preprod', 'preprod-8299'); } const postLogEntry = {