@Override public Object evaluate(EvaluationContext ctx) { // spec says: if FEEL(e1) is true then FEEL(e2) else FEEL(e3) Object cond = this.condition.evaluate( ctx ); if ( cond != null && cond instanceof Boolean && cond == Boolean.TRUE ) { return this.thenExpression.evaluate( ctx ); } else { return this.elseExpression.evaluate( ctx ); } }
@Override public Object evaluate(EvaluationContext ctx) { return value.evaluate( ctx ); }
@Override public Object evaluate(EvaluationContext ctx) { return expression != null ? expression.evaluate( ctx ) : null; }
public String evaluateName( EvaluationContext ctx ) { return (String) name.evaluate( ctx ); }
public Object evaluateRangeEnd(EvaluationContext ctx) { return rangeEndExpr != null ? rangeEndExpr.evaluate(ctx) : null; }
@Override public List evaluate(EvaluationContext ctx) { return elements.stream().map( e -> e != null ? e.evaluate( ctx ) : null ).collect( Collectors.toList() ); }
private UnaryTest createCompareUnaryTest( BiPredicate<Comparable, Comparable> op ) { return (context, left) -> { Object right = value.evaluate( context ); return EvalHelper.compare( left, right, context, op ); }; }
private UnaryTest createIsNotEqualUnaryTest( ) { return (context, left) -> { Object right = value.evaluate( context ); Boolean result = utEqualSemantic(left, right, context); return result != null ? ! result : null; }; }
private UnaryTest createIsEqualUnaryTest( ) { return (context, left) -> { Object right = value.evaluate( context ); return utEqualSemantic(left, right, context); }; }
@Override public Object evaluate(EvaluationContext ctx) { String n = name.evaluate( ctx ); Object val = expression.evaluate( ctx ); return new NamedParameter( n, val ); }
@Override public Object evaluate(EvaluationContext ctx) { Object value = expression.evaluate( ctx ); Type t = type.evaluate( ctx ); return t.isInstanceOf( value ); }
@Override public Object evaluate(EvaluationContext ctx) { if (expression == null) return null; BigDecimal result = EvalHelper.getBigDecimalOrNull( expression.evaluate( ctx ) ); if ( result == null ) { ctx.notifyEvt( astEvent(Severity.WARN, Msg.createMessage(Msg.NEGATING_A_NULL))); return null; } else if ( Sign.NEGATIVE == sign ) { return BigDecimal.valueOf( -1 ).multiply( result ); } else { return result; } }
private UnaryTest createBooleanUnaryTest( ) { return (context, left) -> { Object right = value.evaluate( context ); if( right instanceof Boolean ) { return (Boolean) right; } else { context.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.EXTENDED_UNARY_TEST_MUST_BE_BOOLEAN, left.toString(), value.toString() ) ) ); return Boolean.FALSE; } }; }
@Override public Object evaluate(EvaluationContext ctx) { try { ctx.enterFrame(); List results = new ArrayList( ); ctx.setValue("partial", results); ForIteration[] ictx = initializeContexts( ctx, iterationContexts); while ( nextIteration( ctx, ictx ) ) { Object result = expression.evaluate( ctx ); results.add( result ); } return results; } catch (EndpointOfRangeNotOfNumberException e) { // ast error already reported return null; } finally { ctx.exitFrame(); } }
public static Expression external(List<String> paramNames, BaseNode body) { EvaluationContextImpl emptyEvalCtx = new EvaluationContextImpl(Functions.class.getClassLoader(), new FEELEventListenersManager()); Map<String, Object> conf = (Map<String, Object>) body.evaluate(emptyEvalCtx); Map<String, String> java = (Map<String, String>) conf.get( "java" ); if (java != null) { String className = java.get("class"); String methodSignature = java.get("method signature"); if (className == null || methodSignature == null) { throw new FEELCompilationError( Msg.createMessage(Msg.UNABLE_TO_FIND_EXTERNAL_FUNCTION_AS_DEFINED_BY, methodSignature)); } return FunctionDefs.asMethodCall(className, methodSignature, paramNames); } else { throw new FEELCompilationError(Msg.createMessage(Msg.UNABLE_TO_FIND_EXTERNAL_FUNCTION_AS_DEFINED_BY, null)); } }
public FEELFnResult<Object> invoke(EvaluationContext ctx, Object[] params ) { if( params.length != parameters.size() ) { return FEELFnResult.ofError(new InvalidInputEvent(Severity.ERROR, "Illegal invocation of function", getName(), getName() + "( " + Arrays.asList(params)+" )", getSignature())); } FEELEvent capturedException = null; try { ctx.enterFrame(); for ( int i = 0; i < parameters.size(); i++ ) { ctx.setValue( parameters.get( i ), params[i] ); } Object result = this.body.evaluate( ctx ); return FEELFnResult.ofResult( result ); } catch( Exception e ) { capturedException = new FEELEventBase(Severity.ERROR, "Error invoking function", new RuntimeException("Error invoking function " + getSignature() + ".", e)); } finally { ctx.exitFrame(); } return FEELFnResult.ofError( capturedException ); }
private void evaluateExpressionInContext(EvaluationContext ctx, List results, Object v) { try { ctx.enterFrame(); // handle it as a predicate // Have the "item" variable set first, so to respect the DMN spec: The expression in square brackets can reference a list // element using the name item, unless the list element is a context that contains the key "item". ctx.setValue( "item", v ); // using Root object logic to avoid having to eagerly inspect all attributes. ctx.setRootObject(v); // a filter would always return a list with all the elements for which the filter is true. // In case any element fails in there or the filter expression returns null, it will only exclude the element, but will continue to process the list. // In case all elements fail, the result will be an empty list. Object r = this.filter.evaluate(new SilentWrappingEvaluationContextImpl(ctx)); // evaluate filter, ignoring errors if( r instanceof Boolean && ((Boolean)r) == Boolean.TRUE ) { results.add( v ); } } finally { ctx.exitFrame(); } }
private Boolean iterateContexts(EvaluationContext ctx, List<IterationContextNode> iterationContexts, BaseNode expression, Quantifier quantifier ) { try { ctx.enterFrame(); QEIteration[] ictx = initializeContexts(ctx, iterationContexts); while ( nextIteration( ctx, ictx ) ) { Boolean result = (Boolean) expression.evaluate( ctx ); if ( result != null && result.equals( quantifier.positiveTest() ) ) { return quantifier.positiveTest(); } } return quantifier.defaultValue(); } finally { ctx.exitFrame(); } }
@Override public Range evaluate(EvaluationContext ctx) { Object s = start.evaluate( ctx ); Object e = end.evaluate( ctx ); boolean problem = false; if ( s == null ) { ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "Start"))); problem = true; } if ( e == null ) { ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.IS_NULL, "End"))); problem = true; } if (problem) { return null; } if ( BuiltInType.determineTypeFromInstance( s ) != BuiltInType.determineTypeFromInstance( e ) && !s.getClass().isAssignableFrom( e.getClass() ) ) { ctx.notifyEvt( astEvent(Severity.ERROR, Msg.createMessage(Msg.X_TYPE_INCOMPATIBLE_WITH_Y_TYPE, "Start", "End"))); return null; } Comparable start = convertToComparable( ctx, s ); Comparable end = convertToComparable( ctx, e ); return new RangeImpl( lowerBound==IntervalBoundary.OPEN ? Range.RangeBoundary.OPEN : Range.RangeBoundary.CLOSED, start, end, upperBound==IntervalBoundary.OPEN ? Range.RangeBoundary.OPEN : Range.RangeBoundary.CLOSED ); }