Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bulk merge uris as strings #1515

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
public static final String RDF_VALUE = "value";

private static final List<Object> STATUS_PATH = List.of(JsonLd.GRAPH_KEY, 1, STATUS_KEY);
private static final List<Object> UPDATE_TIMESTAMP_PATH = List.of(JsonLd.GRAPH_KEY, 1, SHOULD_UPDATE_TIMESTAMP_KEY);
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,16 +31,17 @@ deprecateLinks.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 (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
Expand Down
Loading