Java Code Examples for org.apache.nifi.processor.util.StandardValidators#DATA_SIZE_VALIDATOR

The following examples show how to use org.apache.nifi.processor.util.StandardValidators#DATA_SIZE_VALIDATOR . 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: ControlRate.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 2
Source File: ControlRate.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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;
}