From 72e410ff654b2e79083e616f4b3b698d6a5fa98c Mon Sep 17 00:00:00 2001 From: kwahlin Date: Thu, 7 Nov 2024 11:48:46 +0100 Subject: [PATCH] Avoid duplicate links when relinking --- .../main/resources/bulk-change-scripts/merge.groovy | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/whelktool/src/main/resources/bulk-change-scripts/merge.groovy b/whelktool/src/main/resources/bulk-change-scripts/merge.groovy index 816348d52f..c55c3326d8 100644 --- a/whelktool/src/main/resources/bulk-change-scripts/merge.groovy +++ b/whelktool/src/main/resources/bulk-change-scripts/merge.groovy @@ -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 deprecate = parameters.get(DEPRECATE_KEY) -String keep = parameters.get(KEEP_KEY) +List 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 allObsoleteThingUris = synchronizedSet([] as Set) selectByIds(deprecate) { obsolete -> @@ -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) } @@ -30,7 +37,7 @@ selectByIds(deprecate) { } selectByIds([keep]) { - allObsoleteThingUris.each {uri -> + allObsoleteThingUris.each { uri -> it.doc.addThingIdentifier(uri) } it.scheduleSave()