Java Code Examples for org.apache.nifi.components.ValidationResult#Builder

The following examples show how to use org.apache.nifi.components.ValidationResult#Builder . 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: StandardValidators.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject(subject).input(input);
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }

    try {
        FlowFile.KeyValidator.validateKey(input);
        builder.valid(true);
    } catch (final IllegalArgumentException e) {
        builder.valid(false).explanation(e.getMessage());
    }

    return builder.build();
}
 
Example 2
Source File: StandardValidators.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject("Property Name").input(subject);
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }

    try {
        FlowFile.KeyValidator.validateKey(subject);
        builder.valid(true);
    } catch (final IllegalArgumentException e) {
        builder.valid(false).explanation(e.getMessage());
    }

    return builder.build();
}
 
Example 3
Source File: DebugFlow.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder resultBuilder = new ValidationResult.Builder()
        .subject(subject)
        .input(input);

    try {
        final Class<?> exceptionClass = Class.forName(input);
        if (RuntimeException.class.isAssignableFrom(exceptionClass)) {
            resultBuilder.valid(true);
        } else {
            resultBuilder.valid(false).explanation("Class " + input + " is a Checked Exception, not a RuntimeException");
        }
    } catch (ClassNotFoundException e) {
        resultBuilder.valid(false).explanation("Class " + input + " cannot be found");
    }

    return resultBuilder.build();
}
 
Example 4
Source File: SNMPUtils.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject(subject).input(input);
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }
    try {
        if (OID_PATTERN.matcher(input).matches()) {
            builder.valid(true);
        } else {
            builder.valid(false).explanation(input + "is not a valid OID");
        }
    } catch (final IllegalArgumentException e) {
        builder.valid(false).explanation(e.getMessage());
    }
    return builder.build();
}
 
Example 5
Source File: StandardValidators.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject(subject).input(input);
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }

    try {
        FlowFile.KeyValidator.validateKey(input);
        builder.valid(true);
    } catch (final IllegalArgumentException e) {
        builder.valid(false).explanation(e.getMessage());
    }

    return builder.build();
}
 
Example 6
Source File: StandardValidators.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject("Property Name").input(subject);
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }

    try {
        FlowFile.KeyValidator.validateKey(subject);
        builder.valid(true);
    } catch (final IllegalArgumentException e) {
        builder.valid(false).explanation(e.getMessage());
    }

    return builder.build();
}
 
Example 7
Source File: DebugFlow.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder resultBuilder = new ValidationResult.Builder()
        .subject(subject)
        .input(input);

    try {
        final Class<?> exceptionClass = Class.forName(input);
        if (RuntimeException.class.isAssignableFrom(exceptionClass)) {
            resultBuilder.valid(true);
        } else {
            resultBuilder.valid(false).explanation("Class " + input + " is a Checked Exception, not a RuntimeException");
        }
    } catch (ClassNotFoundException e) {
        resultBuilder.valid(false).explanation("Class " + input + " cannot be found");
    }

    return resultBuilder.build();
}
 
Example 8
Source File: PutFile.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(String subject, String input, ValidationContext context) {
    ValidationResult.Builder vr = new ValidationResult.Builder();
    if (context.isExpressionLanguagePresent(input)) {
        return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
    }

    if (RWX_PATTERN.matcher(input).matches() || NUM_PATTERN.matcher(input).matches()) {
        return vr.valid(true).build();
    }
    return vr.valid(false)
            .subject(subject)
            .input(input)
            .explanation("This must be expressed in rwxr-x--- form or octal triplet form.")
            .build();
}
 
Example 9
Source File: PutBigQueryBatch.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject(subject).input(input);
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }

    if (TYPES.contains(input.toUpperCase())) {
        builder.valid(true);
    } else {
        builder.valid(false).explanation("Load File Type must be one of the following options: " + StringUtils.join(TYPES, ", "));
    }

    return builder.build();
}
 
Example 10
Source File: Validation.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(String subject, String value, ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject(subject).input(value);

    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }

    String reason = null;
    try {
        new MongoClientURI(value);
    } catch (final Exception e) {
        reason = e.getLocalizedMessage();
    }

    return builder.explanation(reason).valid(reason == null).build();
}
 
Example 11
Source File: SNMPUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    builder.subject(subject).input(input);
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return builder.valid(true).explanation("Contains Expression Language").build();
    }
    try {
        if (OID_PATTERN.matcher(input).matches()) {
            builder.valid(true);
        } else {
            builder.valid(false).explanation(input + "is not a valid OID");
        }
    } catch (final IllegalArgumentException e) {
        builder.valid(false).explanation(e.getMessage());
    }
    return builder.build();
}
 
Example 12
Source File: StandardValidators.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
    }

    if (input == null) {
        return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Time Period cannot be null").build();
    }
    final String lowerCase = input.toLowerCase();
    final boolean validSyntax = pattern.matcher(lowerCase).matches();
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    if (validSyntax) {
        final long nanos = FormatUtils.getTimeDuration(lowerCase, TimeUnit.NANOSECONDS);

        if (nanos < minNanos || nanos > maxNanos) {
            builder.subject(subject).input(input).valid(false)
                    .explanation("Must be in the range of " + minValueEnglish + " to " + maxValueEnglish);
        } else {
            builder.subject(subject).input(input).valid(true);
        }
    } else {
        builder.subject(subject).input(input).valid(false)
                .explanation("Must be of format <duration> <TimeUnit> where <duration> is a non-negative "
                        + "integer and TimeUnit is a supported Time Unit, such as: nanos, millis, secs, mins, hrs, days");
    }
    return builder.build();
}
 
Example 13
Source File: StandardValidators.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
    }

    if (input == null) {
        return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Time Period cannot be null").build();
    }
    final String lowerCase = input.toLowerCase();
    final boolean validSyntax = pattern.matcher(lowerCase).matches();
    final ValidationResult.Builder builder = new ValidationResult.Builder();
    if (validSyntax) {
        final long nanos = FormatUtils.getTimeDuration(lowerCase, TimeUnit.NANOSECONDS);

        if (nanos < minNanos || nanos > maxNanos) {
            builder.subject(subject).input(input).valid(false)
                    .explanation("Must be in the range of " + minValueEnglish + " to " + maxValueEnglish);
        } else {
            builder.subject(subject).input(input).valid(true);
        }
    } else {
        builder.subject(subject).input(input).valid(false)
                .explanation("Must be of format <duration> <TimeUnit> where <duration> is a non-negative "
                        + "integer and TimeUnit is a supported Time Unit, such as: nanos, millis, secs, mins, hrs, days");
    }
    return builder.build();
}