Skip to content

Commit

Permalink
Add f110/710 generator that generates field from dc.contributor.group…
Browse files Browse the repository at this point in the history
…author information
  • Loading branch information
aatuny committed Nov 5, 2024
1 parent 869f98f commit 8cea33e
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/transform/convert/common/generate1xx.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,30 @@ export function generate100and700({getFieldValues}) {
}));
}
}

export function generate110and710({getFieldValues}) {
const groupAuthors = getFieldValues('dc.contributor.groupauthor');
if (groupAuthors.length === 0) {
return [];
}

const f100authors = getFieldValues(p => [
'dc.contributor.author',
'dc.creator'
].includes(p));


if (f100authors.length === 0) {
// Note: first of groupauthors goes to f110 and rest 710
return groupAuthors.map((ga, idx) => ({
tag: idx === 0 ? '110' : '710', ind1: '1', ind2: '',
subfields: [{code: 'a', value: `${ga},`}, {code: 'e', value: 'kirjoittaja.'}]
}));
}

// In case f100 is created, add all groupauthors to f710
return groupAuthors.map(ga => ({
tag: '710', ind1: '1', ind2: '',
subfields: [{code: 'a', value: `${ga},`}, {code: 'e', value: 'kirjoittaja.'}]
}));
}
24 changes: 24 additions & 0 deletions src/transform/convert/common/generate1xx.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {createValueInterface} from '../util';

// Run tests
generate100and700();
generate110and710();

// Test functions
function generate100and700() {
Expand All @@ -32,3 +33,26 @@ function generate100and700() {
expect(result).to.eql(output);
}
}

function generate110and710() {
generateTests({
callback,
path: [__dirname, '..', '..', '..', '..', 'test-fixtures', 'transform', 'convert', 'common', 'generate1xx', 'generate110and710'],
recurse: false,
useMetadataFile: true,
fixura: {
reader: READERS.JSON,
failWhenNotFound: true
}
});

function callback({getFixture}) {
const input = getFixture('input.json');
const output = getFixture('output.json');

const valueInterface = createValueInterface(input);

const result = fieldGenerator.generate110and710(valueInterface);
expect(result).to.eql(output);
}
}
3 changes: 2 additions & 1 deletion src/transform/convert/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import moment from 'moment';

import {generate007, generate008, generateLDR} from './common/generateControlFields';
import {generate020, generate024, generate040, generate041, generate042} from './common/generate0xx';
import {generate100and700} from './common/generate1xx';
import {generate100and700, generate110and710} from './common/generate1xx';
import {generate245, generate246, generate250, generate264} from './common/generate2xx';
import {generate300, generate336, generate337, generate338, generate341} from './common/generate3xx';
import {generate490} from './common/generate4xx';
Expand Down Expand Up @@ -40,6 +40,7 @@ export default ({harvestSource, fieldValueInterface, convertOpts = {}, numberOfF
generate041(fieldValueInterface),
generate042(),
generate100and700(fieldValueInterface),
generate110and710(fieldValueInterface),
generate245(fieldValueInterface),
generate246(fieldValueInterface),
generate250(fieldValueInterface),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"$": {
"schema": "dc",
"element": "creator",
"value": "Esimerkki, Erkki"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Does not generate f110/710 if dc.creator is available and there are no dc.contributor.groupauthor entries",
"only": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"$": {
"schema": "dc",
"element": "creator",
"value": "Esimerkki, Erkki"
}
},
{
"$": {
"schema": "dc",
"element": "contributor",
"qualifier": "groupauthor",
"value": "Ryhmä Foo"
}
},
{
"$": {
"schema": "dc",
"element": "contributor",
"qualifier": "groupauthor",
"value": "Ryhmä Bar"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Generate 710 for each dc.contributor.groupauthor if dc.creator is available",
"only": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"tag": "710", "ind1": "1", "ind2": "",
"subfields": [
{"code": "a", "value": "Ryhmä Foo,"},
{"code": "e", "value": "kirjoittaja."}
]
},
{
"tag": "710", "ind1": "1", "ind2": "",
"subfields": [
{"code": "a", "value": "Ryhmä Bar,"},
{"code": "e", "value": "kirjoittaja."}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"$": {
"schema": "dc",
"element": "contributor",
"qualifier": "groupauthor",
"value": "Ryhmä Foo"
}
},
{
"$": {
"schema": "dc",
"element": "contributor",
"qualifier": "groupauthor",
"value": "Ryhmä Bar"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Generate f110 from first dc.contributor.groupauthor and f710 other dc.contributor.groupauthors if dc.creator is not available",
"only": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"tag": "110", "ind1": "1", "ind2": "",
"subfields": [
{"code": "a", "value": "Ryhmä Foo,"},
{"code": "e", "value": "kirjoittaja."}
]
},
{
"tag": "710", "ind1": "1", "ind2": "",
"subfields": [
{"code": "a", "value": "Ryhmä Bar,"},
{"code": "e", "value": "kirjoittaja."}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"description": "Empty input produces empty array as output",
"only": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit 8cea33e

Please sign in to comment.