Search in sources :

Example 1 with UnaryTests

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

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

the class DTSheetListener method newCell.

@Override
public void newCell(int row, int column, String value, int mergedColStart) {
    if (row == 0) {
        // TODO row 0 being the header.
        return;
    }
    if (curRule == null) {
        return;
    }
    if (value == null || value.isEmpty()) {
        LOG.trace("ignoring row {}, col {} having value {}", row, column, value);
        return;
    }
    if (column < headerInfo.gethIndex()) {
        valueCheck(row, column, value);
        UnaryTests ut = new TUnaryTests();
        ut.setText(eValue(value));
        curRule.getInputEntry().add(ut);
    } else if (column == headerInfo.gethIndex()) {
        valueCheck(row, column, value);
        LiteralExpression le = new TLiteralExpression();
        le.setText(eValue(value));
        curRule.getOutputEntry().add(le);
    } else {
        LOG.trace("ignoring row {}, col {} having value {}", row, column, value);
    }
}
Also used : TUnaryTests(org.kie.dmn.model.v1_2.TUnaryTests) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) TUnaryTests(org.kie.dmn.model.v1_2.TUnaryTests) UnaryTests(org.kie.dmn.model.api.UnaryTests)

Example 3 with UnaryTests

use of org.kie.dmn.model.api.UnaryTests 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 4 with UnaryTests

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

the class ExpressionConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    Expression e = (Expression) parent;
    if (!(e instanceof UnaryTests) && e.getTypeRef() != null) {
        writer.addAttribute(TYPE_REF, MarshallingUtils.formatQName(e.getTypeRef(), e));
    }
}
Also used : Expression(org.kie.dmn.model.api.Expression) UnaryTests(org.kie.dmn.model.api.UnaryTests)

Example 5 with UnaryTests

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

UnaryTests (org.kie.dmn.model.api.UnaryTests)27 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)9 DecisionRule (org.kie.dmn.model.api.DecisionRule)5 TUnaryTests (org.kie.dmn.model.v1_2.TUnaryTests)5 Expression (org.kie.dmn.model.api.Expression)4 RuleAnnotation (org.kie.dmn.model.api.RuleAnnotation)3 TUnaryTests (org.kie.dmn.model.v1_1.TUnaryTests)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 QName (javax.xml.namespace.QName)2 Resource (org.kie.api.io.Resource)2 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 DMNType (org.kie.dmn.api.core.DMNType)2 TUnaryTests (org.kie.dmn.model.v1_3.TUnaryTests)2 TUnaryTests (org.kie.dmn.model.v1_4.TUnaryTests)2