From 0cb17c4a7e8304c5dc48b3789a5442920d84daba Mon Sep 17 00:00:00 2001 From: kwahlin Date: Tue, 12 Nov 2024 14:53:36 +0100 Subject: [PATCH 1/3] Handle URIs as strings instead of links in merge spec --- .../main/java/whelk/datatool/bulkchange/BulkJobDocument.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java b/whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java index 9c37cc774e..5b787183fc 100644 --- a/whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java +++ b/whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java @@ -65,6 +65,7 @@ public String key() { public static final String KEEP_KEY = "bulk:keep"; public static final String DEPRECATE_KEY = "bulk:deprecate"; public static final String SCRIPT_KEY = "bulk:script"; + private static final String RDF_VALUE = "value"; private static final List STATUS_PATH = List.of(JsonLd.GRAPH_KEY, 1, STATUS_KEY); private static final List UPDATE_TIMESTAMP_PATH = List.of(JsonLd.GRAPH_KEY, 1, SHOULD_UPDATE_TIMESTAMP_KEY); @@ -127,8 +128,8 @@ public Specification getSpecification() { get(spec, TARGET_FORM_KEY, Collections.emptyMap()) ); case SpecType.Merge -> new Specification.Merge( - get(spec, List.of(DEPRECATE_KEY, "*", ID_KEY), Collections.emptyList()), - get(spec, List.of(KEEP_KEY, ID_KEY), "") + get(spec, List.of(DEPRECATE_KEY, "*", RDF_VALUE), Collections.emptyList()), + get(spec, List.of(KEEP_KEY, RDF_VALUE), "") ); case SpecType.Other -> new Specification.Other( get(spec, SCRIPT_KEY, null), From 1c3d283974fac281fb284a6d45198da458eb981f Mon Sep 17 00:00:00 2001 From: kwahlin Date: Tue, 12 Nov 2024 15:22:31 +0100 Subject: [PATCH 2/3] Adjust topic subdivision script --- .../datatool/bulkchange/BulkJobDocument.java | 2 +- .../removeTopicSubdivision.groovy | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java b/whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java index 5b787183fc..0950a05746 100644 --- a/whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java +++ b/whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java @@ -65,7 +65,7 @@ public String key() { public static final String KEEP_KEY = "bulk:keep"; public static final String DEPRECATE_KEY = "bulk:deprecate"; public static final String SCRIPT_KEY = "bulk:script"; - private static final String RDF_VALUE = "value"; + public static final String RDF_VALUE = "value"; private static final List STATUS_PATH = List.of(JsonLd.GRAPH_KEY, 1, STATUS_KEY); private static final List UPDATE_TIMESTAMP_PATH = List.of(JsonLd.GRAPH_KEY, 1, SHOULD_UPDATE_TIMESTAMP_KEY); diff --git a/whelktool/src/main/resources/bulk-change-scripts/removeTopicSubdivision.groovy b/whelktool/src/main/resources/bulk-change-scripts/removeTopicSubdivision.groovy index dc625f1d42..8ebcaadbda 100644 --- a/whelktool/src/main/resources/bulk-change-scripts/removeTopicSubdivision.groovy +++ b/whelktool/src/main/resources/bulk-change-scripts/removeTopicSubdivision.groovy @@ -13,12 +13,14 @@ import whelk.util.DocumentUtil import static whelk.JsonLd.ID_KEY import static whelk.datatool.bulkchange.BulkJobDocument.DEPRECATE_KEY import static whelk.datatool.bulkchange.BulkJobDocument.KEEP_KEY +import static whelk.datatool.bulkchange.BulkJobDocument.RDF_VALUE -List deprecateLinks = asList(parameters.get(DEPRECATE_KEY)) -Map keepLink = parameters.get(KEEP_KEY) +List deprecateUris = asList(parameters.get(DEPRECATE_KEY)) +Map keepUri = parameters.get(KEEP_KEY) -deprecateLinks.each { deprecate -> - selectByIds([deprecate[ID_KEY]]) { obsoleteSubdivision -> +deprecateUris.each { deprecate -> + Map deprecateLink = [(ID_KEY): deprecate[RDF_VALUE]] + selectByIds([deprecateLink[ID_KEY]]) { obsoleteSubdivision -> selectByIds(obsoleteSubdivision.getDependers()) { depender -> Map thing = depender.graph[1] as Map @@ -31,14 +33,15 @@ deprecateLinks.each { deprecate -> var t = asList(value.get('termComponentList')) if (deprecate in t) { // TODO? add way to do this with an op? SplitReplace? [Replace, Insert]? - if (keepLink && path.size() > 1) { + if (keepUri && path.size() > 1) { + var keepLink = [(ID_KEY): keepUri[RDF_VALUE]] var parent = DocumentUtil.getAtPath(thing, path.dropRight(1)) if (parent instanceof List && !parent.contains(keepLink)) { parent.add(keepLink) } } - return mapSubject(value, t, deprecate) + return mapSubject(value, t, deprecateLink) } } return DocumentUtil.NOP From c3d6b32e6c37393c01e0e6126ccd8da473ac427b Mon Sep 17 00:00:00 2001 From: kwahlin Date: Tue, 12 Nov 2024 15:24:20 +0100 Subject: [PATCH 3/3] Change variable --- .../resources/bulk-change-scripts/removeTopicSubdivision.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whelktool/src/main/resources/bulk-change-scripts/removeTopicSubdivision.groovy b/whelktool/src/main/resources/bulk-change-scripts/removeTopicSubdivision.groovy index 8ebcaadbda..1c02b6f00a 100644 --- a/whelktool/src/main/resources/bulk-change-scripts/removeTopicSubdivision.groovy +++ b/whelktool/src/main/resources/bulk-change-scripts/removeTopicSubdivision.groovy @@ -31,7 +31,7 @@ deprecateUris.each { deprecate -> def modified = DocumentUtil.traverse(thing) { value, path -> if (value instanceof Map && value[JsonLd.TYPE_KEY] == 'ComplexSubject') { var t = asList(value.get('termComponentList')) - if (deprecate in t) { + if (deprecateLink in t) { // TODO? add way to do this with an op? SplitReplace? [Replace, Insert]? if (keepUri && path.size() > 1) { var keepLink = [(ID_KEY): keepUri[RDF_VALUE]]