@natlibfi/melinda-record-match-validator
Version:
Validates if two records matched by melinda-record-matching can be merged and sets merge priority
58 lines (53 loc) • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.check042 = check042;
exports.compare042 = compare042;
exports.get042 = get042;
var _debug = _interopRequireDefault(require("debug"));
var _utils = require("./utils");
var _collectUtils = require("./collectFunctions/collectUtils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
//import {compareArrayContent} from './compareUtils';
const debug = (0, _debug.default)('@natlibfi/melinda-record-match-validator:field042');
const debugDev = debug.extend('dev');
//const debugData = debug.extend('data');
function get042(record) {
return (0, _collectUtils.hasField)('042', record, _collectUtils.getSubfields, 'a');
}
function compare042Data(data1, data2) {
// Look for NatLibFi authentication codes (finb and finbd) from within 042$a subfields, and give one point for each of the two.
const score1 = score042Field(data1);
const score2 = score042Field(data2);
(0, _utils.nvdebug)(`042 scores: ${score1} vs ${score2}`, debugDev);
if (score1 > score2) {
return 'A';
}
if (score1 < score2) {
return 'B';
}
return true; // This test does not fail
function score042Field(authenticationCodes) {
(0, _utils.nvdebug)('FFS', debugDev);
(0, _utils.nvdebug)(authenticationCodes.join(', '), debugDev);
return (authenticationCodes.includes('finb') ? 1 : 0) + (authenticationCodes.includes('finbd') ? 1 : 0);
}
}
function compare042(recordValuesA, recordValuesB) {
const f042A = recordValuesA['042'];
const f042B = recordValuesB['042'];
debugDev('%o vs %o', f042A, f042B);
// We no longer use the generic functions as we are interested only in two specific values
return compare042Data(f042A, f042B);
//return compareArrayContent(f042A, f042B, true);
}
function check042({
record1,
record2
}) {
const data1 = get042(record1);
const data2 = get042(record2);
return compare042Data(data1, data2);
}
//# sourceMappingURL=field042.js.map