Skip to content

Commit

Permalink
Avoid duplicate links when relinking
Browse files Browse the repository at this point in the history
  • Loading branch information
kwahlin committed Nov 7, 2024
1 parent defe011 commit 72e410f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions whelktool/src/main/resources/bulk-change-scripts/merge.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import static whelk.JsonLd.ID_KEY
import static whelk.datatool.bulkchange.BulkJobDocument.DEPRECATE_KEY
import static whelk.datatool.bulkchange.BulkJobDocument.KEEP_KEY

List<String> deprecate = parameters.get(DEPRECATE_KEY)
String keep = parameters.get(KEEP_KEY)
List<String> deprecate = ["https://id.kb.se/term/sao/M%C3%84V1"]//parameters.get(DEPRECATE_KEY)
String keep = "https://id.kb.se/term/sao/M%C3%84V-NY" //parameters.get(KEEP_KEY)

Set<String> allObsoleteThingUris = synchronizedSet([] as Set<String>)
selectByIds(deprecate) { obsolete ->
Expand All @@ -21,6 +21,13 @@ selectByIds(deprecate) { obsolete ->
if (modified) {
depender.scheduleSave(loud: isLoudAllowed)
}
// Remove duplicate links
DocumentUtil.traverse(depender.graph) { value, path ->
if (value instanceof List) {
value.unique(true) { it instanceof Map ? it[ID_KEY] : it }
return new DocumentUtil.Nop()
}
}
}
allObsoleteThingUris.addAll(obsoleteThingUris)
}
Expand All @@ -30,7 +37,7 @@ selectByIds(deprecate) {
}

selectByIds([keep]) {
allObsoleteThingUris.each {uri ->
allObsoleteThingUris.each { uri ->
it.doc.addThingIdentifier(uri)
}
it.scheduleSave()
Expand Down

0 comments on commit 72e410f

Please sign in to comment.