Search in sources :

Example 1 with LiteralExpression

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

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

the class DTAnalysis method gapsAsMessages.

private Collection gapsAsMessages() {
    List<DMNDTAnalysisMessage> results = new ArrayList<>();
    if (!ddtaTable.getColIDsStringWithoutEnum().isEmpty()) {
        List<String> names = ddtaTable.getColIDsStringWithoutEnum().stream().map(id -> sourceDT.getInput().get(id - 1)).map(InputClause::getInputExpression).map(LiteralExpression::getText).collect(Collectors.toList());
        results.add(new DMNDTAnalysisMessage(this, Severity.WARN, MsgUtil.createMessage(Msg.DTANALYSIS_GAP_SKIPPED_BECAUSE_FREE_STRING, names), Msg.DTANALYSIS_GAP_SKIPPED_BECAUSE_FREE_STRING.getType()));
        return results;
    }
    for (Hyperrectangle gap : gaps) {
        results.add(new DMNDTAnalysisMessage(this, Severity.WARN, MsgUtil.createMessage(Msg.DTANALYSIS_GAP, gap.asHumanFriendly(ddtaTable)), Msg.DTANALYSIS_GAP.getType()));
    }
    return results;
}
Also used : MsgUtil(org.kie.dmn.core.util.MsgUtil) Arrays(java.util.Arrays) RangeBoundary(org.kie.dmn.feel.runtime.Range.RangeBoundary) DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) InputClause(org.kie.dmn.model.api.InputClause) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) DMNDTAnalysisMessage(org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage) Map(java.util.Map) PosNegBlock(org.kie.dmn.validation.dtanalysis.mcdc.MCDCAnalyser.PosNegBlock) DashNode(org.kie.dmn.feel.lang.ast.DashNode) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ValidatorUtil(org.kie.dmn.validation.ValidatorUtil) Collectors(java.util.stream.Collectors) Severity(org.kie.dmn.api.core.DMNMessage.Severity) HitPolicy(org.kie.dmn.model.api.HitPolicy) List(java.util.List) Msg(org.kie.dmn.core.util.Msg) Collections(java.util.Collections) DMNDTAnalysisMessage(org.kie.dmn.validation.dtanalysis.DMNDTAnalysisMessage) ArrayList(java.util.ArrayList) InputClause(org.kie.dmn.model.api.InputClause)

Example 3 with LiteralExpression

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

the class XLS2DMNParser method appendDecisionDT.

private void appendDecisionDT(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
    for (DTHeaderInfo hi : headerInfos.values()) {
        Decision decision = new TDecision();
        decision.setName(hi.getSheetName());
        decision.setId("d_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        InformationItem variable = new TInformationItem();
        variable.setName(hi.getSheetName());
        variable.setId("dvar_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        variable.setTypeRef(new QName("Any"));
        decision.setVariable(variable);
        for (String ri : hi.getRequiredInput()) {
            InformationRequirement ir = new TInformationRequirement();
            DMNElementReference er = new TDMNElementReference();
            er.setHref("#id_" + CodegenStringUtil.escapeIdentifier(ri));
            ir.setRequiredInput(er);
            decision.getInformationRequirement().add(ir);
        }
        for (String ri : hi.getRequiredDecision()) {
            InformationRequirement ir = new TInformationRequirement();
            DMNElementReference er = new TDMNElementReference();
            er.setHref("#d_" + CodegenStringUtil.escapeIdentifier(ri));
            ir.setRequiredDecision(er);
            decision.getInformationRequirement().add(ir);
        }
        DecisionTable dt = new TDecisionTable();
        dt.setOutputLabel(hi.getSheetName());
        dt.setId("ddt_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        dt.setHitPolicy(HitPolicy.ANY);
        for (String ri : hi.getRequiredInput()) {
            InputClause ic = new TInputClause();
            ic.setLabel(ri);
            LiteralExpression le = new TLiteralExpression();
            le.setText(ri);
            ic.setInputExpression(le);
            dt.getInput().add(ic);
        }
        for (String rd : hi.getRequiredDecision()) {
            InputClause ic = new TInputClause();
            ic.setLabel(rd);
            LiteralExpression le = new TLiteralExpression();
            le.setText(rd);
            ic.setInputExpression(le);
            dt.getInput().add(ic);
        }
        OutputClause oc = new TOutputClause();
        dt.getOutput().add(oc);
        decision.setExpression(dt);
        definitions.getDrgElement().add(decision);
    }
}
Also used : TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) Decision(org.kie.dmn.model.api.Decision) TDecision(org.kie.dmn.model.v1_2.TDecision) OutputClause(org.kie.dmn.model.api.OutputClause) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) DMNElementReference(org.kie.dmn.model.api.DMNElementReference) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TInputClause(org.kie.dmn.model.v1_2.TInputClause) TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) InformationRequirement(org.kie.dmn.model.api.InformationRequirement) TDecision(org.kie.dmn.model.v1_2.TDecision) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) TInputClause(org.kie.dmn.model.v1_2.TInputClause) InputClause(org.kie.dmn.model.api.InputClause)

Example 4 with LiteralExpression

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

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

the class LiteralExpressionConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    LiteralExpression le = (LiteralExpression) parent;
    String exprLanguage = reader.getAttribute(EXPR_LANGUAGE);
    le.setExpressionLanguage(exprLanguage);
}
Also used : LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TLiteralExpression(org.kie.dmn.model.v1_1.TLiteralExpression)

Aggregations

LiteralExpression (org.kie.dmn.model.api.LiteralExpression)31 UnaryTests (org.kie.dmn.model.api.UnaryTests)11 DecisionRule (org.kie.dmn.model.api.DecisionRule)9 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)8 InputClause (org.kie.dmn.model.api.InputClause)6 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 InformationItem (org.kie.dmn.model.api.InformationItem)5 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 DMNMessage (org.kie.dmn.api.core.DMNMessage)4 DMNType (org.kie.dmn.api.core.DMNType)4 DMNNode (org.kie.dmn.api.core.ast.DMNNode)4 DMNExpressionEvaluator (org.kie.dmn.core.api.DMNExpressionEvaluator)4 Decision (org.kie.dmn.model.api.Decision)4 DecisionTable (org.kie.dmn.model.api.DecisionTable)4 Entry (java.util.Map.Entry)3 Objects (java.util.Objects)3