diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateCsv.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateCsv.java index 4a751f0fe3..b66124561b 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateCsv.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ValidateCsv.java @@ -23,6 +23,7 @@ import java.io.OutputStream; import java.io.Reader; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -40,6 +41,9 @@ import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.annotation.documentation.Tags; import org.apache.nifi.components.AllowableValue; import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.PropertyValue; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.processor.AbstractProcessor; @@ -117,7 +121,7 @@ public class ValidateCsv extends AbstractProcessor { + allowedOperators.toString() + ". Note: cell processors cannot be nested except with Optional.") .required(true) .expressionLanguageSupported(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .addValidator(StandardValidators.NON_EMPTY_EL_VALIDATOR) .build(); public static final PropertyDescriptor HEADER = new PropertyDescriptor.Builder() @@ -209,6 +213,31 @@ public class ValidateCsv extends AbstractProcessor { return properties; } + @Override + protected Collection customValidate(ValidationContext context) { + + PropertyValue schemaProp = context.getProperty(SCHEMA); + String schema = schemaProp.getValue(); + String subject = SCHEMA.getName(); + + if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(schema)) { + return Collections.singletonList(new ValidationResult.Builder().subject(subject).input(schema).explanation("Expression Language Present").valid(true).build()); + } + // If no Expression Language is present, try parsing the schema + try { + this.parseSchema(schema); + } catch (Exception e) { + final List problems = new ArrayList<>(1); + problems.add(new ValidationResult.Builder().subject(subject) + .input(schema) + .valid(false) + .explanation("Error while parsing the schema: " + e.getMessage()) + .build()); + return problems; + } + return super.customValidate(context); + } + public CsvPreference getPreference(final ProcessContext context, final FlowFile flowFile) { // When going from the UI to Java, the characters are escaped so that what you // input is transferred over to Java as is. So when you type the characters "\" diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java index 21d14064c6..097aad879a 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java @@ -264,7 +264,9 @@ public class TestValidateCsv { runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n"); runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\""); runner.setProperty(ValidateCsv.HEADER, "false"); + runner.assertNotValid(); + // We runner.setProperty(ValidateCsv.SCHEMA, "RequireSubString(\"test\")"); runner.assertNotValid();