Search in sources :

Example 1 with ProcessedExpression

use of org.kie.dmn.feel.codegen.feel11.ProcessedExpression in project drools by kiegroup.

the class FEELParserSeverityTest method parseSeverity.

private ASTNode parseSeverity(String input, FEELEvent.Severity severity) {
    FEELEventListenersManager mgr = new FEELEventListenersManager();
    CompilerContext ctx = new CompilerContextImpl(mgr);
    final FEELEventListener listener = mock(FEELEventListener.class);
    mgr.addListener(listener);
    mgr.addListener(e -> LOG.info("{}", e));
    ProcessedExpression processedExpression = new ProcessedExpression(input, ctx, ProcessedFEELUnit.DefaultMode.Interpreted, Collections.emptyList());
    final ArgumentCaptor<FEELEvent> captor = ArgumentCaptor.forClass(FEELEvent.class);
    verify(listener, atLeastOnce()).onEvent(captor.capture());
    assertThat(captor.getValue().getSeverity(), is(severity));
    return processedExpression.getInterpreted().getASTNode();
}
Also used : CompilerContext(org.kie.dmn.feel.lang.CompilerContext) FEELEventListenersManager(org.kie.dmn.feel.lang.impl.FEELEventListenersManager) ProcessedExpression(org.kie.dmn.feel.codegen.feel11.ProcessedExpression) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) CompilerContextImpl(org.kie.dmn.feel.lang.impl.CompilerContextImpl) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent)

Example 2 with ProcessedExpression

use of org.kie.dmn.feel.codegen.feel11.ProcessedExpression in project drools by kiegroup.

the class DMNDTAnalyser method compileTableRules.

private void compileTableRules(DecisionTable dt, DDTATable ddtaTable) {
    for (int jRowIdx = 0; jRowIdx < dt.getRule().size(); jRowIdx++) {
        DecisionRule r = dt.getRule().get(jRowIdx);
        DDTARule ddtaRule = new DDTARule();
        int jColIdx = 0;
        for (UnaryTests ie : r.getInputEntry()) {
            ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(ie.getText(), FEEL.newCompilerContext());
            UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
            UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
            DDTAInputClause ddtaInputClause = ddtaTable.getInputs().get(jColIdx);
            DDTAInputEntry ddtaInputEntry = new DDTAInputEntry(utln.getElements(), toIntervals(utln.getElements(), utln.isNegated(), ddtaInputClause.getDomainMinMax(), ddtaInputClause.getDiscreteValues(), jRowIdx + 1, jColIdx + 1));
            for (Interval interval : ddtaInputEntry.getIntervals()) {
                Interval domainMinMax = ddtaTable.getInputs().get(jColIdx).getDomainMinMax();
                if (!domainMinMax.includes(interval)) {
                    throw new IllegalStateException(MsgUtil.createMessage(Msg.DTANALYSIS_ERROR_RULE_OUTSIDE_DOMAIN, jRowIdx + 1, interval, domainMinMax, jColIdx + 1));
                }
            }
            ddtaRule.getInputEntry().add(ddtaInputEntry);
            jColIdx++;
        }
        for (LiteralExpression oe : r.getOutputEntry()) {
            ProcessedExpression compile = (ProcessedExpression) FEEL.compile(oe.getText(), FEEL.newCompilerContext());
            InterpretedExecutableExpression interpreted = compile.getInterpreted();
            BaseNode outputEntryNode = (BaseNode) interpreted.getASTNode();
            Comparable<?> value = valueFromNode(outputEntryNode, outputClauseVisitor);
            ddtaRule.getOutputEntry().add(value);
            jColIdx++;
        }
        ddtaTable.addRule(ddtaRule);
    }
}
Also used : DDTARule(org.kie.dmn.validation.dtanalysis.model.DDTARule) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ProcessedUnaryTest(org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest) ProcessedExpression(org.kie.dmn.feel.codegen.feel11.ProcessedExpression) UnaryTestInterpretedExecutableExpression(org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression) InterpretedExecutableExpression(org.kie.dmn.feel.lang.impl.InterpretedExecutableExpression) DecisionRule(org.kie.dmn.model.api.DecisionRule) DDTAInputEntry(org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry) UnaryTestInterpretedExecutableExpression(org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression) UnaryTestListNode(org.kie.dmn.feel.lang.ast.UnaryTestListNode) DDTAInputClause(org.kie.dmn.validation.dtanalysis.model.DDTAInputClause) UnaryTests(org.kie.dmn.model.api.UnaryTests) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Aggregations

ProcessedExpression (org.kie.dmn.feel.codegen.feel11.ProcessedExpression)2 FEELEvent (org.kie.dmn.api.feel.runtime.events.FEELEvent)1 FEELEventListener (org.kie.dmn.api.feel.runtime.events.FEELEventListener)1 ProcessedUnaryTest (org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest)1 CompilerContext (org.kie.dmn.feel.lang.CompilerContext)1 BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)1 UnaryTestListNode (org.kie.dmn.feel.lang.ast.UnaryTestListNode)1 CompilerContextImpl (org.kie.dmn.feel.lang.impl.CompilerContextImpl)1 FEELEventListenersManager (org.kie.dmn.feel.lang.impl.FEELEventListenersManager)1 InterpretedExecutableExpression (org.kie.dmn.feel.lang.impl.InterpretedExecutableExpression)1 UnaryTestInterpretedExecutableExpression (org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression)1 DecisionRule (org.kie.dmn.model.api.DecisionRule)1 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)1 UnaryTests (org.kie.dmn.model.api.UnaryTests)1 DDTAInputClause (org.kie.dmn.validation.dtanalysis.model.DDTAInputClause)1 DDTAInputEntry (org.kie.dmn.validation.dtanalysis.model.DDTAInputEntry)1 DDTARule (org.kie.dmn.validation.dtanalysis.model.DDTARule)1 Interval (org.kie.dmn.validation.dtanalysis.model.Interval)1