Java Code Examples for org.apache.nifi.components.ValidationContext#getProperties()

The following examples show how to use org.apache.nifi.components.ValidationContext#getProperties() . 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: ForkRecord.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    final List<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));
    Validator validator = new RecordPathValidator();

    Map<PropertyDescriptor, String> processorProperties = validationContext.getProperties();
    for (final Map.Entry<PropertyDescriptor, String> entry : processorProperties.entrySet()) {
        PropertyDescriptor property = entry.getKey();
        if (property.isDynamic() && property.isExpressionLanguageSupported()) {
            String dynamicValue = validationContext.getProperty(property).getValue();
            if(!validationContext.isExpressionLanguagePresent(dynamicValue)) {
                results.add(validator.validate(property.getDisplayName(), dynamicValue, validationContext));
            }
        }
    }

    return results;
}
 
Example 2
Source File: ScriptingComponentHelper.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Custom validation for ensuring exactly one of Script File or Script Body is populated
 *
 * @param validationContext provides a mechanism for obtaining externally
 *                          managed values, such as property values and supplies convenience methods
 *                          for operating on those values
 * @return A collection of validation results
 */
public Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Set<ValidationResult> results = new HashSet<>();

    // Verify that exactly one of "script file" or "script body" is set
    Map<PropertyDescriptor, String> propertyMap = validationContext.getProperties();
    if (StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_FILE)) == StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_BODY))) {
        results.add(new ValidationResult.Builder().valid(false).explanation(
                "Exactly one of Script File or Script Body must be set").build());
    }

    return results;
}
 
Example 3
Source File: AbstractCassandraProcessor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Set<ValidationResult> results = new HashSet<>();

    // Ensure that if username or password is set, then the other is too
    Map<PropertyDescriptor, String> propertyMap = validationContext.getProperties();
    if (StringUtils.isEmpty(propertyMap.get(USERNAME)) != StringUtils.isEmpty(propertyMap.get(PASSWORD))) {
        results.add(new ValidationResult.Builder().valid(false).explanation(
                "If username or password is specified, then the other must be specified as well").build());
    }

    return results;
}
 
Example 4
Source File: ScriptingComponentHelper.java    From nifi-script-tester with Apache License 2.0 5 votes vote down vote up
/**
 * Custom validation for ensuring exactly one of Script File or Script Body is populated
 *
 * @param validationContext provides a mechanism for obtaining externally
 *                          managed values, such as property values and supplies convenience methods
 *                          for operating on those values
 * @return A collection of validation results
 */
public Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Set<ValidationResult> results = new HashSet<>();

    // Verify that exactly one of "script file" or "script body" is set
    Map<PropertyDescriptor, String> propertyMap = validationContext.getProperties();
    if (StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_FILE)) == StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_BODY))) {
        results.add(new ValidationResult.Builder().valid(false).explanation(
                "Exactly one of Script File or Script Body must be set").build());
    }

    return results;
}
 
Example 5
Source File: ScriptingComponentHelper.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Custom validation for ensuring exactly one of Script File or Script Body is populated
 *
 * @param validationContext provides a mechanism for obtaining externally
 *                          managed values, such as property values and supplies convenience methods
 *                          for operating on those values
 * @return A collection of validation results
 */
public Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Set<ValidationResult> results = new HashSet<>();

    // Verify that exactly one of "script file" or "script body" is set
    Map<PropertyDescriptor, String> propertyMap = validationContext.getProperties();
    if (StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_FILE)) == StringUtils.isEmpty(propertyMap.get(ScriptingComponentUtils.SCRIPT_BODY))) {
        results.add(new ValidationResult.Builder().subject("Script Body or Script File").valid(false).explanation(
                "exactly one of Script File or Script Body must be set").build());
    }

    return results;
}
 
Example 6
Source File: AbstractEasyRulesEngineController.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Custom validation for ensuring exactly one of Script File or Script Body is populated
 *
 * @param validationContext provides a mechanism for obtaining externally
 *                          managed values, such as property values and supplies convenience methods
 *                          for operating on those values
 * @return A collection of validation results
 */
@Override
public Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Set<ValidationResult> results = new HashSet<>();

    // Verify that exactly one of "script file" or "script body" is set
    Map<PropertyDescriptor, String> propertyMap = validationContext.getProperties();
    if (StringUtils.isEmpty(propertyMap.get(RULES_FILE_PATH)) == StringUtils.isEmpty(propertyMap.get(RULES_BODY))) {
        results.add(new ValidationResult.Builder().subject("Rules Body or Rules File").valid(false).explanation(
                "exactly one of Rules File or Rules Body must be set").build());
    }
    return results;
}
 
Example 7
Source File: RouteText.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Collection<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));
    boolean dynamicProperty = false;

    final String matchStrategy = validationContext.getProperty(MATCH_STRATEGY).getValue();
    final boolean compileRegex = matchStrategy.equals(matchesRegularExpressionValue) || matchStrategy.equals(containsRegularExpressionValue);
    final boolean requiresExpression = matchStrategy.equalsIgnoreCase(satisfiesExpression);

    Validator validator = null;
    if (compileRegex) {
        validator = StandardValidators.createRegexValidator(0, Integer.MAX_VALUE, true);
    }

    Map<PropertyDescriptor, String> allProperties = validationContext.getProperties();
    for (final PropertyDescriptor descriptor : allProperties.keySet()) {
        if (descriptor.isDynamic()) {
            dynamicProperty = true;

            final String propValue = validationContext.getProperty(descriptor).getValue();

            if (compileRegex) {
                ValidationResult validationResult = validator.validate(descriptor.getName(), propValue, validationContext);
                if (validationResult != null) {
                    results.add(validationResult);
                }
            } else if (requiresExpression) {
                try {
                    final ResultType resultType = validationContext.newExpressionLanguageCompiler().compile(propValue).getResultType();
                    if (resultType != ResultType.BOOLEAN) {
                        results.add(new ValidationResult.Builder().valid(false).input(propValue).subject(descriptor.getName())
                            .explanation("expression returns type of " + resultType.name() + " but is required to return a Boolean value").build());
                    }
                } catch (final IllegalArgumentException iae) {
                    results.add(new ValidationResult.Builder().valid(false).input(propValue).subject(descriptor.getName())
                        .explanation("input is not a valid Expression Language expression").build());
                }
            }
        }
    }

    if (!dynamicProperty) {
        results.add(new ValidationResult.Builder().subject("Dynamic Properties")
            .explanation("In order to route text there must be dynamic properties to match against").valid(false).build());
    }

    return results;
}
 
Example 8
Source File: CredentialsFactory.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public CredentialsStrategy selectPrimaryStrategy(final ValidationContext validationContext) {
    final Map<PropertyDescriptor, String> properties = validationContext.getProperties();
    return selectPrimaryStrategy(properties);
}
 
Example 9
Source File: CredentialsProviderFactory.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public CredentialsStrategy selectPrimaryStrategy(final ValidationContext validationContext) {
    final Map<PropertyDescriptor, String> properties = validationContext.getProperties();
    return selectPrimaryStrategy(properties);
}
 
Example 10
Source File: RouteText.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
    Collection<ValidationResult> results = new ArrayList<>(super.customValidate(validationContext));
    boolean dynamicProperty = false;

    final String matchStrategy = validationContext.getProperty(MATCH_STRATEGY).getValue();
    final boolean compileRegex = matchStrategy.equals(matchesRegularExpressionValue) || matchStrategy.equals(containsRegularExpressionValue);
    final boolean requiresExpression = matchStrategy.equalsIgnoreCase(satisfiesExpression);

    Validator validator = null;
    if (compileRegex) {
        validator = StandardValidators.createRegexValidator(0, Integer.MAX_VALUE, true);
    }

    Map<PropertyDescriptor, String> allProperties = validationContext.getProperties();
    for (final PropertyDescriptor descriptor : allProperties.keySet()) {
        if (descriptor.isDynamic()) {
            dynamicProperty = true;

            final String propValue = validationContext.getProperty(descriptor).getValue();

            if (compileRegex) {
                ValidationResult validationResult = validator.validate(descriptor.getName(), propValue, validationContext);
                if (validationResult != null) {
                    results.add(validationResult);
                }
            } else if (requiresExpression) {
                try {
                    final ResultType resultType = validationContext.newExpressionLanguageCompiler().compile(propValue).getResultType();
                    if (resultType != ResultType.BOOLEAN) {
                        results.add(new ValidationResult.Builder().valid(false).input(propValue).subject(descriptor.getName())
                            .explanation("expression returns type of " + resultType.name() + " but is required to return a Boolean value").build());
                    }
                } catch (final IllegalArgumentException iae) {
                    results.add(new ValidationResult.Builder().valid(false).input(propValue).subject(descriptor.getName())
                        .explanation("input is not a valid Expression Language expression").build());
                }
            }
        }
    }

    if (!dynamicProperty) {
        results.add(new ValidationResult.Builder().subject("Dynamic Properties")
            .explanation("In order to route text there must be dynamic properties to match against").valid(false).build());
    }

    return results;
}
 
Example 11
Source File: CredentialsFactory.java    From nifi with Apache License 2.0 4 votes vote down vote up
public CredentialsStrategy selectPrimaryStrategy(final ValidationContext validationContext) {
    final Map<PropertyDescriptor, String> properties = validationContext.getProperties();
    return selectPrimaryStrategy(properties);
}
 
Example 12
Source File: CredentialsProviderFactory.java    From nifi with Apache License 2.0 4 votes vote down vote up
public CredentialsStrategy selectPrimaryStrategy(final ValidationContext validationContext) {
    final Map<PropertyDescriptor, String> properties = validationContext.getProperties();
    return selectPrimaryStrategy(properties);
}