Search in sources :

Example 1 with DecisionRule

use of org.kie.dmn.model.api.DecisionRule 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)

Example 2 with DecisionRule

use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.

the class DTSheetListener method finishSheet.

@Override
public void finishSheet() {
    List<DecisionRule> toBeRemoved = new ArrayList<>();
    for (int i = 0; i < dt.getRule().size(); i++) {
        DecisionRule rule = dt.getRule().get(i);
        if (rule.getInputEntry().isEmpty()) {
            toBeRemoved.add(rule);
        }
    }
    dt.getRule().removeAll(toBeRemoved);
}
Also used : ArrayList(java.util.ArrayList) DecisionRule(org.kie.dmn.model.api.DecisionRule) TDecisionRule(org.kie.dmn.model.v1_2.TDecisionRule)

Example 3 with DecisionRule

use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.

the class DecisionTableConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    DecisionTable dt = (DecisionTable) parent;
    for (InputClause i : dt.getInput()) {
        writeChildrenNode(writer, context, i, INPUT);
    }
    for (OutputClause o : dt.getOutput()) {
        writeChildrenNode(writer, context, o, OUTPUT);
    }
    for (DecisionRule r : dt.getRule()) {
        writeChildrenNode(writer, context, r, RULE);
    }
}
Also used : OutputClause(org.kie.dmn.model.api.OutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_1.TDecisionTable) InputClause(org.kie.dmn.model.api.InputClause) DecisionRule(org.kie.dmn.model.api.DecisionRule)

Example 4 with DecisionRule

use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.

the class DecisionRuleConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    DecisionRule dr = (DecisionRule) parent;
    for (UnaryTests ie : dr.getInputEntry()) {
        writeChildrenNode(writer, context, ie, INPUT_ENTRY);
    }
    for (LiteralExpression oe : dr.getOutputEntry()) {
        writeChildrenNode(writer, context, oe, OUTPUT_ENTRY);
    }
    for (RuleAnnotation a : dr.getAnnotationEntry()) {
        writeChildrenNode(writer, context, a, ANNOTATION_ENTRY);
    }
}
Also used : RuleAnnotation(org.kie.dmn.model.api.RuleAnnotation) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) UnaryTests(org.kie.dmn.model.api.UnaryTests) DecisionRule(org.kie.dmn.model.api.DecisionRule) TDecisionRule(org.kie.dmn.model.v1_3.TDecisionRule)

Example 5 with DecisionRule

use of org.kie.dmn.model.api.DecisionRule in project drools by kiegroup.

the class DecisionRuleConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    DecisionRule dr = (DecisionRule) parent;
    for (UnaryTests ie : dr.getInputEntry()) {
        writeChildrenNode(writer, context, ie, INPUT_ENTRY);
    }
    for (LiteralExpression oe : dr.getOutputEntry()) {
        writeChildrenNode(writer, context, oe, OUTPUT_ENTRY);
    }
    for (RuleAnnotation a : dr.getAnnotationEntry()) {
        writeChildrenNode(writer, context, a, ANNOTATION_ENTRY);
    }
}
Also used : RuleAnnotation(org.kie.dmn.model.api.RuleAnnotation) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) UnaryTests(org.kie.dmn.model.api.UnaryTests) DecisionRule(org.kie.dmn.model.api.DecisionRule) TDecisionRule(org.kie.dmn.model.v1_2.TDecisionRule)

Aggregations

DecisionRule (org.kie.dmn.model.api.DecisionRule)12 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)7 InputClause (org.kie.dmn.model.api.InputClause)6 UnaryTests (org.kie.dmn.model.api.UnaryTests)6 DecisionTable (org.kie.dmn.model.api.DecisionTable)5 OutputClause (org.kie.dmn.model.api.OutputClause)5 RuleAnnotation (org.kie.dmn.model.api.RuleAnnotation)3 ArrayList (java.util.ArrayList)2 DMNType (org.kie.dmn.api.core.DMNType)2 RuleAnnotationClause (org.kie.dmn.model.api.RuleAnnotationClause)2 TDecisionRule (org.kie.dmn.model.v1_2.TDecisionRule)2 Collections (java.util.Collections)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 QName (javax.xml.namespace.QName)1