Skip to content

Commit

Permalink
Fix broken create script (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwahlin authored Dec 10, 2024
1 parent ec8ba88 commit 7820332
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 4 additions & 8 deletions whelktool/src/main/groovy/whelk/datatool/form/MatchForm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class MatchForm {

MatchForm(Map form, Whelk whelk) {
this.form = form
this.formBNodeIdToPath = collectFormBNodeIdToPath()
this.formBNodeIdToResourceIds = collectFormBNodeIdToResourceIds(whelk)
this.formBNodeIdToPath = collectFormBNodeIdToPath(form)
this.formBNodeIdToResourceIds = collectFormBNodeIdToResourceIds(form, whelk)
this.baseTypeToSubtypes = collectBaseTypeToSubtypes(whelk?.jsonld)
}

Expand Down Expand Up @@ -250,11 +250,7 @@ class MatchForm {
return getAtPath(form, [RECORD_KEY, BNODE_ID], "TEMP_ID")
}

private Map<String, Set<String>> collectFormBNodeIdToResourceIds(Whelk whelk) {
return collectFormBNodeIdToResourceIds(form, whelk)
}

private static Map<String, Set<String>> collectFormBNodeIdToResourceIds(Map form, Whelk whelk) {
static Map<String, Set<String>> collectFormBNodeIdToResourceIds(Map form, Whelk whelk) {
Map<String, Set<String>> nodeIdMappings = [:]

IdLoader idLoader = whelk ? new IdLoader(whelk.storage) : null
Expand Down Expand Up @@ -300,7 +296,7 @@ class MatchForm {
return nodeIdMappings
}

private Map<String, List> collectFormBNodeIdToPath() {
static Map<String, List> collectFormBNodeIdToPath(Map form) {
Map<String, List> nodeIdToPath = [:]
DocumentUtil.findKey(form, BNODE_ID) { nodeId, path ->
nodeIdToPath[(String) nodeId] = path.dropRight(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import whelk.Document
import whelk.datatool.form.Transform
import whelk.util.DocumentUtil

import static java.util.Collections.synchronizedSet;
Expand All @@ -10,19 +9,21 @@ import static whelk.JsonLd.RECORD_TYPE
import static whelk.JsonLd.THING_KEY
import static whelk.JsonLd.TYPE_KEY
import static whelk.datatool.bulkchange.BulkJobDocument.TARGET_FORM_KEY
import static whelk.datatool.form.MatchForm.collectFormBNodeIdToPath
import static whelk.datatool.form.MatchForm.collectFormBNodeIdToResourceIds
import static whelk.util.DocumentUtil.traverse

Map targetForm = parameters.get(TARGET_FORM_KEY)

Map<String, Set<String>> nodeIdMappings = Transform.collectNodeIdMappings(targetForm, getWhelk())
Map<String, Set<String>> nodeIdMappings = collectFormBNodeIdToResourceIds(targetForm, getWhelk())

if (nodeIdMappings.size() != 1) {
// Allow only one id list
return
}

def varyingNodeId = nodeIdMappings.keySet().find()
def varyingNodePath = Transform.collectNodeIdToPath(targetForm)[varyingNodeId]
def varyingNodePath = collectFormBNodeIdToPath(targetForm)[varyingNodeId]
def ids = nodeIdMappings.values().find()

if (varyingNodePath == [] || varyingNodePath == [RECORD_KEY]) {
Expand Down

0 comments on commit 7820332

Please sign in to comment.