From 99361dd517b3162120cf554a5ae8617ffe9a54ca Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Wed, 16 Oct 2024 18:13:43 +0200 Subject: [PATCH] Ignore old value's path in `copy_field` Fix function. (#377) --- .../java/org/metafacture/metafix/FixMethod.java | 6 +++--- .../metafacture/metafix/MetafixMethodTest.java | 15 ++++++++++++--- .../todo.txt | 1 - 3 files changed, 15 insertions(+), 7 deletions(-) delete mode 100644 metafix/src/test/resources/org/metafacture/metafix/integration/method/fromXml/toJson/replace_allInOptionalSubfieldOfRepeatedObjectsWithAsteriskImplicitArray/todo.txt diff --git a/metafix/src/main/java/org/metafacture/metafix/FixMethod.java b/metafix/src/main/java/org/metafacture/metafix/FixMethod.java index 8eddcfe5..38e538fa 100644 --- a/metafix/src/main/java/org/metafacture/metafix/FixMethod.java +++ b/metafix/src/main/java/org/metafacture/metafix/FixMethod.java @@ -180,7 +180,7 @@ public void apply(final Metafix metafix, final Record record, final List h.forEach((subField, value) -> { record.addNested(field, new Value(subField)); - record.addNested(field, value); + record.addNested(field, value.withPathSet(null)); }); }))); } @@ -210,9 +210,9 @@ public void apply(final Metafix metafix, final Record record, final List oldValue.matchType() .ifArray(a -> { record.remove(newName); - a.forEach(v -> record.addNested(newName, v)); + a.forEach(v -> record.addNested(newName, v.withPathSet(null))); }) - .orElse(v -> record.set(newName, v)); + .orElse(v -> record.set(newName, v.withPathSet(null))); } } }, diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java index 8b167257..42e6985f 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java @@ -2188,10 +2188,9 @@ public void inDoBindCopyFieldWithVarInSourceAndTarget() { ); } - @Test - public void replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget() { + private void replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget(final boolean explicitArray) { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( - "set_array('RSWK[]')", + explicitArray ? "set_array('RSWK[]')" : "", "do list(path: '650??', 'var': '$i')", " copy_field('$i.a', 'RSWK[].$append.subjectTopicName')", " copy_field('$i.v', 'RSWK[].$last.subjectGenre')", @@ -2227,6 +2226,16 @@ public void replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget() { ); } + @Test + public void replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget() { + replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget(true); + } + + @Test + public void replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTargetImplicitArray() { + replaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget(false); + } + @Test public void multipleReplaceAllWithWildcardAfterCopyFieldWithVarInSourceAndTarget() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( diff --git a/metafix/src/test/resources/org/metafacture/metafix/integration/method/fromXml/toJson/replace_allInOptionalSubfieldOfRepeatedObjectsWithAsteriskImplicitArray/todo.txt b/metafix/src/test/resources/org/metafacture/metafix/integration/method/fromXml/toJson/replace_allInOptionalSubfieldOfRepeatedObjectsWithAsteriskImplicitArray/todo.txt deleted file mode 100644 index bb2574a2..00000000 --- a/metafix/src/test/resources/org/metafacture/metafix/integration/method/fromXml/toJson/replace_allInOptionalSubfieldOfRepeatedObjectsWithAsteriskImplicitArray/todo.txt +++ /dev/null @@ -1 +0,0 @@ -See issue #377