private Object[] resolveActualInputs(EvaluationContext ctx, FEEL feel) { Map<String, Object> variables = ctx.getAllValues(); Object[] actualInputs = new Object[ inputs.size() ]; for( int i = 0; i < inputs.size(); i++ ) { CompiledExpression compiledInput = inputs.get( i ).getCompiledInput(); if( compiledInput != null ) { actualInputs[i] = feel.evaluate( compiledInput, variables ); } else { actualInputs[i] = feel.evaluate( inputs.get( i ).getInputExpression(), variables ); } } return actualInputs; }
/** * If valid input values are defined, check that all parameters match the respective valid inputs * @param ctx * @param params * @return */ private Either<FEELEvent, Object> actualInputsMatchInputValues(EvaluationContext ctx, Object[] params) { // check that all the parameters match the input list values if they are defined for( int i = 0; i < params.length; i++ ) { final DTInputClause input = inputs.get( i ); // if a list of values is defined, check the the parameter matches the value if ( input.getInputValues() != null && ! input.getInputValues().isEmpty() ) { final Object parameter = params[i]; boolean satisfies = input.getInputValues().stream().map( ut -> ut.apply( ctx, parameter ) ).filter( Boolean::booleanValue ).findAny().orElse( false ); if ( !satisfies ) { String values = input.getInputValuesText(); return Either.ofLeft(new InvalidInputEvent( FEELEvent.Severity.ERROR, input.getInputExpression()+"='" + parameter + "' does not match any of the valid values " + values + " for decision table '" + getName() + "'.", getName(), null, values ) ); } } } return Either.ofRight(true); }
/** * Checks if the parameters match a single rule * @param ctx * @param params * @param rule * @return */ private boolean matches(EvaluationContext ctx, Object[] params, DTDecisionRule rule) { for( int i = 0; i < params.length; i++ ) { CompiledExpression compiledInput = inputs.get(i).getCompiledInput(); if ( compiledInput instanceof CompiledFEELExpression) { ctx.setValue("?", ((CompiledFEELExpression) compiledInput).apply(ctx)); } if( ! satisfies( ctx, params[i], rule.getInputEntry().get( i ) ) ) { return false; } } return true; }
.mapToObj( i -> new DTInputClause( inputExpressions.get( i ), inputValuesList.toString(), Collections.singletonList( inputValues.get( i ) ), null ) ) .collect( Collectors.toList() ); } else { inputs = inputExpressions.stream().map( ie -> new DTInputClause( ie, null, null, null ) ).collect( Collectors.toList() );