From 740d3ddb14d7b1ff1577a8840d7a235be98afcd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Lindstr=C3=B6m?= Date: Thu, 31 Aug 2023 15:28:34 +0200 Subject: [PATCH] Do not use PrimaryContribution on instances When moving contributions to the instance, set them to type Contribution, to avoid there being multiple primary (100) fields when reverting to MARC. --- .../marc/ContributionByRoleStep.groovy | 25 +++++-- .../marcframe-bib-postproc-contribution.json | 71 +++++++++++++++++++ 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/whelk-core/src/main/groovy/whelk/converter/marc/ContributionByRoleStep.groovy b/whelk-core/src/main/groovy/whelk/converter/marc/ContributionByRoleStep.groovy index f9b7d0dd00..365f5c50c2 100644 --- a/whelk-core/src/main/groovy/whelk/converter/marc/ContributionByRoleStep.groovy +++ b/whelk-core/src/main/groovy/whelk/converter/marc/ContributionByRoleStep.groovy @@ -58,14 +58,16 @@ class ContributionByRoleStep extends MarcFramePostProcStepBase { workRoles << it } } - def contrib = it.clone() + if (instanceRoles) { + def contrib = it.clone() contrib.role = instanceRoles + setToPlainContribution(contrib) instanceContribs << contrib - } else { - if (workRoles) { - contrib.role = workRoles - } + } + if (workRoles) { + def contrib = it.clone() + contrib.role = workRoles workContribs << contrib } } @@ -76,10 +78,12 @@ class ContributionByRoleStep extends MarcFramePostProcStepBase { } else { work.contribution = workContribs } + if (!instance.contribution) { instance.contribution = [] } instance.contribution += instanceContribs + return true } else { return false @@ -101,7 +105,14 @@ class ContributionByRoleStep extends MarcFramePostProcStepBase { } else if (work.contribution !instanceof List) { work.contribution = [work.contribution] } - work.contribution += asList(instance.contribution) - instance.remove('contribution') + var instanceContribs = asList(instance.remove('contribution')) + instanceContribs.each { setToPlainContribution(it) } + work.contribution += instanceContribs + } + + void setToPlainContribution(contrib) { + if (contrib[TYPE] != 'Contribution') { + contrib[TYPE] = 'Contribution' + } } } diff --git a/whelk-core/src/main/resources/ext/marcframe-bib-postproc-contribution.json b/whelk-core/src/main/resources/ext/marcframe-bib-postproc-contribution.json index 67b880e7b2..c053a00210 100644 --- a/whelk-core/src/main/resources/ext/marcframe-bib-postproc-contribution.json +++ b/whelk-core/src/main/resources/ext/marcframe-bib-postproc-contribution.json @@ -79,6 +79,77 @@ } }, "back": "source" + }, + { + "name": "Split publisher from author and move", + "source": { + "mainEntity": { + "@type": "Instance", + "instanceOf": { + "@type": "Text", + "contribution": [ + { + "role": [ + {"@id": "https://id.kb.se/relator/author"}, + {"@id": "https://id.kb.se/relator/publisher"} + ], + "@type": "PrimaryContribution", + "agent": {"@id": "x"} + } + ] + } + } + }, + "result": { + "mainEntity": { + "@type": "Instance", + "instanceOf": { + "@type": "Text", + "contribution": [ + { + "role": [ + {"@id": "https://id.kb.se/relator/author"} + ], + "@type": "PrimaryContribution", + "agent": {"@id": "x"} + } + ] + }, + "contribution": [ + { + "role": [ + {"@id": "https://id.kb.se/relator/publisher"} + ], + "@type": "Contribution", + "agent": {"@id": "x"} + } + ] + } + }, + "back": { + "mainEntity": { + "@type": "Instance", + "instanceOf": { + "@type": "Text", + "contribution": [ + { + "role": [ + {"@id": "https://id.kb.se/relator/author"} + ], + "@type": "PrimaryContribution", + "agent": {"@id": "x"} + }, + { + "role": [ + {"@id": "https://id.kb.se/relator/publisher"} + ], + "@type": "Contribution", + "agent": {"@id": "x"} + } + ] + } + } + } } ] }