From b7f7b411efca794d91892f0b1b06a143e024a2a6 Mon Sep 17 00:00:00 2001 From: Nissim Shiman Date: Wed, 7 Dec 2022 20:32:06 +0000 Subject: [PATCH] NIFI-10853 Allow UpdateAttribute dynamic property to validate nifi expressions Signed-off-by: Matthew Burgess This closes #6770 --- .../processors/attributes/UpdateAttribute.java | 15 ++++----------- .../update/attributes/TestUpdateAttribute.java | 7 +++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java index 3e39eadf2f..cea1b47412 100644 --- a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java +++ b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java @@ -233,21 +233,14 @@ public class UpdateAttribute extends AbstractProcessor implements Searchable { @Override protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) { - PropertyDescriptor.Builder propertyBuilder = new PropertyDescriptor.Builder() + return new PropertyDescriptor.Builder() .name(propertyDescriptorName) .required(false) + .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true)) .addValidator(StandardValidators.ATTRIBUTE_KEY_PROPERTY_NAME_VALIDATOR) .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) - .dynamic(true); - - if (stateful) { - return propertyBuilder - .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true)) - .build(); - } else { - return propertyBuilder - .build(); - } + .dynamic(true) + .build(); } @Override diff --git a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java index f2220100f6..65ed24c71f 100644 --- a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java +++ b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java @@ -151,6 +151,13 @@ public class TestUpdateAttribute { runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS).get(0).assertAttributeEquals("NewAttr", "3"); } + @Test + public void testAddAttributeWithIncorrectExpression() throws Exception { + final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); + runner.setProperty("NewId", "${UUID(}"); + runner.assertNotValid(); + } + @Test public void testBasicState() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());