org.apache.nifi.processor.util.StandardValidators Java Examples

The following examples show how to use org.apache.nifi.processor.util.StandardValidators. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestStandardValidators.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonEmptyELValidator() {
    Validator val = StandardValidators.NON_EMPTY_EL_VALIDATOR;
    ValidationContext vc = mock(ValidationContext.class);
    Mockito.when(vc.isExpressionLanguageSupported("foo")).thenReturn(true);

    ValidationResult vr = val.validate("foo", "", vc);
    assertFalse(vr.isValid());

    vr = val.validate("foo", "    h", vc);
    assertTrue(vr.isValid());

    Mockito.when(vc.isExpressionLanguagePresent("${test}")).thenReturn(true);
    vr = val.validate("foo", "${test}", vc);
    assertTrue(vr.isValid());

    vr = val.validate("foo", "${test", vc);
    assertTrue(vr.isValid());
}
 
Example #2
Source File: ExtractText.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: MergeContent.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected Collection<ValidationResult> additionalCustomValidation(ValidationContext context) {
    final Collection<ValidationResult> results = new ArrayList<>();

    final String delimiterStrategy = context.getProperty(DELIMITER_STRATEGY).getValue();
    if(DELIMITER_STRATEGY_FILENAME.equals(delimiterStrategy)) {
        final String headerValue = context.getProperty(HEADER).getValue();
        if (headerValue != null) {
            results.add(StandardValidators.FILE_EXISTS_VALIDATOR.validate(HEADER.getName(), headerValue, context));
        }

        final String footerValue = context.getProperty(FOOTER).getValue();
        if (footerValue != null) {
            results.add(StandardValidators.FILE_EXISTS_VALIDATOR.validate(FOOTER.getName(), footerValue, context));
        }

        final String demarcatorValue = context.getProperty(DEMARCATOR).getValue();
        if (demarcatorValue != null) {
            results.add(StandardValidators.FILE_EXISTS_VALIDATOR.validate(DEMARCATOR.getName(), demarcatorValue, context));
        }
    }
    return results;
}
 
Example #4
Source File: DistributeLoad.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    // validate that the property name is valid.
    final int numRelationships = this.relationshipsRef.get().size();
    try {
        final int value = Integer.parseInt(propertyDescriptorName);
        if (value <= 0 || value > numRelationships) {
            return new PropertyDescriptor.Builder()
                    .addValidator(new InvalidPropertyNameValidator(propertyDescriptorName)).name(propertyDescriptorName).build();
        }
    } catch (final NumberFormatException e) {
        return new PropertyDescriptor.Builder()
                .addValidator(new InvalidPropertyNameValidator(propertyDescriptorName)).name(propertyDescriptorName).build();
    }

    // validate that the property value is valid
    return new PropertyDescriptor.Builder().addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
            .name(propertyDescriptorName).dynamic(true).build();
}
 
Example #5
Source File: MergeContent.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected Collection<ValidationResult> additionalCustomValidation(ValidationContext context) {
    final Collection<ValidationResult> results = new ArrayList<>();

    final String delimiterStrategy = context.getProperty(DELIMITER_STRATEGY).getValue();
    if(DELIMITER_STRATEGY_FILENAME.equals(delimiterStrategy)) {
        final String headerValue = context.getProperty(HEADER).getValue();
        if (headerValue != null) {
            results.add(StandardValidators.FILE_EXISTS_VALIDATOR.validate(HEADER.getName(), headerValue, context));
        }

        final String footerValue = context.getProperty(FOOTER).getValue();
        if (footerValue != null) {
            results.add(StandardValidators.FILE_EXISTS_VALIDATOR.validate(FOOTER.getName(), footerValue, context));
        }

        final String demarcatorValue = context.getProperty(DEMARCATOR).getValue();
        if (demarcatorValue != null) {
            results.add(StandardValidators.FILE_EXISTS_VALIDATOR.validate(DEMARCATOR.getName(), demarcatorValue, context));
        }
    }
    return results;
}
 
Example #6
Source File: ReplaceText.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    final List<ValidationResult> errors = new ArrayList<>(super.customValidate(validationContext));

    switch (validationContext.getProperty(REPLACEMENT_STRATEGY).getValue()) {
        case literalReplaceValue:
            errors.add(StandardValidators.NON_EMPTY_VALIDATOR
                    .validate(SEARCH_VALUE.getName(), validationContext.getProperty(SEARCH_VALUE).getValue(), validationContext));
            break;

        case regexReplaceValue:
            errors.add(StandardValidators.createRegexValidator(0, Integer.MAX_VALUE, true)
                    .validate(SEARCH_VALUE.getName(), validationContext.getProperty(SEARCH_VALUE).getValue(), validationContext));
            break;

        case appendValue:
        case prependValue:
        case alwaysReplace:
        default:
            // nothing to check, search value is not used
            break;
    }

    return errors;
}
 
Example #7
Source File: DistributeLoad.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    // validate that the property name is valid.
    final int numRelationships = this.relationshipsRef.get().size();
    try {
        final int value = Integer.parseInt(propertyDescriptorName);
        if (value <= 0 || value > numRelationships) {
            return new PropertyDescriptor.Builder()
                    .addValidator(new InvalidPropertyNameValidator(propertyDescriptorName)).name(propertyDescriptorName).build();
        }
    } catch (final NumberFormatException e) {
        return new PropertyDescriptor.Builder()
                .addValidator(new InvalidPropertyNameValidator(propertyDescriptorName)).name(propertyDescriptorName).build();
    }

    // validate that the property value is valid
    return new PropertyDescriptor.Builder().addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
            .name(propertyDescriptorName).dynamic(true).build();
}
 
Example #8
Source File: ExecuteStreamCommand.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    if (!propertyDescriptorName.startsWith("command.argument.")) {
        return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .description(
                "Sets the environment variable '" + propertyDescriptorName + "' for the process' environment")
            .dynamic(true)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .build();
    }
    // get the number part of the name
    Matcher matcher = DYNAMIC_PARAMETER_NAME.matcher(propertyDescriptorName);
    if (matcher.matches()) {
        final String commandIndex = matcher.group("commandIndex");
        return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .displayName(propertyDescriptorName)
            .description("Argument passed to command")
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .addValidator(ATTRIBUTE_EXPRESSION_LANGUAGE_VALIDATOR)
            .build();
    }
    return null;
}
 
Example #9
Source File: InvokeHTTP.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName) {
    if (propertyDescriptorName.startsWith(FORM_BASE)) {

        Matcher matcher = DYNAMIC_FORM_PARAMETER_NAME.matcher(propertyDescriptorName);
        if (matcher.matches()) {
            return new PropertyDescriptor.Builder()
                .required(false)
                .name(propertyDescriptorName)
                .description("Form Data " + matcher.group("formDataName"))
                .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true))
                .dynamic(true)
                .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
                .build();
        }
        return null;
    }

    return new PropertyDescriptor.Builder()
            .required(false)
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true))
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .build();
}
 
Example #10
Source File: AbstractKiteProcessor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(String subject, String configFiles,
        ValidationContext context) {
    if (configFiles != null && !configFiles.isEmpty()) {
        for (String file : COMMA.split(configFiles)) {
            ValidationResult result = StandardValidators.FILE_EXISTS_VALIDATOR
                    .validate(subject, file, context);
            if (!result.isValid()) {
                return result;
            }
        }
    }
    return new ValidationResult.Builder()
            .subject(subject)
            .input(configFiles)
            .explanation("Files exist")
            .valid(true)
            .build();
}
 
Example #11
Source File: ScriptedReportingTask.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a PropertyDescriptor for the given name. This is for the user to be able to define their own properties
 * which will be available as variables in the script
 *
 * @param propertyDescriptorName used to lookup if any property descriptors exist for that name
 * @return a PropertyDescriptor object corresponding to the specified dynamic property name
 */
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .required(false)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
            .dynamic(true)
            .build();
}
 
Example #12
Source File: JMSConnectionFactoryProvider.java    From solace-integration-guides with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value for '" + propertyDescriptorName
                    + "' property to be set on the provided ConnectionFactory implementation.")
            .name(propertyDescriptorName).addValidator(StandardValidators.NON_EMPTY_VALIDATOR).dynamic(true)
            .build();
}
 
Example #13
Source File: ExecuteProcess.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
    .name(propertyDescriptorName)
    .description("Sets the environment variable '" + propertyDescriptorName + "' for the process' environment")
    .dynamic(true)
    .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    .build();
}
 
Example #14
Source File: RouteOnAttribute.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .required(false)
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(ResultType.BOOLEAN, false))
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .build();
}
 
Example #15
Source File: AbstractSingleAttributeBasedControllerServiceLookup.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected PropertyDescriptor lookupKeyPropertyDescriptor(String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .description("The " + getServiceName() + " to return when " + getLookupAttribute() + " = '" + propertyDescriptorName + "'")
            .identifiesControllerService(getServiceType())
            .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
            .build();
}
 
Example #16
Source File: AbstractPutHBase.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    if (propertyDescriptorName.startsWith("visibility.")) {
        String[] parts = propertyDescriptorName.split("\\.");
        String displayName;
        String description;

        if (parts.length == 2) {
            displayName = String.format("Column Family %s Default Visibility", parts[1]);
            description = String.format("Default visibility setting for %s", parts[1]);
        } else if (parts.length == 3) {
            displayName = String.format("Column Qualifier %s.%s Default Visibility", parts[1], parts[2]);
            description = String.format("Default visibility setting for %s.%s", parts[1], parts[2]);
        } else {
            return null;
        }

        return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .displayName(displayName)
            .description(description)
            .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .dynamic(true)
            .build();
    }

    return null;
}
 
Example #17
Source File: AbstractGraphExecutor.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String name) {
    return new PropertyDescriptor.Builder()
        .name(name)
        .displayName(name)
        .required(true)
        .addValidator(StandardValidators.NON_EMPTY_EL_VALIDATOR)
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .build();
}
 
Example #18
Source File: QuerySolr.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value to send for the '" + propertyDescriptorName + "' Solr parameter")
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .build();
}
 
Example #19
Source File: PutSolrContentStream.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value to send for the '" + propertyDescriptorName + "' request parameter")
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .build();
}
 
Example #20
Source File: ExecuteScript.java    From nifi-script-tester with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a PropertyDescriptor for the given name. This is for the user to be able to define their own properties
 * which will be available as variables in the script
 *
 * @param propertyDescriptorName used to lookup if any property descriptors exist for that name
 * @return a PropertyDescriptor object corresponding to the specified dynamic property name
 */
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .required(false)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .expressionLanguageSupported(true)
            .dynamic(true)
            .build();
}
 
Example #21
Source File: PutSlack.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    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)
            .build();
}
 
Example #22
Source File: PutSQS.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .required(false)
            .dynamic(true)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .build();
}
 
Example #23
Source File: PutSNS.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .expressionLanguageSupported(true)
            .required(false)
            .dynamic(true)
            .build();
}
 
Example #24
Source File: PutSQS.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .expressionLanguageSupported(true)
            .required(false)
            .dynamic(true)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .build();
}
 
Example #25
Source File: RouteText.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
        .required(false)
        .name(propertyDescriptorName)
        .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
        .dynamic(true)
        .build();
}
 
Example #26
Source File: AbstractEmailProcessor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value for '" + propertyDescriptorName + "' Java Mail property.")
            .name(propertyDescriptorName).addValidator(StandardValidators.NON_EMPTY_VALIDATOR).dynamic(true)
            .build();
}
 
Example #27
Source File: GetKafka.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value for '" + propertyDescriptorName + "' Kafka Configuration.")
            .name(propertyDescriptorName).addValidator(StandardValidators.NON_EMPTY_VALIDATOR).dynamic(true)
            .build();
}
 
Example #28
Source File: ForkRecord.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    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)
            .build();
}
 
Example #29
Source File: HandleHttpResponse.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .description("Specifies the value to send for the '" + propertyDescriptorName + "' HTTP Header")
            .name(propertyDescriptorName)
            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
            .dynamic(true)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .build();
}
 
Example #30
Source File: TransformXml.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
    return new PropertyDescriptor.Builder()
            .name(propertyDescriptorName)
            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
            .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING, true))
            .required(false)
            .dynamic(true)
            .build();
}