Search in sources :

Example 6 with FEELEventBase

use of org.kie.dmn.feel.runtime.events.FEELEventBase in project drools by kiegroup.

the class DecisionTableFunction method toDecisionRule.

/**
 * Convert row to DTDecisionRule
 * @param mainCtx the main context is used to identify the hosted FEELEventManager
 * @param embeddedFEEL a possibly cached embedded FEEL to compile the output expression, error will be reported up to the mainCtx
 * @param index
 * @param rule
 * @param inputSize
 * @return
 */
private static DTDecisionRule toDecisionRule(EvaluationContext mainCtx, FEEL embeddedFEEL, int index, List<?> rule, int inputSize) {
    // TODO should be check indeed block of inputSize n inputs, followed by block of outputs.
    DTDecisionRule dr = new DTDecisionRule(index);
    for (int i = 0; i < rule.size(); i++) {
        Object o = rule.get(i);
        if (i < inputSize) {
            dr.getInputEntry().add(toUnaryTest(mainCtx, o));
        } else {
            FEELEventListener ruleListener = event -> mainCtx.notifyEvt(() -> new FEELEventBase(event.getSeverity(), Msg.createMessage(Msg.ERROR_COMPILE_EXPR_DT_FUNCTION_RULE_IDX, index + 1, event.getMessage()), event.getSourceException()));
            embeddedFEEL.addListener(ruleListener);
            CompiledExpression compiledExpression = embeddedFEEL.compile((String) o, embeddedFEEL.newCompilerContext());
            dr.getOutputEntry().add(compiledExpression);
            embeddedFEEL.removeListener(ruleListener);
        }
    }
    return dr;
}
Also used : IntStream(java.util.stream.IntStream) FEEL(org.kie.dmn.feel.FEEL) FEELEventBase(org.kie.dmn.feel.runtime.events.FEELEventBase) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) UnaryTest(org.kie.dmn.feel.runtime.UnaryTest) Logger(org.slf4j.Logger) DTOutputClause(org.kie.dmn.feel.runtime.decisiontables.DTOutputClause) HitPolicy(org.kie.dmn.feel.runtime.decisiontables.HitPolicy) LoggerFactory(org.slf4j.LoggerFactory) DTInputClause(org.kie.dmn.feel.runtime.decisiontables.DTInputClause) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Range(org.kie.dmn.feel.runtime.Range) ArrayList(java.util.ArrayList) List(java.util.List) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) EvaluationContext(org.kie.dmn.feel.lang.EvaluationContext) DTDecisionRule(org.kie.dmn.feel.runtime.decisiontables.DTDecisionRule) Msg(org.kie.dmn.feel.util.Msg) DecisionTableImpl(org.kie.dmn.feel.runtime.decisiontables.DecisionTableImpl) Collections(java.util.Collections) FEELEventBase(org.kie.dmn.feel.runtime.events.FEELEventBase) DTDecisionRule(org.kie.dmn.feel.runtime.decisiontables.DTDecisionRule) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression)

Aggregations

FEELEvent (org.kie.dmn.api.feel.runtime.events.FEELEvent)6 FEELEventBase (org.kie.dmn.feel.runtime.events.FEELEventBase)6 InvalidInputEvent (org.kie.dmn.feel.runtime.events.InvalidInputEvent)2 InvalidParametersEvent (org.kie.dmn.feel.runtime.events.InvalidParametersEvent)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 DMNContext (org.kie.dmn.api.core.DMNContext)1 DMNModel (org.kie.dmn.api.core.DMNModel)1 DMNResult (org.kie.dmn.api.core.DMNResult)1 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)1 FEELEventListener (org.kie.dmn.api.feel.runtime.events.FEELEventListener)1 FEEL (org.kie.dmn.feel.FEEL)1 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)1 EvaluationContext (org.kie.dmn.feel.lang.EvaluationContext)1 NamedParameter (org.kie.dmn.feel.lang.impl.NamedParameter)1