Skip to content

Commit

Permalink
Link role before trying to move to instance
Browse files Browse the repository at this point in the history
  • Loading branch information
kwahlin committed Sep 28, 2023
1 parent 2f758f5 commit 111f421
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package whelk.converter.marc

import groovy.transform.CompileStatic
import groovy.util.logging.Log4j2 as Log
import whelk.filter.BlankNodeLinker

import static whelk.JsonLd.asList

Expand All @@ -15,11 +16,17 @@ class ContributionByRoleStep extends MarcFramePostProcStepBase {

boolean requiresResources = true
Set<String> instanceRelators
BlankNodeLinker relatorLinker

void init() {
def relatorResources = resourceCache?.relatorResources

if (!relatorResources) return

relatorLinker = relatorResources.relatorLinker
// NOTE: Assuming OK to move role with a non-Instance Embodiment domain (Item
// or Representation) to Instance (an instance is an embodiment, a work isn't).
instanceRelators = resourceCache?.relators?.findResults {
instanceRelators = relatorResources.relators.findResults {
def domainRef = it.domain?[ID]
if (domainRef) {
def domain = ld.toTermKey(domainRef)
Expand All @@ -28,7 +35,7 @@ class ContributionByRoleStep extends MarcFramePostProcStepBase {
}
}
} as Set
log.debug "Using as instance relations: $INSTANCE_RELATORS"
log.debug "Using as instance relations: $instanceRelators"
}

void modify(Map record, Map thing) {
Expand All @@ -51,6 +58,7 @@ class ContributionByRoleStep extends MarcFramePostProcStepBase {
asList(work.contribution).each {
var instanceRoles = []
var workRoles = []
relatorLinker.linkAll(it, 'role')
asList(it.role).each {
if (it[ID] in instanceRelators) {
instanceRoles << it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
{
"role": [
{"@id": "https://id.kb.se/relator/publisher"}
{"code": "pbl"}
],
"@type": "Contribution",
"agent": {"@id": "y"}
Expand Down Expand Up @@ -78,7 +78,30 @@
]
}
},
"back": "source"
"back": {
"mainEntity": {
"@type": "Instance",
"instanceOf": {
"@type": "Text",
"contribution": [
{
"role": [
{"@id": "https://id.kb.se/relator/author"}
],
"@type": "Contribution",
"agent": {"@id": "x"}
},
{
"role": [
{"@id": "https://id.kb.se/relator/publisher"}
],
"@type": "Contribution",
"agent": {"@id": "y"}
}
]
}
}
}
},
{
"name": "Split publisher from author and move",
Expand Down

0 comments on commit 111f421

Please sign in to comment.