diff --git a/metafix/src/main/java/org/metafacture/metafix/Value.java b/metafix/src/main/java/org/metafacture/metafix/Value.java index 60458410..c7d5d3a7 100644 --- a/metafix/src/main/java/org/metafacture/metafix/Value.java +++ b/metafix/src/main/java/org/metafacture/metafix/Value.java @@ -269,7 +269,7 @@ enum Type { String } - /*private-private*/ static class TypeMatcher { + public static class TypeMatcher { private final Set<Type> expected = new HashSet<>(); private final Value value; diff --git a/metafix/src/main/java/org/metafacture/metafix/api/FixPredicate.java b/metafix/src/main/java/org/metafacture/metafix/api/FixPredicate.java index ce621656..a654af60 100644 --- a/metafix/src/main/java/org/metafacture/metafix/api/FixPredicate.java +++ b/metafix/src/main/java/org/metafacture/metafix/api/FixPredicate.java @@ -43,7 +43,10 @@ default boolean testConditional(final Record record, final List<String> params, final String string = params.get(1); final Value value = record.find(field); - return value != null && qualifier.test(value.asList(null).asArray().stream(), v -> conditional.test(v.toString(), string)); + return value != null && qualifier.test(value.asList(null).asArray().stream(), v -> v.extractType((m, c) -> m + .ifString(s -> c.accept(conditional.test(s, string))) + .orElse(w -> c.accept(false)) + )); } } diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java index d28bb1cd..a7c4db90 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixIfTest.java @@ -365,6 +365,46 @@ public void ifAnyMatchNested() { }); } + @Test + public void shouldNotImplicitlyMatchNestedField() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "if any_match('author.name', '.*University.*')", + " add_field('author.type', 'Organization')", + "end" + ), + i -> { + i.startRecord("1"); + i.startEntity("author"); + i.literal("name", "A University"); + i.endEntity(); + i.endRecord(); + + i.startRecord("2"); + i.startEntity("author"); + i.startEntity("name"); + i.literal("label", "Some University"); + i.endEntity(); + i.endEntity(); + i.endRecord(); + }, + (o, f) -> { + o.get().startRecord("1"); + o.get().startEntity("author"); + o.get().literal("name", "A University"); + o.get().literal("type", "Organization"); + o.get().endEntity(); + o.get().endRecord(); + + o.get().startRecord("2"); + o.get().startEntity("author"); + o.get().startEntity("name"); + o.get().literal("label", "Some University"); + f.apply(2).endEntity(); + o.get().endRecord(); + } + ); + } + @Test public void ifAnyMatchFirstRecord() { MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(