@natlibfi/melinda-rest-api-commons 2.3.1-alpha.7 → 2.3.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,321 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.REPLACE_PREFIXES = exports.BIB_PREVALIDATION_FIX_SETTINGS = exports.BIB_PREIMPORT_FIX_SETTINGS = exports.BIB_POSTMERGE_FIX_SETTINGS = exports.BIB_HANDLE_TEMP_URNS_SETTINGS = exports.BIB_FORMAT_SETTINGS = exports.BIB_F035_TO_SID = exports.AUTNAME_PREIMPORT_FIX_SETTINGS = void 0;
7
+ exports.fixRecord = fixRecord;
8
+
9
+ var _marcRecord = require("@natlibfi/marc-record");
10
+
11
+ var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
12
+
13
+ var _debug = _interopRequireDefault(require("debug"));
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+
17
+ /**
18
+ *
19
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
20
+ *
21
+ * Shared modules for microservices of Melinda rest api batch import system
22
+ *
23
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
24
+ *
25
+ * This file is part of melinda-rest-api-commons
26
+ *
27
+ * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
28
+ * it under the terms of the GNU Affero General Public License as
29
+ * published by the Free Software Foundation, either version 3 of the
30
+ * License, or (at your option) any later version.
31
+ *
32
+ * melinda-rest-api-commons is distributed in the hope that it will be useful,
33
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
34
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35
+ * GNU Affero General Public License for more details.
36
+ *
37
+ * You should have received a copy of the GNU Affero General Public License
38
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
39
+ *
40
+ * @licend The above is the entire license notice
41
+ * for the JavaScript code in this file.
42
+ *
43
+ */
44
+ function fixRecord(record, settings = {}) {
45
+ const logger = (0, _melindaBackendCommons.createLogger)();
46
+ const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:fixRecord');
47
+ const debugData = debug.extend('data');
48
+ logger.verbose(`We will apply formatting to the record according to settings: ${JSON.stringify(settings)}`);
49
+
50
+ const newRecord = _marcRecord.MarcRecord.clone(record, {
51
+ subfieldValues: false
52
+ });
53
+
54
+ debugData(`settings: ${JSON.stringify(settings)}`);
55
+ const generateMissingSIDsOptions = settings.generateMissingSIDs || undefined;
56
+ generateMissingSIDs(generateMissingSIDsOptions);
57
+ const replacePrefixesOptions = settings.replacePrefixes || [];
58
+ debugData(`replacePrefixesOptions: ${JSON.stringify(replacePrefixesOptions)}`);
59
+ replacePrefixesOptions.forEach(options => {
60
+ replacePrefixes(options);
61
+ });
62
+ handleTempUrns(settings.handleTempUrns);
63
+ return newRecord.toObject(); // Replace prefix in all specified subfields
64
+
65
+ function replacePrefixes(options) {
66
+ const {
67
+ oldPrefix,
68
+ newPrefix,
69
+ prefixReplaceCodes
70
+ } = options;
71
+ debug(`Replacing ${oldPrefix} with ${newPrefix} in subfields ${prefixReplaceCodes}`);
72
+ const pattern = `(${oldPrefix})`;
73
+ const replacement = `(${newPrefix})`;
74
+ newRecord.getDatafields().forEach(field => {
75
+ field.subfields.filter(({
76
+ code
77
+ }) => prefixReplaceCodes.includes(code)).forEach(subfield => {
78
+ subfield.value = subfield.value.replace(pattern, replacement); // eslint-disable-line functional/immutable-data
79
+ });
80
+ });
81
+ }
82
+
83
+ function generateMissingSIDs(options) {
84
+ debugData(`generateMissingSIDs options: ${JSON.stringify(options)}`);
85
+ const f035Filters = options && options.f035Filters ? options.f035Filters : [];
86
+ const fSIDFilters = options && options.fSIDFilters ? options.fSIDFilters : [];
87
+
88
+ if (f035Filters.length !== fSIDFilters.length || f035Filters.length < 1 || fSIDFilters.length < 1) {
89
+ debug(`No sane options for generating missing SIDs`);
90
+ return;
91
+ }
92
+
93
+ const f035s = f035ToSidInfo(newRecord.get(/^035$/u));
94
+ const fSIDs = sidsToSidInfo(newRecord.get(/^SID$/u));
95
+ const sidsToBeAdded = genNewSids(fSIDs.length === 0 ? f035s // test that SIDs are not there yet
96
+ : f035s.filter(f035SidInfo => fSIDs.some(fSIDInfo => f035SidInfo.SID !== fSIDInfo.SID && f035SidInfo.value !== fSIDInfo.value))); // Add new SIDs
97
+
98
+ return sidsToBeAdded.forEach(sidField => newRecord.insertField(sidField));
99
+
100
+ function genNewSids(sidsToBeAdded) {
101
+ return sidsToBeAdded.map(sidInfo => ({
102
+ tag: 'SID',
103
+ ind1: ' ',
104
+ ind2: ' ',
105
+ subfields: [{
106
+ code: 'c',
107
+ value: sidInfo.value
108
+ }, {
109
+ code: 'b',
110
+ value: sidInfo.SID
111
+ }]
112
+ }));
113
+ }
114
+
115
+ function sidsToSidInfo(SIDs) {
116
+ return SIDs.flatMap(({
117
+ subfields
118
+ }) => {
119
+ const [SID] = subfields.filter(sub => sub.code === 'b' && fSIDFilters.includes(sub.value)).map(sub => sub.value);
120
+ const [value] = subfields.filter(sub => sub.code === 'c' && sub.value !== undefined).map(sub => sub.value);
121
+
122
+ if (SID && value) {
123
+ return {
124
+ SID,
125
+ value
126
+ };
127
+ }
128
+
129
+ return undefined;
130
+ }).filter(value => value !== undefined);
131
+ }
132
+
133
+ function f035ToSidInfo(f035s) {
134
+ return f035s.flatMap(({
135
+ subfields
136
+ }) => {
137
+ const [wantedSub] = subfields.filter(sub => sub.code === 'a' && f035Filters.some(regexp => regexp.test(sub.value)));
138
+
139
+ if (wantedSub) {
140
+ return {
141
+ SID: fSIDFilters[f035Filters.findIndex(regexp => regexp.test(wantedSub.value))],
142
+ value: wantedSub.value.slice(wantedSub.value.indexOf(')') + 1)
143
+ };
144
+ }
145
+
146
+ return undefined;
147
+ }).filter(value => value !== undefined);
148
+ }
149
+ } // eslint-disable-next-line max-statements
150
+
151
+
152
+ function handleTempUrns(options) {
153
+ debugData(`Options for handleTempUrns: ${JSON.stringify(options)}`);
154
+
155
+ if (options !== true) {
156
+ return;
157
+ } // If we have an non-temp URN, we can delete tempURNs, otherwise we should delete the temp subfield from URN
158
+
159
+
160
+ const hasURN = f => f.tag === '856' && f.subfields.some(({
161
+ code,
162
+ value
163
+ }) => code === 'u' && /urn.fi/u.test(value));
164
+
165
+ const hasTempSubfield = f => f.subfields.some(({
166
+ code,
167
+ value
168
+ }) => code === '9' && /^MELINDA<TEMP>$/u.test(value));
169
+
170
+ const hasNoTempSubfield = f => !f.subfields.some(({
171
+ code,
172
+ value
173
+ }) => code === '9' && /^MELINDA<TEMP>$/u.test(value));
174
+
175
+ const f856sUrn = newRecord.fields.filter(hasURN);
176
+ const f856sUrnsWithTempSubfields = f856sUrn.filter(hasTempSubfield);
177
+ const f856sUrnsWithNoTempSubfields = f856sUrn.filter(hasNoTempSubfield);
178
+ debugData(`URN f856s: ${JSON.stringify(f856sUrn)}`);
179
+ debugData(`URN f856s with temp subfield: ${JSON.stringify(f856sUrnsWithTempSubfields)}`); // None of the URNs has temp subfields, we don't need to do anything
180
+
181
+ if (f856sUrnsWithTempSubfields.length < 1) {
182
+ debug(`No Urns with temp subfield`);
183
+ return;
184
+ } // Do we have an existing URN with legal deposit subfields, if we have, we can remove the temp URN field(s)
185
+
186
+
187
+ const existingLegalDepositURN = validateLD(f856sUrnsWithNoTempSubfields);
188
+ debug(`existingLegalDepositURN: ${existingLegalDepositURN}`);
189
+
190
+ if (existingLegalDepositURN) {
191
+ debug(`We have an existing LD URN, we can delete temp fields (${f856sUrnsWithTempSubfields.length})`);
192
+ newRecord.removeFields(f856sUrnsWithTempSubfields);
193
+ return;
194
+ } // We do not have an existing legalDepositURN, we should use the tempURN and remove the temp subfields from it
195
+
196
+
197
+ if (!existingLegalDepositURN && f856sUrnsWithTempSubfields.length > 0) {
198
+ //debug(`All Urns (${f856sUrn.length}) have a temp subfield`);
199
+ debugData(`Original temp URNs: (${JSON.stringify(f856sUrnsWithTempSubfields)})`);
200
+ const fixedFields = f856sUrnsWithTempSubfields.map(removeTempSubfield).filter(field => field);
201
+ debug(`We removed temp subfields: (${JSON.stringify(fixedFields)})`);
202
+ newRecord.removeFields(f856sUrnsWithTempSubfields);
203
+ newRecord.insertFields(fixedFields);
204
+ return;
205
+ } // Should we check that the non-temp URN has 2nd ind '0' - meaning that the URN handles the actual resource itself?
206
+
207
+ } // ---- LD-functions below are same as in https://github.com/NatLibFi/marc-record-validators-melinda/blob/feature-updates-to-urn/src/urn.js
208
+ // we propably should develop the urn/legaldeposit -validator to use also here
209
+
210
+
211
+ function createLDSubfields() {
212
+ return [{
213
+ code: 'z',
214
+ value: 'Käytettävissä vapaakappalekirjastoissa'
215
+ }, {
216
+ code: '5',
217
+ value: 'FI-Vapaa'
218
+ }];
219
+ }
220
+
221
+ function validateLD(f856sUrn) {
222
+ debug(`Validating the existence of legal deposit subfields`);
223
+ const ldSubfields = createLDSubfields();
224
+ const f856sUrnWithLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, ldSubfields));
225
+
226
+ if (f856sUrnWithLdSubfields.length > 0) {
227
+ debug(`Record has ${f856sUrnWithLdSubfields.length} URN fields with all necessary legal deposit subfields`);
228
+ debugData(`f856sUrnWithLdSubfields: ${JSON.stringify(f856sUrnWithLdSubfields)}`);
229
+ return true;
230
+ }
231
+
232
+ return false;
233
+ }
234
+
235
+ function fieldHasLDSubfields(field, ldSubfields) {
236
+ if (ldSubfields.every(ldsf => field.subfields.some(sf => sf.code === ldsf.code && sf.value === ldsf.value))) {
237
+ return true;
238
+ }
239
+ } // ---
240
+
241
+
242
+ function removeTempSubfield(field) {
243
+ // Handle non-numeric fields, and fields with a numeric tag of 010 and greater
244
+ // Aleph's FMT as a controlfield might be a problem
245
+ if (!isNaN(field.tag) && parseInt(field.tag, 10) >= 10) {
246
+ const filteredSubfields = field.subfields.filter(sf => sf.code !== '9' && !/^MELINDA<TEMP>$/u.test(sf.value)); // Remove whole field if there are no subfields left
247
+
248
+ if (filteredSubfields.length < 1) {
249
+ return false;
250
+ }
251
+
252
+ return {
253
+ tag: field.tag,
254
+ ind1: field.ind1,
255
+ ind2: field.ind2,
256
+ subfields: filteredSubfields
257
+ };
258
+ } // return controlFields as is
259
+
260
+
261
+ return field;
262
+ }
263
+ } // This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index
264
+
265
+
266
+ const BIB_F035_TO_SID = {
267
+ f035Filters: [/^\(FI-BTJ\)/u, /^\(FI-TATI\)/u],
268
+ fSIDFilters: ['FI-BTJ', 'tati']
269
+ }; // There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization
270
+
271
+ exports.BIB_F035_TO_SID = BIB_F035_TO_SID;
272
+ const REPLACE_PREFIXES = [{
273
+ oldPrefix: 'FI-MELINDA',
274
+ newPrefix: 'FIN01',
275
+ prefixReplaceCodes: ['w']
276
+ }, {
277
+ oldPrefix: 'FI-ASTERI-S',
278
+ newPrefix: 'FIN10',
279
+ prefixReplaceCodes: ['0']
280
+ }, {
281
+ oldPrefix: 'FI-ASTERI-N',
282
+ newPrefix: 'FIN11',
283
+ prefixReplaceCodes: ['0']
284
+ }, {
285
+ oldPrefix: 'FI-ASTERI-A',
286
+ newPrefix: 'FIN12',
287
+ prefixReplaceCodes: ['0']
288
+ }, {
289
+ oldPrefix: 'FI-ASTERI-W',
290
+ newPrefix: 'FIN13',
291
+ prefixReplaceCodes: ['0']
292
+ }]; // If placed in config.js testing needs envs
293
+ // BIB_FORMAT_SETTINGS is outdated, use other settings instead
294
+
295
+ exports.REPLACE_PREFIXES = REPLACE_PREFIXES;
296
+ const BIB_FORMAT_SETTINGS = {
297
+ replacePrefixes: REPLACE_PREFIXES,
298
+ generateMissingSIDs: BIB_F035_TO_SID
299
+ };
300
+ exports.BIB_FORMAT_SETTINGS = BIB_FORMAT_SETTINGS;
301
+ const BIB_PREVALIDATION_FIX_SETTINGS = {
302
+ generateMissingSIDs: BIB_F035_TO_SID
303
+ };
304
+ exports.BIB_PREVALIDATION_FIX_SETTINGS = BIB_PREVALIDATION_FIX_SETTINGS;
305
+ const BIB_POSTMERGE_FIX_SETTINGS = {
306
+ handleTempUrns: true
307
+ };
308
+ exports.BIB_POSTMERGE_FIX_SETTINGS = BIB_POSTMERGE_FIX_SETTINGS;
309
+ const BIB_PREIMPORT_FIX_SETTINGS = {
310
+ replacePrefixes: REPLACE_PREFIXES
311
+ };
312
+ exports.BIB_PREIMPORT_FIX_SETTINGS = BIB_PREIMPORT_FIX_SETTINGS;
313
+ const AUTNAME_PREIMPORT_FIX_SETTINGS = {
314
+ replacePrefixes: REPLACE_PREFIXES
315
+ };
316
+ exports.AUTNAME_PREIMPORT_FIX_SETTINGS = AUTNAME_PREIMPORT_FIX_SETTINGS;
317
+ const BIB_HANDLE_TEMP_URNS_SETTINGS = {
318
+ handleTempUrns: true
319
+ };
320
+ exports.BIB_HANDLE_TEMP_URNS_SETTINGS = BIB_HANDLE_TEMP_URNS_SETTINGS;
321
+ //# sourceMappingURL=fix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix.js","names":["fixRecord","record","settings","logger","createLogger","debug","createDebugLogger","debugData","extend","verbose","JSON","stringify","newRecord","MarcRecord","clone","subfieldValues","generateMissingSIDsOptions","generateMissingSIDs","undefined","replacePrefixesOptions","replacePrefixes","forEach","options","handleTempUrns","toObject","oldPrefix","newPrefix","prefixReplaceCodes","pattern","replacement","getDatafields","field","subfields","filter","code","includes","subfield","value","replace","f035Filters","fSIDFilters","length","f035s","f035ToSidInfo","get","fSIDs","sidsToSidInfo","sidsToBeAdded","genNewSids","f035SidInfo","some","fSIDInfo","SID","sidField","insertField","map","sidInfo","tag","ind1","ind2","SIDs","flatMap","sub","wantedSub","regexp","test","findIndex","slice","indexOf","hasURN","f","hasTempSubfield","hasNoTempSubfield","f856sUrn","fields","f856sUrnsWithTempSubfields","f856sUrnsWithNoTempSubfields","existingLegalDepositURN","validateLD","removeFields","fixedFields","removeTempSubfield","insertFields","createLDSubfields","ldSubfields","f856sUrnWithLdSubfields","fieldHasLDSubfields","every","ldsf","sf","isNaN","parseInt","filteredSubfields","BIB_F035_TO_SID","REPLACE_PREFIXES","BIB_FORMAT_SETTINGS","BIB_PREVALIDATION_FIX_SETTINGS","BIB_POSTMERGE_FIX_SETTINGS","BIB_PREIMPORT_FIX_SETTINGS","AUTNAME_PREIMPORT_FIX_SETTINGS","BIB_HANDLE_TEMP_URNS_SETTINGS"],"sources":["../../src/helpers/fix.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport createDebugLogger from 'debug';\n\nexport function fixRecord(record, settings = {}) {\n const logger = createLogger();\n const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fixRecord');\n const debugData = debug.extend('data');\n\n logger.verbose(`We will apply formatting to the record according to settings: ${JSON.stringify(settings)}`);\n const newRecord = MarcRecord.clone(record, {subfieldValues: false});\n debugData(`settings: ${JSON.stringify(settings)}`);\n\n const generateMissingSIDsOptions = settings.generateMissingSIDs || undefined;\n generateMissingSIDs(generateMissingSIDsOptions);\n\n const replacePrefixesOptions = settings.replacePrefixes || [];\n debugData(`replacePrefixesOptions: ${JSON.stringify(replacePrefixesOptions)}`);\n\n replacePrefixesOptions.forEach(options => {\n replacePrefixes(options);\n });\n\n handleTempUrns(settings.handleTempUrns);\n\n return newRecord.toObject();\n\n // Replace prefix in all specified subfields\n function replacePrefixes(options) {\n const {oldPrefix, newPrefix, prefixReplaceCodes} = options;\n debug(`Replacing ${oldPrefix} with ${newPrefix} in subfields ${prefixReplaceCodes}`);\n const pattern = `(${oldPrefix})`;\n const replacement = `(${newPrefix})`;\n newRecord.getDatafields()\n .forEach(field => {\n field.subfields\n .filter(({code}) => prefixReplaceCodes.includes(code))\n .forEach(subfield => {\n subfield.value = subfield.value.replace(pattern, replacement); // eslint-disable-line functional/immutable-data\n });\n });\n }\n\n\n function generateMissingSIDs(options) {\n debugData(`generateMissingSIDs options: ${JSON.stringify(options)}`);\n\n const f035Filters = options && options.f035Filters ? options.f035Filters : [];\n const fSIDFilters = options && options.fSIDFilters ? options.fSIDFilters : [];\n\n if (f035Filters.length !== fSIDFilters.length || f035Filters.length < 1 || fSIDFilters.length < 1) {\n debug(`No sane options for generating missing SIDs`);\n return;\n }\n\n const f035s = f035ToSidInfo(newRecord.get(/^035$/u));\n const fSIDs = sidsToSidInfo(newRecord.get(/^SID$/u));\n\n const sidsToBeAdded = genNewSids(fSIDs.length === 0\n ? f035s\n // test that SIDs are not there yet\n : f035s.filter(f035SidInfo => fSIDs.some(fSIDInfo => f035SidInfo.SID !== fSIDInfo.SID && f035SidInfo.value !== fSIDInfo.value)));\n\n // Add new SIDs\n return sidsToBeAdded.forEach(sidField => newRecord.insertField(sidField));\n\n function genNewSids(sidsToBeAdded) {\n return sidsToBeAdded.map(sidInfo => ({tag: 'SID', ind1: ' ', ind2: ' ', subfields: [{code: 'c', value: sidInfo.value}, {code: 'b', value: sidInfo.SID}]}));\n }\n\n function sidsToSidInfo(SIDs) {\n return SIDs.flatMap(({subfields}) => {\n const [SID] = subfields.filter(sub => sub.code === 'b' && fSIDFilters.includes(sub.value)).map(sub => sub.value);\n const [value] = subfields.filter(sub => sub.code === 'c' && sub.value !== undefined).map(sub => sub.value);\n\n if (SID && value) {\n return {\n SID,\n value\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n\n function f035ToSidInfo(f035s) {\n return f035s.flatMap(({subfields}) => {\n const [wantedSub] = subfields.filter(sub => sub.code === 'a' && f035Filters.some(regexp => regexp.test(sub.value)));\n\n if (wantedSub) {\n return {\n SID: fSIDFilters[f035Filters.findIndex(regexp => regexp.test(wantedSub.value))],\n value: wantedSub.value.slice(wantedSub.value.indexOf(')') + 1)\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n }\n\n\n // eslint-disable-next-line max-statements\n function handleTempUrns(options) {\n debugData(`Options for handleTempUrns: ${JSON.stringify(options)}`);\n\n if (options !== true) {\n return;\n }\n\n // If we have an non-temp URN, we can delete tempURNs, otherwise we should delete the temp subfield from URN\n\n const hasURN = f => f.tag === '856' && f.subfields.some(({code, value}) => code === 'u' && (/urn.fi/u).test(value));\n\n const hasTempSubfield = f => f.subfields.some(({code, value}) => code === '9' && (/^MELINDA<TEMP>$/u).test(value));\n const hasNoTempSubfield = f => !f.subfields.some(({code, value}) => code === '9' && (/^MELINDA<TEMP>$/u).test(value));\n\n const f856sUrn = newRecord.fields.filter(hasURN);\n const f856sUrnsWithTempSubfields = f856sUrn.filter(hasTempSubfield);\n const f856sUrnsWithNoTempSubfields = f856sUrn.filter(hasNoTempSubfield);\n\n debugData(`URN f856s: ${JSON.stringify(f856sUrn)}`);\n debugData(`URN f856s with temp subfield: ${JSON.stringify(f856sUrnsWithTempSubfields)}`);\n\n // None of the URNs has temp subfields, we don't need to do anything\n if (f856sUrnsWithTempSubfields.length < 1) {\n debug(`No Urns with temp subfield`);\n return;\n }\n\n // Do we have an existing URN with legal deposit subfields, if we have, we can remove the temp URN field(s)\n const existingLegalDepositURN = validateLD(f856sUrnsWithNoTempSubfields);\n debug(`existingLegalDepositURN: ${existingLegalDepositURN}`);\n\n if (existingLegalDepositURN) {\n debug(`We have an existing LD URN, we can delete temp fields (${f856sUrnsWithTempSubfields.length})`);\n newRecord.removeFields(f856sUrnsWithTempSubfields);\n return;\n }\n\n // We do not have an existing legalDepositURN, we should use the tempURN and remove the temp subfields from it\n if (!existingLegalDepositURN && f856sUrnsWithTempSubfields.length > 0) {\n //debug(`All Urns (${f856sUrn.length}) have a temp subfield`);\n debugData(`Original temp URNs: (${JSON.stringify(f856sUrnsWithTempSubfields)})`);\n const fixedFields = f856sUrnsWithTempSubfields.map(removeTempSubfield).filter(field => field);\n debug(`We removed temp subfields: (${JSON.stringify(fixedFields)})`);\n newRecord.removeFields(f856sUrnsWithTempSubfields);\n newRecord.insertFields(fixedFields);\n return;\n }\n\n // Should we check that the non-temp URN has 2nd ind '0' - meaning that the URN handles the actual resource itself?\n }\n\n // ---- LD-functions below are same as in https://github.com/NatLibFi/marc-record-validators-melinda/blob/feature-updates-to-urn/src/urn.js\n // we propably should develop the urn/legaldeposit -validator to use also here\n\n function createLDSubfields() {\n return [\n {\n code: 'z',\n value: 'Käytettävissä vapaakappalekirjastoissa'\n },\n {\n code: '5',\n value: 'FI-Vapaa'\n }\n ];\n }\n\n function validateLD(f856sUrn) {\n debug(`Validating the existence of legal deposit subfields`);\n const ldSubfields = createLDSubfields();\n const f856sUrnWithLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, ldSubfields));\n if (f856sUrnWithLdSubfields.length > 0) {\n debug(`Record has ${f856sUrnWithLdSubfields.length} URN fields with all necessary legal deposit subfields`);\n debugData(`f856sUrnWithLdSubfields: ${JSON.stringify(f856sUrnWithLdSubfields)}`);\n return true;\n }\n return false;\n }\n\n function fieldHasLDSubfields(field, ldSubfields) {\n if (ldSubfields.every(ldsf => field.subfields.some(sf => sf.code === ldsf.code && sf.value === ldsf.value))) {\n return true;\n }\n }\n\n // ---\n\n function removeTempSubfield(field) {\n\n // Handle non-numeric fields, and fields with a numeric tag of 010 and greater\n // Aleph's FMT as a controlfield might be a problem\n if (!isNaN(field.tag) && parseInt(field.tag, 10) >= 10) {\n\n const filteredSubfields = field.subfields.filter(sf => sf.code !== '9' && !(/^MELINDA<TEMP>$/u).test(sf.value));\n\n // Remove whole field if there are no subfields left\n if (filteredSubfields.length < 1) {\n return false;\n }\n\n return {\n tag: field.tag,\n ind1: field.ind1,\n ind2: field.ind2,\n subfields: filteredSubfields\n };\n }\n // return controlFields as is\n return field;\n }\n}\n\n// This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index\nexport const BIB_F035_TO_SID = {\n f035Filters: [/^\\(FI-BTJ\\)/u, /^\\(FI-TATI\\)/u],\n fSIDFilters: ['FI-BTJ', 'tati']\n};\n\n// There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization\nexport const REPLACE_PREFIXES = [\n {\n oldPrefix: 'FI-MELINDA',\n newPrefix: 'FIN01',\n prefixReplaceCodes: ['w']\n },\n {\n oldPrefix: 'FI-ASTERI-S',\n newPrefix: 'FIN10',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-N',\n newPrefix: 'FIN11',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-A',\n newPrefix: 'FIN12',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-W',\n newPrefix: 'FIN13',\n prefixReplaceCodes: ['0']\n }\n];\n\n// If placed in config.js testing needs envs\n// BIB_FORMAT_SETTINGS is outdated, use other settings instead\nexport const BIB_FORMAT_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES,\n generateMissingSIDs: BIB_F035_TO_SID\n};\n\nexport const BIB_PREVALIDATION_FIX_SETTINGS = {\n generateMissingSIDs: BIB_F035_TO_SID\n};\n\nexport const BIB_POSTMERGE_FIX_SETTINGS = {\n handleTempUrns: true\n};\n\nexport const BIB_PREIMPORT_FIX_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES\n};\n\nexport const AUTNAME_PREIMPORT_FIX_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES\n};\n\nexport const BIB_HANDLE_TEMP_URNS_SETTINGS = {\n handleTempUrns: true\n};\n"],"mappings":";;;;;;;;AA4BA;;AACA;;AACA;;;;AA9BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,SAASA,SAAT,CAAmBC,MAAnB,EAA2BC,QAAQ,GAAG,EAAtC,EAA0C;EAC/C,MAAMC,MAAM,GAAG,IAAAC,mCAAA,GAAf;EACA,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,8CAAlB,CAAd;EACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;EAEAL,MAAM,CAACM,OAAP,CAAgB,iEAAgEC,IAAI,CAACC,SAAL,CAAeT,QAAf,CAAyB,EAAzG;;EACA,MAAMU,SAAS,GAAGC,sBAAA,CAAWC,KAAX,CAAiBb,MAAjB,EAAyB;IAACc,cAAc,EAAE;EAAjB,CAAzB,CAAlB;;EACAR,SAAS,CAAE,aAAYG,IAAI,CAACC,SAAL,CAAeT,QAAf,CAAyB,EAAvC,CAAT;EAEA,MAAMc,0BAA0B,GAAGd,QAAQ,CAACe,mBAAT,IAAgCC,SAAnE;EACAD,mBAAmB,CAACD,0BAAD,CAAnB;EAEA,MAAMG,sBAAsB,GAAGjB,QAAQ,CAACkB,eAAT,IAA4B,EAA3D;EACAb,SAAS,CAAE,2BAA0BG,IAAI,CAACC,SAAL,CAAeQ,sBAAf,CAAuC,EAAnE,CAAT;EAEAA,sBAAsB,CAACE,OAAvB,CAA+BC,OAAO,IAAI;IACxCF,eAAe,CAACE,OAAD,CAAf;EACD,CAFD;EAIAC,cAAc,CAACrB,QAAQ,CAACqB,cAAV,CAAd;EAEA,OAAOX,SAAS,CAACY,Q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G;EACxC9E,eAAe,EAAE0E;AADuB,CAAnC;;AAIA,MAAMK,8BAA8B,GAAG;EAC5C/E,eAAe,EAAE0E;AAD2B,CAAvC;;AAIA,MAAMM,6BAA6B,GAAG;EAC3C7E,cAAc,EAAE;AAD2B,CAAtC"}
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+
3
+ var _chai = require("chai");
4
+
5
+ var _fixura = _interopRequireWildcard(require("@natlibfi/fixura"));
6
+
7
+ var _marcRecord = require("@natlibfi/marc-record");
8
+
9
+ var _fix = require("./fix");
10
+
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+
15
+ /**
16
+ *
17
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
18
+ *
19
+ * Shared modules for microservices of Melinda rest api batch import system
20
+ *
21
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
22
+ *
23
+ * This file is part of melinda-rest-api-commons
24
+ *
25
+ * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
26
+ * it under the terms of the GNU Affero General Public License as
27
+ * published by the Free Software Foundation, either version 3 of the
28
+ * License, or (at your option) any later version.
29
+ *
30
+ * melinda-rest-api-commons is distributed in the hope that it will be useful,
31
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
+ * GNU Affero General Public License for more details.
34
+ *
35
+ * You should have received a copy of the GNU Affero General Public License
36
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
37
+ *
38
+ * @licend The above is the entire license notice
39
+ * for the JavaScript code in this file.
40
+ *
41
+ */
42
+ //import {createDebugLogger} from 'debug';
43
+ describe('services/fix', () => {
44
+ const FIXTURES_PATH = [__dirname, '..', '..', 'test-fixtures', 'format'];
45
+ const {
46
+ getFixture
47
+ } = (0, _fixura.default)({
48
+ root: FIXTURES_PATH,
49
+ reader: _fixura.READERS.JSON
50
+ });
51
+ describe('Undefined options', () => {
52
+ it(`Should not update link subfield prefixes if options are undefined`, () => {
53
+ const record = new _marcRecord.MarcRecord(getFixture({
54
+ components: ['in', 'fiAsteriN0Fin11.json']
55
+ }));
56
+ const result = (0, _fix.fixRecord)(record.toObject(), undefined);
57
+ const expected = getFixture({
58
+ components: ['in', 'fiAsteriN0Fin11.json']
59
+ });
60
+ (0, _chai.expect)(result).to.eql(expected);
61
+ });
62
+ });
63
+ describe('fiAsteriN0Fin11', () => {
64
+ it('Should succeed', () => {
65
+ const record = new _marcRecord.MarcRecord(getFixture({
66
+ components: ['in', 'fiAsteriN0Fin11.json']
67
+ }));
68
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_FORMAT_SETTINGS);
69
+ const expected = getFixture({
70
+ components: ['out', 'fiAsteriN0Fin11.json']
71
+ });
72
+ (0, _chai.expect)(result).to.eql(expected);
73
+ });
74
+ });
75
+ describe('fiAsteriS0Fin10', () => {
76
+ it('Should succeed', () => {
77
+ const record = new _marcRecord.MarcRecord(getFixture({
78
+ components: ['in', 'fiAsteriS0Fin10.json']
79
+ }));
80
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_FORMAT_SETTINGS);
81
+ const expected = getFixture({
82
+ components: ['out', 'fiAsteriS0Fin10.json']
83
+ });
84
+ (0, _chai.expect)(result).to.eql(expected);
85
+ });
86
+ });
87
+ describe('fiMelindaWFin01', () => {
88
+ it('Should succeed', () => {
89
+ const record = new _marcRecord.MarcRecord(getFixture({
90
+ components: ['in', 'fiMelindaWFin01.json']
91
+ }));
92
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_FORMAT_SETTINGS);
93
+ const expected = getFixture({
94
+ components: ['out', 'fiMelindaWFin01.json']
95
+ });
96
+ (0, _chai.expect)(result).to.eql(expected);
97
+ });
98
+ });
99
+ describe('f035fibtj', () => {
100
+ it('Should add FI-BTJ SID', () => {
101
+ const record = new _marcRecord.MarcRecord(getFixture({
102
+ components: ['in', 'f035fibtj.json']
103
+ }));
104
+ const result = (0, _fix.fixRecord)(record.toObject(), {
105
+ generateMissingSIDs: _fix.BIB_F035_TO_SID
106
+ });
107
+ const expected = getFixture({
108
+ components: ['out', 'f035fibtj.json']
109
+ });
110
+ (0, _chai.expect)(result).to.eql(expected);
111
+ });
112
+ });
113
+ describe('f035tati', () => {
114
+ it('Should add tati SID', () => {
115
+ const record = new _marcRecord.MarcRecord(getFixture({
116
+ components: ['in', 'f035tati.json']
117
+ }));
118
+ const result = (0, _fix.fixRecord)(record.toObject(), {
119
+ generateMissingSIDs: _fix.BIB_F035_TO_SID
120
+ });
121
+ const expected = getFixture({
122
+ components: ['out', 'f035tati.json']
123
+ });
124
+ (0, _chai.expect)(result).to.eql(expected);
125
+ });
126
+ });
127
+ describe('f035fibtjAndTati', () => {
128
+ it('Should add tati SID and skip FI-BTJ SID', () => {
129
+ const record = new _marcRecord.MarcRecord(getFixture({
130
+ components: ['in', 'f035fibtjAndTati.json']
131
+ }));
132
+ const result = (0, _fix.fixRecord)(record.toObject(), {
133
+ generateMissingSIDs: _fix.BIB_F035_TO_SID
134
+ });
135
+ const expected = getFixture({
136
+ components: ['out', 'f035fibtjAndTati.json']
137
+ }); // eslint-disable-next-line no-console
138
+ //console.log(`result: ${JSON.stringify(result)}`);
139
+ // eslint-disable-next-line no-console
140
+ //console.log(`expect: ${JSON.stringify(expected)}`);
141
+
142
+ (0, _chai.expect)(result).to.eql(expected);
143
+ });
144
+ });
145
+ describe('f035tati', () => {
146
+ it('Should NOT add tati SID with undefined options', () => {
147
+ const record = new _marcRecord.MarcRecord(getFixture({
148
+ components: ['in', 'f035tati.json']
149
+ }));
150
+ const result = (0, _fix.fixRecord)(record.toObject(), undefined);
151
+ const expected = getFixture({
152
+ components: ['in', 'f035tati.json']
153
+ });
154
+ (0, _chai.expect)(result).to.eql(expected);
155
+ });
156
+ });
157
+ describe('bib-prevalidation-fix -settings', () => {
158
+ it('Should add missing SIDs, but not handle sf $0s when running with BIB_PREVALIDATION_FIX_SETTINGS', () => {
159
+ const record = new _marcRecord.MarcRecord(getFixture({
160
+ components: ['in', 'f035tatiAndFin11-for-prevalidation.json']
161
+ }));
162
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_PREVALIDATION_FIX_SETTINGS);
163
+ const expected = getFixture({
164
+ components: ['out', 'f035tatiAndFin11-for-prevalidation.json']
165
+ });
166
+ (0, _chai.expect)(result).to.eql(expected);
167
+ });
168
+ });
169
+ describe('bib-postvalidation-fix -settings', () => {
170
+ it('Should handle link subfields, but not add missing SIDs, when running with BIB_PREIMPORT_FIX_SETTINGS', () => {
171
+ const record = new _marcRecord.MarcRecord(getFixture({
172
+ components: ['in', 'f035tatiAndFin11-for-postvalidation.json']
173
+ }));
174
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_PREIMPORT_FIX_SETTINGS);
175
+ const expected = getFixture({
176
+ components: ['out', 'f035tatiAndFin11-for-postvalidation.json']
177
+ });
178
+ (0, _chai.expect)(result).to.eql(expected);
179
+ });
180
+ });
181
+ describe('handle tempURNs', () => {
182
+ it('It should do nothing if there are not tempURNs', () => {
183
+ const record = new _marcRecord.MarcRecord(getFixture({
184
+ components: ['in', 'tempUrnNoTemp.json']
185
+ }));
186
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_HANDLE_TEMP_URNS_SETTINGS);
187
+ const expected = getFixture({
188
+ components: ['out', 'tempUrnNoTemp.json']
189
+ });
190
+ (0, _chai.expect)(result).to.eql(expected);
191
+ });
192
+ it('It should find a single tempURN and remove the temp subfield', () => {
193
+ const record = new _marcRecord.MarcRecord(getFixture({
194
+ components: ['in', 'tempUrnWithTemp.json']
195
+ }));
196
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_HANDLE_TEMP_URNS_SETTINGS);
197
+ const expected = getFixture({
198
+ components: ['out', 'tempUrnWithTemp.json']
199
+ });
200
+ (0, _chai.expect)(result).to.eql(expected);
201
+ });
202
+ it('It should find a tempURN and an existing legal deposit URN and remove the tempURN', () => {
203
+ const record = new _marcRecord.MarcRecord(getFixture({
204
+ components: ['in', 'tempUrnWithTempAndLD.json']
205
+ }));
206
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_HANDLE_TEMP_URNS_SETTINGS);
207
+ const expected = getFixture({
208
+ components: ['out', 'tempUrnWithTempAndLD.json']
209
+ });
210
+ (0, _chai.expect)(result).to.eql(expected);
211
+ });
212
+ it('It should find a tempURN and an existing non-legal deposit URN and remove the temp subfields from tempURN', () => {
213
+ const record = new _marcRecord.MarcRecord(getFixture({
214
+ components: ['in', 'tempUrnWithTempAndNoLD.json']
215
+ }));
216
+ const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_HANDLE_TEMP_URNS_SETTINGS);
217
+ const expected = getFixture({
218
+ components: ['out', 'tempUrnWithTempAndNoLD.json']
219
+ });
220
+ (0, _chai.expect)(result).to.eql(expected);
221
+ });
222
+ });
223
+ });
224
+ //# sourceMappingURL=fix.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix.spec.js","names":["describe","FIXTURES_PATH","__dirname","getFixture","fixtureFactory","root","reader","READERS","JSON","it","record","MarcRecord","components","result","fixRecord","toObject","undefined","expected","expect","to","eql","BIB_FORMAT_SETTINGS","generateMissingSIDs","BIB_F035_TO_SID","BIB_PREVALIDATION_FIX_SETTINGS","BIB_PREIMPORT_FIX_SETTINGS","BIB_HANDLE_TEMP_URNS_SETTINGS"],"sources":["../../src/helpers/fix.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport fixtureFactory, {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {fixRecord, BIB_FORMAT_SETTINGS, BIB_F035_TO_SID, BIB_PREVALIDATION_FIX_SETTINGS, BIB_PREIMPORT_FIX_SETTINGS, BIB_HANDLE_TEMP_URNS_SETTINGS} from './fix';\n//import {createDebugLogger} from 'debug';\n\ndescribe('services/fix', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'format'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});\n\n describe('Undefined options', () => {\n it(`Should not update link subfield prefixes if options are undefined`, () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n }));\n const result = fixRecord(record.toObject(), undefined);\n const expected = getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n\n describe('fiAsteriN0Fin11', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriN0Fin11.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiAsteriS0Fin10', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriS0Fin10.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriS0Fin10.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiMelindaWFin01', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiMelindaWFin01.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiMelindaWFin01.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtj', () => {\n it('Should add FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtj.json'\n ]\n }));\n const result = fixRecord(record.toObject(), {generateMissingSIDs: BIB_F035_TO_SID});\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtj.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035tati', () => {\n it('Should add tati SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n }));\n const result = fixRecord(record.toObject(), {generateMissingSIDs: BIB_F035_TO_SID});\n const expected = getFixture({\n components: [\n 'out',\n 'f035tati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtjAndTati', () => {\n it('Should add tati SID and skip FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtjAndTati.json'\n ]\n }));\n const result = fixRecord(record.toObject(), {generateMissingSIDs: BIB_F035_TO_SID});\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtjAndTati.json'\n ]\n });\n // eslint-disable-next-line no-console\n //console.log(`result: ${JSON.stringify(result)}`);\n // eslint-disable-next-line no-console\n //console.log(`expect: ${JSON.stringify(expected)}`);\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035tati', () => {\n it('Should NOT add tati SID with undefined options', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n }));\n const result = fixRecord(record.toObject(), undefined);\n const expected = getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('bib-prevalidation-fix -settings', () => {\n it('Should add missing SIDs, but not handle sf $0s when running with BIB_PREVALIDATION_FIX_SETTINGS', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tatiAndFin11-for-prevalidation.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_PREVALIDATION_FIX_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'f035tatiAndFin11-for-prevalidation.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n\n describe('bib-postvalidation-fix -settings', () => {\n it('Should handle link subfields, but not add missing SIDs, when running with BIB_PREIMPORT_FIX_SETTINGS', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tatiAndFin11-for-postvalidation.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_PREIMPORT_FIX_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'f035tatiAndFin11-for-postvalidation.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('handle tempURNs', () => {\n it('It should do nothing if there are not tempURNs', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'tempUrnNoTemp.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_HANDLE_TEMP_URNS_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'tempUrnNoTemp.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n\n it('It should find a single tempURN and remove the temp subfield', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'tempUrnWithTemp.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_HANDLE_TEMP_URNS_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'tempUrnWithTemp.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n\n it('It should find a tempURN and an existing legal deposit URN and remove the tempURN', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'tempUrnWithTempAndLD.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_HANDLE_TEMP_URNS_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'tempUrnWithTempAndLD.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n\n it('It should find a tempURN and an existing non-legal deposit URN and remove the temp subfields from tempURN', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'tempUrnWithTempAndNoLD.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_HANDLE_TEMP_URNS_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'tempUrnWithTempAndNoLD.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n});\n"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA;AAEAA,QAAQ,CAAC,cAAD,EAAiB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AAsBH,QAAtB;IACD,CAhBC,CAAF;EAiBD,CAxEO,CAAR;AA0ED,CAjSO,CAAR"}
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var _exportNames = {
9
9
  amqpFactory: true,
10
10
  conversions: true,
11
11
  validations: true,
12
- format: true,
12
+ fixes: true,
13
13
  logError: true,
14
14
  createImportJobState: true,
15
15
  createImportJobStateForQuery: true,
@@ -52,7 +52,7 @@ Object.defineProperty(exports, "createRecordResponseItem", {
52
52
  return _utils.createRecordResponseItem;
53
53
  }
54
54
  });
55
- exports.format = void 0;
55
+ exports.fixes = void 0;
56
56
  Object.defineProperty(exports, "logError", {
57
57
  enumerable: true,
58
58
  get: function () {
@@ -88,9 +88,9 @@ var _conversion = _interopRequireDefault(require("./helpers/conversion"));
88
88
 
89
89
  var _validation = _interopRequireDefault(require("./helpers/validation"));
90
90
 
91
- var format = _interopRequireWildcard(require("./helpers/format"));
91
+ var fixes = _interopRequireWildcard(require("./helpers/fix"));
92
92
 
93
- exports.format = format;
93
+ exports.fixes = fixes;
94
94
 
95
95
  var _utils = require("./utils");
96
96
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport mongoFactory from './mongo';\nimport mongoLogFactory from './mongoLog';\nimport amqpFactory from './amqp';\nimport conversions from './helpers/conversion';\nimport validations from './helpers/validation';\nimport * as format from './helpers/format';\nimport {logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem} from './utils';\n\nexport {mongoFactory, mongoLogFactory, amqpFactory, conversions, validations, format, logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem};\nexport * from './constants';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AACA;;AAGA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport mongoFactory from './mongo';\nimport mongoLogFactory from './mongoLog';\nimport amqpFactory from './amqp';\nimport conversions from './helpers/conversion';\nimport validations from './helpers/validation';\nimport * as fixes from './helpers/fix';\nimport {logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem} from './utils';\n\nexport {mongoFactory, mongoLogFactory, amqpFactory, conversions, validations, fixes, logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem};\nexport * from './constants';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AACA;;AAGA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
package/dist/utils.js CHANGED
@@ -100,9 +100,9 @@ function createRecordResponseItem({
100
100
 
101
101
 
102
102
  function getRecordResponseStatusAndMessage(responseStatus, responsePayload, id) {
103
- logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);
104
- const responseStatusName = _httpStatus.default[`${responseStatus}_NAME`];
105
- logger.debug(`Response status name: ${responseStatusName}`);
103
+ logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`); //const responseStatusName = httpStatus[`${responseStatus}_NAME`];
104
+ //logger.debug(`Response status name: ${responseStatusName}`);
105
+
106
106
  const message = getMessageFromResponsePayload(responsePayload);
107
107
  const ids = responsePayload.ids || [];
108
108
  logger.debug(`Response message: ${message}`); // We map responseStatus here for a wider recordStatus and more detailed detailedRecordStatus
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["logger","createLogger","logError","err","ApiError","error","JSON","stringify","stack","undefined","createImportJobState","operation","state","queryImportJobState","IMPORT_JOB_STATE","Error","OPERATIONS","importJobStateWithOperation","importJobStateForQuery","createRecordResponseItem","responsePayload","responseStatus","recordMetadata","id","recordResponseStatusAndMessage","getRecordResponseStatusAndMessage","recordResponseItem","databaseId","debug","responseStatusName","httpStatus","message","getMessageFromResponsePayload","ids","includes","recordStatus","detailedRecordStatus","CONFLICT","test","length","UNPROCESSABLE_ENTITY","NOT_FOUND","String","addRecordResponseItem","correlationId","mongoOperator","pushMessages","messages","messageField"],"sources":["../src/utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {IMPORT_JOB_STATE, OPERATIONS} from './constants';\nimport httpStatus from 'http-status';\n\nconst logger = createLogger();\n\nexport function logError(err) {\n if (err instanceof ApiError) {\n logger.error(JSON.stringify(err));\n return;\n }\n\n if (err === 'SIGINT') {\n logger.error(err);\n return;\n }\n\n logger.error(err.stack === undefined ? err : err.stack);\n}\n\nexport function createImportJobState(operation, state, queryImportJobState = false) {\n if (!(state in IMPORT_JOB_STATE)) {\n throw new Error('Invalid IMPORT_JOB_STATE');\n }\n\n if (!(operation in OPERATIONS)) {\n throw new Error('Invalid operation');\n }\n\n if (queryImportJobState) {\n const importJobStateWithOperation = `importJobState.${operation}`;\n const importJobStateForQuery = {[importJobStateWithOperation]: state};\n\n return importJobStateForQuery;\n }\n\n return {[operation]: state};\n}\n\nexport function createRecordResponseItem({responsePayload, responseStatus, recordMetadata, id}) {\n const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload, id);\n const recordResponseItem = {\n databaseId: id || '000000000',\n recordMetadata: responsePayload.recordMetadata || recordMetadata || undefined,\n ...recordResponseStatusAndMessage\n };\n return recordResponseItem;\n}\n\n// eslint-disable-next-line max-statements\nfunction getRecordResponseStatusAndMessage(responseStatus, responsePayload, id) {\n\n logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);\n const responseStatusName = httpStatus[`${responseStatus}_NAME`];\n logger.debug(`Response status name: ${responseStatusName}`);\n\n const message = getMessageFromResponsePayload(responsePayload);\n const ids = responsePayload.ids || [];\n\n logger.debug(`Response message: ${message}`);\n\n // We map responseStatus here for a wider recordStatus and more detailed detailedRecordStatus\n // recordStatus corresponds to RECORD_IMPORT_STATEs used in https://github.com/NatLibFi/melinda-record-import-commons-js\n\n // Non-http statuses\n if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'SKIPPED'].includes(responseStatus)) {\n return {recordStatus: responseStatus, detailedRecordStatus: responseStatus, message};\n }\n\n if (['UNKNOWN'].includes(responseStatus)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: responseStatus, message, ids};\n }\n\n // Duplicates and other CONFLICT statuses\n if ([httpStatus.CONFLICT, 'CONFLICT'].includes(responseStatus)) {\n if ((/^Duplicates in database/u).test(message)) {\n return {recordStatus: 'DUPLICATE', detailedRecordStatus: 'DUPLICATE', message, ids};\n }\n if ((/^MatchValidation for all/u).test(message)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message, ids};\n }\n\n // Use ids only if there are more than one id or the id in payload does not match databaseId\n if (ids.length > 1 || ids[0] !== id) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message, ids};\n }\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message};\n }\n\n if ([httpStatus.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {\n if (ids.length > 1 || ids[0] !== id) {\n return {recordStatus: 'INVALID', detailedRecordStatus: 'UNPROCESSABLE_ENTITY', message, ids};\n }\n return {recordStatus: 'INVALID', detailedRecordStatus: 'UNPROCESSABLE_ENTITY', message};\n }\n\n if ([httpStatus.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'NOT_FOUND', message};\n }\n\n // Otherwise\n return {recordStatus: 'ERROR', detailedRecordStatus: responseStatus, message};\n}\n\nfunction getMessageFromResponsePayload(responsePayload) {\n if (responsePayload.message) {\n return responsePayload.message;\n }\n if (typeof responsePayload === 'string' || responsePayload instanceof String) {\n return responsePayload;\n }\n return '';\n}\n\nexport async function addRecordResponseItem({recordResponseItem, correlationId, mongoOperator}) {\n await mongoOperator.pushMessages({correlationId, messages: [recordResponseItem], messageField: 'records'});\n return true;\n}\n\n"],"mappings":";;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA,MAAMA,MAAM,GAAG,IAAAC,mCAAA,GAAf;;AAEO,SAASC,QAAT,CAAkBC,GAAlB,EAAuB;EAC5B,IAAIA,GAAG,YAAYC,qBAAnB,EAA6B;IAC3BJ,MAAM,CAACK,KAAP,CAAaC,IAAI,CAACC,SAAL,CAAeJ,GAAf,CAAb;IACA;EACD;;EAED,IAAIA,GAAG,KAAK,QAAZ,EAAsB;IACpBH,MAAM,CAACK,KAAP,CAAaF,GAAb;IACA;EACD;;EAEDH,MAAM,CAACK,KAAP,CAAaF,GAAG,CAACK,KAAJ,KAAcC,SAAd,GAA0BN,GAA1B,GAAgCA,GAAG,CAACK,KAAjD;AACD;;AAEM,SAASE,oBAAT,CAA8BC,SAA9B,EAAyCC,K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gDsB,YAAY,EAAE;EAA9D,CAA3B,CAAN;EACA,OAAO,IAAP;AACD"}
1
+ {"version":3,"file":"utils.js","names":["logger","createLogger","logError","err","ApiError","error","JSON","stringify","stack","undefined","createImportJobState","operation","state","queryImportJobState","IMPORT_JOB_STATE","Error","OPERATIONS","importJobStateWithOperation","importJobStateForQuery","createRecordResponseItem","responsePayload","responseStatus","recordMetadata","id","recordResponseStatusAndMessage","getRecordResponseStatusAndMessage","recordResponseItem","databaseId","debug","message","getMessageFromResponsePayload","ids","includes","recordStatus","detailedRecordStatus","httpStatus","CONFLICT","test","length","UNPROCESSABLE_ENTITY","NOT_FOUND","String","addRecordResponseItem","correlationId","mongoOperator","pushMessages","messages","messageField"],"sources":["../src/utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {IMPORT_JOB_STATE, OPERATIONS} from './constants';\nimport httpStatus from 'http-status';\n\nconst logger = createLogger();\n\nexport function logError(err) {\n if (err instanceof ApiError) {\n logger.error(JSON.stringify(err));\n return;\n }\n\n if (err === 'SIGINT') {\n logger.error(err);\n return;\n }\n\n logger.error(err.stack === undefined ? err : err.stack);\n}\n\nexport function createImportJobState(operation, state, queryImportJobState = false) {\n if (!(state in IMPORT_JOB_STATE)) {\n throw new Error('Invalid IMPORT_JOB_STATE');\n }\n\n if (!(operation in OPERATIONS)) {\n throw new Error('Invalid operation');\n }\n\n if (queryImportJobState) {\n const importJobStateWithOperation = `importJobState.${operation}`;\n const importJobStateForQuery = {[importJobStateWithOperation]: state};\n\n return importJobStateForQuery;\n }\n\n return {[operation]: state};\n}\n\nexport function createRecordResponseItem({responsePayload, responseStatus, recordMetadata, id}) {\n const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload, id);\n const recordResponseItem = {\n databaseId: id || '000000000',\n recordMetadata: responsePayload.recordMetadata || recordMetadata || undefined,\n ...recordResponseStatusAndMessage\n };\n return recordResponseItem;\n}\n\n// eslint-disable-next-line max-statements\nfunction getRecordResponseStatusAndMessage(responseStatus, responsePayload, id) {\n\n logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);\n //const responseStatusName = httpStatus[`${responseStatus}_NAME`];\n //logger.debug(`Response status name: ${responseStatusName}`);\n\n const message = getMessageFromResponsePayload(responsePayload);\n const ids = responsePayload.ids || [];\n\n logger.debug(`Response message: ${message}`);\n\n // We map responseStatus here for a wider recordStatus and more detailed detailedRecordStatus\n // recordStatus corresponds to RECORD_IMPORT_STATEs used in https://github.com/NatLibFi/melinda-record-import-commons-js\n\n // Non-http statuses\n if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'SKIPPED'].includes(responseStatus)) {\n return {recordStatus: responseStatus, detailedRecordStatus: responseStatus, message};\n }\n\n if (['UNKNOWN'].includes(responseStatus)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: responseStatus, message, ids};\n }\n\n // Duplicates and other CONFLICT statuses\n if ([httpStatus.CONFLICT, 'CONFLICT'].includes(responseStatus)) {\n if ((/^Duplicates in database/u).test(message)) {\n return {recordStatus: 'DUPLICATE', detailedRecordStatus: 'DUPLICATE', message, ids};\n }\n if ((/^MatchValidation for all/u).test(message)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message, ids};\n }\n\n // Use ids only if there are more than one id or the id in payload does not match databaseId\n if (ids.length > 1 || ids[0] !== id) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message, ids};\n }\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message};\n }\n\n if ([httpStatus.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {\n if (ids.length > 1 || ids[0] !== id) {\n return {recordStatus: 'INVALID', detailedRecordStatus: 'UNPROCESSABLE_ENTITY', message, ids};\n }\n return {recordStatus: 'INVALID', detailedRecordStatus: 'UNPROCESSABLE_ENTITY', message};\n }\n\n if ([httpStatus.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'NOT_FOUND', message};\n }\n\n // Otherwise\n return {recordStatus: 'ERROR', detailedRecordStatus: responseStatus, message};\n}\n\nfunction getMessageFromResponsePayload(responsePayload) {\n if (responsePayload.message) {\n return responsePayload.message;\n }\n if (typeof responsePayload === 'string' || responsePayload instanceof String) {\n return responsePayload;\n }\n return '';\n}\n\nexport async function addRecordResponseItem({recordResponseItem, correlationId, mongoOperator}) {\n await mongoOperator.pushMessages({correlationId, messages: [recordResponseItem], messageField: 'records'});\n return true;\n}\n\n"],"mappings":";;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA,MAAMA,MAAM,GAAG,IAAAC,mCAAA,GAAf;;AAEO,SAASC,QAAT,CAAkBC,GAAlB,EAAuB;EAC5B,IAAIA,GAAG,YAAYC,qBAAnB,EAA6B;IAC3BJ,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eAAP;EACD;;EACD,OAAO,EAAP;AACD;;AAEM,eAAesB,qBAAf,CAAqC;EAAChB,kBAAD;EAAqBiB,aAArB;EAAoCC;AAApC,CAArC,EAAyF;EAC9F,MAAMA,aAAa,CAACC,YAAd,CAA2B;IAACF,aAAD;IAAgBG,QAAQ,EAAE,CAACpB,kBAAD,CAA1B;IAAgDqB,YAAY,EAAE;EAA9D,CAA3B,CAAN;EACA,OAAO,IAAP;AACD"}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
15
15
  },
16
16
  "license": "AGPL-3.0+",
17
- "version": "2.3.1-alpha.7",
17
+ "version": "2.3.2-alpha.2",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=14"
@@ -33,13 +33,14 @@
33
33
  "build": "babel src --source-maps --copy-files --delete-dir-on-start --out-dir=dist"
34
34
  },
35
35
  "dependencies": {
36
- "@natlibfi/marc-record": "^7.0.0",
36
+ "@natlibfi/marc-record": "^7.2.0-alpha.1",
37
37
  "@natlibfi/marc-record-serializers": "^8.1.0",
38
38
  "@natlibfi/marc-record-validate": "^7.0.1",
39
39
  "@natlibfi/marc-record-validators-melinda": "^9.0.9",
40
40
  "@natlibfi/melinda-backend-commons": "^2.0.5",
41
41
  "@natlibfi/melinda-commons": "^12.0.3",
42
42
  "amqplib": ">=0.8.0 <1.0.0",
43
+ "debug": "^4.3.4",
43
44
  "http-status": "^1.5.2",
44
45
  "moment": "^2.29.3",
45
46
  "mongo-sanitize": "^1.1.0",
@@ -1,148 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BIB_FORMAT_SETTINGS = void 0;
7
- exports.formatRecord = formatRecord;
8
-
9
- var _marcRecord = require("@natlibfi/marc-record");
10
-
11
- var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
12
-
13
- /**
14
- *
15
- * @licstart The following is the entire license notice for the JavaScript code in this file.
16
- *
17
- * Shared modules for microservices of Melinda rest api batch import system
18
- *
19
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
20
- *
21
- * This file is part of melinda-rest-api-commons
22
- *
23
- * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
24
- * it under the terms of the GNU Affero General Public License as
25
- * published by the Free Software Foundation, either version 3 of the
26
- * License, or (at your option) any later version.
27
- *
28
- * melinda-rest-api-commons is distributed in the hope that it will be useful,
29
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31
- * GNU Affero General Public License for more details.
32
- *
33
- * You should have received a copy of the GNU Affero General Public License
34
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
35
- *
36
- * @licend The above is the entire license notice
37
- * for the JavaScript code in this file.
38
- *
39
- */
40
- function formatRecord(record, settings = []) {
41
- const logger = (0, _melindaBackendCommons.createLogger)();
42
- logger.verbose('Applying formating');
43
-
44
- const newRecord = _marcRecord.MarcRecord.clone(record, {
45
- subfieldValues: false
46
- });
47
-
48
- generateMissingSIDs();
49
- settings.forEach(options => {
50
- replacePrefixes(options);
51
- });
52
- return newRecord.toObject(); // Replace prefix in all specified subfields
53
-
54
- function replacePrefixes(options) {
55
- const {
56
- oldPrefix,
57
- newPrefix,
58
- prefixReplaceCodes
59
- } = options;
60
- const pattern = `(${oldPrefix})`;
61
- const replacement = `(${newPrefix})`;
62
- newRecord.getDatafields().forEach(field => {
63
- field.subfields.filter(({
64
- code
65
- }) => prefixReplaceCodes.includes(code)).forEach(subfield => {
66
- subfield.value = subfield.value.replace(pattern, replacement); // eslint-disable-line functional/immutable-data
67
- });
68
- });
69
- }
70
-
71
- function generateMissingSIDs() {
72
- const f035Filters = [/^\(FI-BTJ\)/u, /^\(FI-TATI\)/u];
73
- const fSIDFilters = ['FI-BTJ', 'tati'];
74
- const f035s = f035ToSidInfo(newRecord.get(/^035$/u));
75
- const fSIDs = sidsToSidInfo(newRecord.get(/^SID$/u));
76
- const sidsToBeAdded = genNewSids(fSIDs.length === 0 ? f035s // test that SIDs are not there yet
77
- : f035s.filter(f035SidInfo => fSIDs.some(fSIDInfo => f035SidInfo.SID !== fSIDInfo.SID && f035SidInfo.value !== fSIDInfo.value))); // Add new SIDs
78
-
79
- return sidsToBeAdded.forEach(sidField => newRecord.insertField(sidField));
80
-
81
- function genNewSids(sidsToBeAdded) {
82
- return sidsToBeAdded.map(sidInfo => ({
83
- tag: 'SID',
84
- ind1: ' ',
85
- ind2: ' ',
86
- subfields: [{
87
- code: 'c',
88
- value: sidInfo.value
89
- }, {
90
- code: 'b',
91
- value: sidInfo.SID
92
- }]
93
- }));
94
- }
95
-
96
- function sidsToSidInfo(SIDs) {
97
- return SIDs.flatMap(({
98
- subfields
99
- }) => {
100
- const [SID] = subfields.filter(sub => sub.code === 'b' && fSIDFilters.includes(sub.value)).map(sub => sub.value);
101
- const [value] = subfields.filter(sub => sub.code === 'c' && sub.value !== undefined).map(sub => sub.value);
102
-
103
- if (SID && value) {
104
- return {
105
- SID,
106
- value
107
- };
108
- }
109
-
110
- return undefined;
111
- }).filter(value => value !== undefined);
112
- }
113
-
114
- function f035ToSidInfo(f035s) {
115
- return f035s.flatMap(({
116
- subfields
117
- }) => {
118
- const [wantedSub] = subfields.filter(sub => sub.code === 'a' && f035Filters.some(regexp => regexp.test(sub.value)));
119
-
120
- if (wantedSub) {
121
- return {
122
- SID: fSIDFilters[f035Filters.findIndex(regexp => regexp.test(wantedSub.value))],
123
- value: wantedSub.value.slice(wantedSub.value.indexOf(')') + 1)
124
- };
125
- }
126
-
127
- return undefined;
128
- }).filter(value => value !== undefined);
129
- }
130
- }
131
- } // If placed in config.js testing needs envs
132
-
133
-
134
- const BIB_FORMAT_SETTINGS = [{
135
- oldPrefix: 'FI-MELINDA',
136
- newPrefix: 'FIN01',
137
- prefixReplaceCodes: ['w']
138
- }, {
139
- oldPrefix: 'FI-ASTERI-S',
140
- newPrefix: 'FIN10',
141
- prefixReplaceCodes: ['0']
142
- }, {
143
- oldPrefix: 'FI-ASTERI-N',
144
- newPrefix: 'FIN11',
145
- prefixReplaceCodes: ['0']
146
- }];
147
- exports.BIB_FORMAT_SETTINGS = BIB_FORMAT_SETTINGS;
148
- //# sourceMappingURL=format.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.js","names":["formatRecord","record","settings","logger","createLogger","verbose","newRecord","MarcRecord","clone","subfieldValues","generateMissingSIDs","forEach","options","replacePrefixes","toObject","oldPrefix","newPrefix","prefixReplaceCodes","pattern","replacement","getDatafields","field","subfields","filter","code","includes","subfield","value","replace","f035Filters","fSIDFilters","f035s","f035ToSidInfo","get","fSIDs","sidsToSidInfo","sidsToBeAdded","genNewSids","length","f035SidInfo","some","fSIDInfo","SID","sidField","insertField","map","sidInfo","tag","ind1","ind2","SIDs","flatMap","sub","undefined","wantedSub","regexp","test","findIndex","slice","indexOf","BIB_FORMAT_SETTINGS"],"sources":["../../src/helpers/format.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport function formatRecord(record, settings = []) {\n const logger = createLogger();\n\n logger.verbose('Applying formating');\n const newRecord = MarcRecord.clone(record, {subfieldValues: false});\n\n generateMissingSIDs();\n\n settings.forEach(options => {\n replacePrefixes(options);\n });\n\n return newRecord.toObject();\n\n // Replace prefix in all specified subfields\n function replacePrefixes(options) {\n const {oldPrefix, newPrefix, prefixReplaceCodes} = options;\n const pattern = `(${oldPrefix})`;\n const replacement = `(${newPrefix})`;\n newRecord.getDatafields()\n .forEach(field => {\n field.subfields\n .filter(({code}) => prefixReplaceCodes.includes(code))\n .forEach(subfield => {\n subfield.value = subfield.value.replace(pattern, replacement); // eslint-disable-line functional/immutable-data\n });\n });\n }\n\n\n function generateMissingSIDs() {\n const f035Filters = [/^\\(FI-BTJ\\)/u, /^\\(FI-TATI\\)/u];\n const fSIDFilters = ['FI-BTJ', 'tati'];\n const f035s = f035ToSidInfo(newRecord.get(/^035$/u));\n const fSIDs = sidsToSidInfo(newRecord.get(/^SID$/u));\n\n const sidsToBeAdded = genNewSids(fSIDs.length === 0\n ? f035s\n // test that SIDs are not there yet\n : f035s.filter(f035SidInfo => fSIDs.some(fSIDInfo => f035SidInfo.SID !== fSIDInfo.SID && f035SidInfo.value !== fSIDInfo.value)));\n\n // Add new SIDs\n return sidsToBeAdded.forEach(sidField => newRecord.insertField(sidField));\n\n function genNewSids(sidsToBeAdded) {\n return sidsToBeAdded.map(sidInfo => ({tag: 'SID', ind1: ' ', ind2: ' ', subfields: [{code: 'c', value: sidInfo.value}, {code: 'b', value: sidInfo.SID}]}));\n }\n\n function sidsToSidInfo(SIDs) {\n return SIDs.flatMap(({subfields}) => {\n const [SID] = subfields.filter(sub => sub.code === 'b' && fSIDFilters.includes(sub.value)).map(sub => sub.value);\n const [value] = subfields.filter(sub => sub.code === 'c' && sub.value !== undefined).map(sub => sub.value);\n\n if (SID && value) {\n return {\n SID,\n value\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n\n function f035ToSidInfo(f035s) {\n return f035s.flatMap(({subfields}) => {\n const [wantedSub] = subfields.filter(sub => sub.code === 'a' && f035Filters.some(regexp => regexp.test(sub.value)));\n\n if (wantedSub) {\n return {\n SID: fSIDFilters[f035Filters.findIndex(regexp => regexp.test(wantedSub.value))],\n value: wantedSub.value.slice(wantedSub.value.indexOf(')') + 1)\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n }\n}\n\n// If placed in config.js testing needs envs\nexport const BIB_FORMAT_SETTINGS = [\n {\n oldPrefix: 'FI-MELINDA',\n newPrefix: 'FIN01',\n prefixReplaceCodes: ['w']\n },\n {\n oldPrefix: 'FI-ASTERI-S',\n newPrefix: 'FIN10',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-N',\n newPrefix: 'FIN11',\n prefixReplaceCodes: ['0']\n }\n];\n"],"mappings":";;;;;;;;AA4BA;;AACA;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKO,SAASA,YAAT,CAAsBC,MAAtB,EAA8BC,QAAQ,GAAG,EAAzC,EAA6C;EAClD,MAAMC,MAAM,GAAG,IAAAC,mCAAA,GAAf;EAEAD,MAAM,CAACE,OAAP,CAAe,oBAAf;;EACA,MAAMC,SAAS,GAAGC,sBAAA,CAAWC,KAAX,CAAiBP,MAAjB,EAAyB;IAACQ,cAAc,EAAE;EAAjB,CAAzB,CAAlB;;EAEAC,mBAAmB;EAEnBR,QAAQ,CAACS,OAAT,CAAiBC,OAAO,IAAI;IAC1BC,eAAe,CAACD,OAAD,CAAf;EACD,CAFD;EAIA,OAAON,SAAS,CAACQ,QAAV,EAAP,CAZkD,CAclD;;EACA,SAASD,eAAT,CAAyBD,OAAzB,EAAkC;IAChC,MAAM;MAACG,SAAD;MAAYC,SAAZ;MAAuBC;IAAvB,IAA6CL,OAAnD;IACA,MAAMM,OAAO,GAAI,IAAGH,SAAU,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G,IAAIA,GAAG,CAAC5B,IAAJ,KAAa,GAAb,IAAoBK,WAAW,CAACW,IAAZ,CAAiBe,MAAM,IAAIA,MAAM,CAACC,IAAP,CAAYJ,GAAG,CAACzB,KAAhB,CAA3B,CAA5C,CAApB;;QAEA,IAAI2B,SAAJ,EAAe;UACb,OAAO;YACLZ,GAAG,EAAEZ,WAAW,CAACD,WAAW,CAAC4B,SAAZ,CAAsBF,MAAM,IAAIA,MAAM,CAACC,IAAP,CAAYF,SAAS,CAAC3B,KAAtB,CAAhC,CAAD,CADX;YAELA,KAAK,EAAE2B,SAAS,CAAC3B,KAAV,CAAgB+B,KAAhB,CAAsBJ,SAAS,CAAC3B,KAAV,CAAgBgC,OAAhB,CAAwB,GAAxB,IAA+B,CAArD;UAFF,CAAP;QAID;;QAED,OAAON,SAAP;MACD,CAXM,EAWJ9B,MAXI,CAWGI,KAAK,IAAIA,KAAK,KAAK0B,SAXtB,CAAP;IAYD;EACF;AACF,C,CAED;;;AACO,MAAMO,mBAAmB,GAAG,CACjC;EACE7C,SAAS,EAAE,YADb;EAEEC,SAAS,EAAE,OAFb;EAGEC,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CADiC,EAMjC;EACEF,SAAS,EAAE,aADb;EAEEC,SAAS,EAAE,OAFb;EAGEC,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CANiC,EAWjC;EACEF,SAAS,EAAE,aADb;EAEEC,SAAS,EAAE,OAFb;EAGEC,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CAXiC,CAA5B"}
@@ -1,123 +0,0 @@
1
- "use strict";
2
-
3
- var _chai = require("chai");
4
-
5
- var _fixura = _interopRequireWildcard(require("@natlibfi/fixura"));
6
-
7
- var _marcRecord = require("@natlibfi/marc-record");
8
-
9
- var _format = require("./format");
10
-
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
-
13
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
-
15
- /**
16
- *
17
- * @licstart The following is the entire license notice for the JavaScript code in this file.
18
- *
19
- * Shared modules for microservices of Melinda rest api batch import system
20
- *
21
- * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
22
- *
23
- * This file is part of melinda-rest-api-commons
24
- *
25
- * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
26
- * it under the terms of the GNU Affero General Public License as
27
- * published by the Free Software Foundation, either version 3 of the
28
- * License, or (at your option) any later version.
29
- *
30
- * melinda-rest-api-commons is distributed in the hope that it will be useful,
31
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
- * GNU Affero General Public License for more details.
34
- *
35
- * You should have received a copy of the GNU Affero General Public License
36
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
37
- *
38
- * @licend The above is the entire license notice
39
- * for the JavaScript code in this file.
40
- *
41
- */
42
- describe('services/format', () => {
43
- const FIXTURES_PATH = [__dirname, '..', '..', 'test-fixtures', 'format'];
44
- const {
45
- getFixture
46
- } = (0, _fixura.default)({
47
- root: FIXTURES_PATH,
48
- reader: _fixura.READERS.JSON
49
- });
50
- describe('fiAsteriN0Fin11', () => {
51
- it('Should succeed', () => {
52
- const record = new _marcRecord.MarcRecord(getFixture({
53
- components: ['in', 'fiAsteriN0Fin11.json']
54
- }));
55
- const result = (0, _format.formatRecord)(record.toObject(), _format.BIB_FORMAT_SETTINGS);
56
- const expected = getFixture({
57
- components: ['out', 'fiAsteriN0Fin11.json']
58
- });
59
- (0, _chai.expect)(result).to.eql(expected);
60
- });
61
- });
62
- describe('fiAsteriS0Fin10', () => {
63
- it('Should succeed', () => {
64
- const record = new _marcRecord.MarcRecord(getFixture({
65
- components: ['in', 'fiAsteriS0Fin10.json']
66
- }));
67
- const result = (0, _format.formatRecord)(record.toObject(), _format.BIB_FORMAT_SETTINGS);
68
- const expected = getFixture({
69
- components: ['out', 'fiAsteriS0Fin10.json']
70
- });
71
- (0, _chai.expect)(result).to.eql(expected);
72
- });
73
- });
74
- describe('fiMelindaWFin01', () => {
75
- it('Should succeed', () => {
76
- const record = new _marcRecord.MarcRecord(getFixture({
77
- components: ['in', 'fiMelindaWFin01.json']
78
- }));
79
- const result = (0, _format.formatRecord)(record.toObject(), _format.BIB_FORMAT_SETTINGS);
80
- const expected = getFixture({
81
- components: ['out', 'fiMelindaWFin01.json']
82
- });
83
- (0, _chai.expect)(result).to.eql(expected);
84
- });
85
- });
86
- describe('f035fibtj', () => {
87
- it('Should add FI-BTJ SID', () => {
88
- const record = new _marcRecord.MarcRecord(getFixture({
89
- components: ['in', 'f035fibtj.json']
90
- }));
91
- const result = (0, _format.formatRecord)(record.toObject());
92
- const expected = getFixture({
93
- components: ['out', 'f035fibtj.json']
94
- });
95
- (0, _chai.expect)(result).to.eql(expected);
96
- });
97
- });
98
- describe('f035tati', () => {
99
- it('Should add tati SID', () => {
100
- const record = new _marcRecord.MarcRecord(getFixture({
101
- components: ['in', 'f035tati.json']
102
- }));
103
- const result = (0, _format.formatRecord)(record.toObject());
104
- const expected = getFixture({
105
- components: ['out', 'f035tati.json']
106
- });
107
- (0, _chai.expect)(result).to.eql(expected);
108
- });
109
- });
110
- describe('f035fibtjAndTati', () => {
111
- it('Should add tati SID and skip FI-BTJ SID', () => {
112
- const record = new _marcRecord.MarcRecord(getFixture({
113
- components: ['in', 'f035fibtjAndTati.json']
114
- }));
115
- const result = (0, _format.formatRecord)(record.toObject());
116
- const expected = getFixture({
117
- components: ['out', 'f035fibtjAndTati.json']
118
- });
119
- (0, _chai.expect)(result).to.eql(expected);
120
- });
121
- });
122
- });
123
- //# sourceMappingURL=format.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.spec.js","names":["describe","FIXTURES_PATH","__dirname","getFixture","fixtureFactory","root","reader","READERS","JSON","it","record","MarcRecord","components","result","formatRecord","toObject","BIB_FORMAT_SETTINGS","expected","expect","to","eql"],"sources":["../../src/helpers/format.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport fixtureFactory, {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {formatRecord, BIB_FORMAT_SETTINGS} from './format';\n\ndescribe('services/format', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'format'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});\n\n describe('fiAsteriN0Fin11', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriN0Fin11.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiAsteriS0Fin10', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriS0Fin10.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriS0Fin10.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiMelindaWFin01', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiMelindaWFin01.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiMelindaWFin01.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtj', () => {\n it('Should add FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtj.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtj.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035tati', () => {\n it('Should add tati SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035tati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtjAndTati', () => {\n it('Should add tati SID and skip FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtjAndTati.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtjAndTati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n});\n"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChC,MAAMC,aAAa,GAAG,CACpBC,SADoB,EAEpB,IAFoB,EAGpB,IAHoB,EAIpB,eAJoB,EAKpB,QALoB,CAAtB;EAOA,MAAM;IAACC;EAAD,IAAe,IAAAC,eAAA,EAAe;IAACC,IAAI,EAAEJ,aAAP;IAAsBK,MAAM,EAAEC,eAAA,CAAQC;EAAtC,CAAf,CAArB;EAEAR,QAAQ,CAAC,iBAAD,EAAoB,MAAM;IAChCS,EAAE,CAAC,gBAAD,EAAmB,MAAM;MACzB,MAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeR,UAAU,CAAC;QACvCS,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;MAD2B,CAAD,CAAzB,CAAf;MAMA,MAAMC,MAAM,GAAG,IAAAC,oBAAA,EAAaJ,MAAM,CAACK,QAAP,EAAb,EAAgCC,2BAAhC,CAAf;MACA,MAAMC,QAAQ,GAAGd,UAAU,CAAC;QAC1BS,UAAU,EAAE,CACV,KADU,EAEV,sBAFU;MADc,CAAD,CAA3B;MAOA,IAAAM,YAAA,EAAOL,MAAP,EAAeM,EAAf,CAAkBC,GAAlB,CAAsBH,QAAtB;IACD,CAhBC,CAAF;EAiBD,CAlBO,CAAR;EAoBAjB,QAAQ,CAAC,iBAAD,EAAoB,MAAM;IAChCS,EAAE,CAAC,gBAAD,EAAmB,MAAM;MACzB,MAAMC,MAAM,GAAG,IAAIC,sBAAJ,C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