use of org.apache.nifi.components.Validator in project kylo by Teradata.
the class ThriftConnectionPool method createMultipleFilesExistValidator.
/**
* Validates that one or more files exist, as specified in a single property.
*
* @return a validator which describes the result of the validation
*/
public static final Validator createMultipleFilesExistValidator() {
return new Validator() {
@Override
public ValidationResult validate(String subject, String input, ValidationContext context) {
final String[] files = input.split(",");
for (String filename : files) {
try {
final File file = new File(filename.trim());
final boolean valid = file.exists() && file.isFile();
if (!valid) {
final String message = "File " + file + " does not exist or is not a file";
return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation(message).build();
}
} catch (SecurityException e) {
final String message = "Unable to access " + filename + " due to " + e.getMessage();
return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation(message).build();
}
}
return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();
}
};
}
use of org.apache.nifi.components.Validator in project nifi by apache.
the class ControlRate method customValidate.
@Override
protected Collection<ValidationResult> customValidate(final ValidationContext context) {
final List<ValidationResult> validationResults = new ArrayList<>(super.customValidate(context));
final Validator rateValidator;
switch(context.getProperty(RATE_CONTROL_CRITERIA).getValue().toLowerCase()) {
case DATA_RATE:
rateValidator = StandardValidators.DATA_SIZE_VALIDATOR;
break;
case ATTRIBUTE_RATE:
rateValidator = StandardValidators.POSITIVE_LONG_VALIDATOR;
final String rateAttr = context.getProperty(RATE_CONTROL_ATTRIBUTE_NAME).getValue();
if (rateAttr == null) {
validationResults.add(new ValidationResult.Builder().subject(RATE_CONTROL_ATTRIBUTE_NAME.getName()).explanation("<Rate Controlled Attribute> property must be set if using <Rate Control Criteria> of 'attribute value'").build());
}
break;
case FLOWFILE_RATE:
default:
rateValidator = StandardValidators.POSITIVE_LONG_VALIDATOR;
break;
}
final ValidationResult rateResult = rateValidator.validate("Maximum Rate", context.getProperty(MAX_RATE).getValue(), context);
if (!rateResult.isValid()) {
validationResults.add(rateResult);
}
return validationResults;
}
use of org.apache.nifi.components.Validator in project nifi by apache.
the class ExtractText method customValidate.
@Override
protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
final List<ValidationResult> problems = new ArrayList<>(super.customValidate(validationContext));
// If the capture group zero is not going to be included, each dynamic property must have at least one group
final boolean includeCaptureGroupZero = validationContext.getProperty(INCLUDE_CAPTURE_GROUP_ZERO).getValue().equalsIgnoreCase("true");
getLogger().debug("Include capture group zero is " + includeCaptureGroupZero);
if (!includeCaptureGroupZero) {
final Validator oneGroupMinimumValidator = StandardValidators.createRegexValidator(1, 40, true);
for (Map.Entry<PropertyDescriptor, String> prop : validationContext.getProperties().entrySet()) {
PropertyDescriptor pd = prop.getKey();
if (pd.isDynamic()) {
String value = validationContext.getProperty(pd).getValue();
getLogger().debug("Evaluating dynamic property " + pd.getDisplayName() + " (" + pd.getName() + ") with value " + value);
ValidationResult result = oneGroupMinimumValidator.validate(pd.getDisplayName(), value, validationContext);
getLogger().debug("Validation result: " + result.toString());
if (!result.isValid()) {
problems.add(result);
}
}
}
}
return problems;
}
use of org.apache.nifi.components.Validator in project nifi by apache.
the class TestCSVValidators method testUnescapedSingleCharGoodChar.
@Test
public void testUnescapedSingleCharGoodChar() {
Validator validator = CSVValidators.UNESCAPED_SINGLE_CHAR_VALIDATOR;
ValidationContext mockContext = Mockito.mock(ValidationContext.class);
ValidationResult result = validator.validate("Delimiter", ",", mockContext);
assertTrue(result.isValid());
}
use of org.apache.nifi.components.Validator in project nifi by apache.
the class TestCSVValidators method testUnescapedSingleCharUnicodeChar.
@Test
public void testUnescapedSingleCharUnicodeChar() {
Validator validator = CSVValidators.UNESCAPED_SINGLE_CHAR_VALIDATOR;
ValidationContext mockContext = Mockito.mock(ValidationContext.class);
ValidationResult result = validator.validate("Delimiter", "\\u0001", mockContext);
assertTrue(result.isValid());
}
Aggregations