Skip to content

Commit

Permalink
Do not use PrimaryContribution on instances
Browse files Browse the repository at this point in the history
When moving contributions to the instance, set them to type
Contribution, to avoid there being multiple primary (100) fields when
reverting to MARC.
  • Loading branch information
niklasl committed Aug 31, 2023
1 parent 263c22a commit 740d3dd
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
Expand All @@ -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'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
]
}
}
}
}
]
}

0 comments on commit 740d3dd

Please sign in to comment.