Search in sources :

Example 1 with StandardExpressionLanguageCompiler

use of org.apache.nifi.attribute.expression.language.StandardExpressionLanguageCompiler in project nifi by apache.

the class UpdateAttributeModelFactory method createCondition.

public Condition createCondition(final ConditionDTO dto) {
    if (dto == null) {
        throw new IllegalArgumentException("Condition must be specified.");
    }
    if (dto.getExpression() == null) {
        throw new IllegalArgumentException("Conditions: Expression must be specified.");
    }
    // validate the condition's expression
    final StandardExpressionLanguageCompiler elCompiler = new StandardExpressionLanguageCompiler();
    final String syntaxError = elCompiler.validateExpression(dto.getExpression(), false);
    if (syntaxError != null) {
        throw new IllegalArgumentException(syntaxError);
    }
    final ResultType resultType = elCompiler.getResultType(dto.getExpression());
    if (!ResultType.BOOLEAN.equals(resultType)) {
        throw new IllegalArgumentException("Return type of condition is " + resultType + " but expected type BOOLEAN");
    }
    final Condition condition = new Condition();
    condition.setId(dto.getId());
    condition.setExpression(dto.getExpression());
    return condition;
}
Also used : StandardExpressionLanguageCompiler(org.apache.nifi.attribute.expression.language.StandardExpressionLanguageCompiler) ResultType(org.apache.nifi.expression.AttributeExpression.ResultType)

Aggregations

StandardExpressionLanguageCompiler (org.apache.nifi.attribute.expression.language.StandardExpressionLanguageCompiler)1 ResultType (org.apache.nifi.expression.AttributeExpression.ResultType)1