NIFI-10853 Allow UpdateAttribute dynamic property to validate nifi

expressions

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #6770
This commit is contained in:
Nissim Shiman 2022-12-07 20:32:06 +00:00 committed by Matthew Burgess
parent 4d3fcb6843
commit b7f7b411ef
No known key found for this signature in database
GPG Key ID: 05D3DEB8126DAD24
2 changed files with 11 additions and 11 deletions

View File

@ -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))
.dynamic(true)
.build();
} else {
return propertyBuilder
.build();
}
}
@Override

View File

@ -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());