Search in sources :

Example 6 with InputClause

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

the class DMNDTAnalyser method compileTableInputClauses.

private void compileTableInputClauses(DMNModel model, DecisionTable dt, DDTATable ddtaTable) {
    for (int jColIdx = 0; jColIdx < dt.getInput().size(); jColIdx++) {
        InputClause ie = dt.getInput().get(jColIdx);
        Interval infDomain = new Interval(RangeBoundary.CLOSED, Interval.NEG_INF, Interval.POS_INF, RangeBoundary.CLOSED, 0, jColIdx + 1);
        String allowedValues;
        if (ie.getInputValues() != null) {
            allowedValues = ie.getInputValues().getText();
        } else {
            QName typeRef = DMNCompilerImpl.getNamespaceAndName(dt, ((DMNModelImpl) model).getImportAliasesForNS(), ie.getInputExpression().getTypeRef(), model.getNamespace());
            allowedValues = findAllowedValues(model, typeRef);
        }
        if (allowedValues != null) {
            ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(allowedValues, FEEL.newCompilerContext());
            UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
            UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
            if (utln.getElements().size() != 1) {
                verifyUnaryTestsAllEQ(utln, dt);
                List<Comparable<?>> discreteValues = getDiscreteValues(utln);
                Collections.sort((List) discreteValues);
                Interval discreteDomainMinMax = new Interval(RangeBoundary.CLOSED, discreteValues.get(0), discreteValues.get(discreteValues.size() - 1), RangeBoundary.CLOSED, 0, jColIdx + 1);
                DDTAInputClause ic = new DDTAInputClause(discreteDomainMinMax, discreteValues, getDiscreteValues(utln));
                ddtaTable.getInputs().add(ic);
            } else if (utln.getElements().size() == 1) {
                UnaryTestNode utn0 = (UnaryTestNode) utln.getElements().get(0);
                Interval interval = utnToInterval(utn0, infDomain, null, 0, jColIdx + 1);
                DDTAInputClause ic = new DDTAInputClause(interval);
                ddtaTable.getInputs().add(ic);
            } else {
                throw new IllegalStateException("inputValues not null but utln: " + utln);
            }
        } else {
            DDTAInputClause ic = new DDTAInputClause(infDomain);
            ddtaTable.getInputs().add(ic);
        }
    }
}
Also used : UnaryTestNode(org.kie.dmn.feel.lang.ast.UnaryTestNode) QName(javax.xml.namespace.QName) ProcessedUnaryTest(org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest) UnaryTestInterpretedExecutableExpression(org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression) UnaryTestListNode(org.kie.dmn.feel.lang.ast.UnaryTestListNode) DDTAInputClause(org.kie.dmn.validation.dtanalysis.model.DDTAInputClause) DDTAInputClause(org.kie.dmn.validation.dtanalysis.model.DDTAInputClause) InputClause(org.kie.dmn.model.api.InputClause) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Example 7 with InputClause

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

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

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

the class DMNAlphaNetworkCompiler method initPropertyNames.

private void initPropertyNames(List<InputClause> input) {
    NodeList<Expression> propertyNamesArray = input.stream().map(inputClause -> inputClause.getInputExpression().getText()).map(StringLiteralExpr::new).collect(Collectors.toCollection(NodeList::new));
    ArrayCreationExpr array = new ArrayCreationExpr().setElementType(new ArrayType(parseType(String.class.getCanonicalName()))).setInitializer(new ArrayInitializerExpr(propertyNamesArray));
    template.findAll(StringLiteralExpr.class, n -> n.asString().equals("PROPERTY_NAMES")).forEach(r -> r.replace(array));
}
Also used : ArrayType(com.github.javaparser.ast.type.ArrayType) NodeList(com.github.javaparser.ast.NodeList) DecisionTable(org.kie.dmn.model.api.DecisionTable) ArrayCreationExpr(com.github.javaparser.ast.expr.ArrayCreationExpr) Logger(org.slf4j.Logger) ArrayType(com.github.javaparser.ast.type.ArrayType) InputClause(org.kie.dmn.model.api.InputClause) CodegenStringUtil.replaceStringLiteralExprWith(org.kie.dmn.feel.codegen.feel11.CodegenStringUtil.replaceStringLiteralExprWith) LoggerFactory(org.slf4j.LoggerFactory) CodegenStringUtil.replaceSimpleNameWith(org.kie.dmn.feel.codegen.feel11.CodegenStringUtil.replaceSimpleNameWith) Collectors(java.util.stream.Collectors) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) CodegenStringUtil.parseJavaClassTemplateFromResources(org.kie.dmn.feel.codegen.feel11.CodegenStringUtil.parseJavaClassTemplateFromResources) CodegenStringUtil(org.kie.dmn.feel.codegen.feel11.CodegenStringUtil) HitPolicy(org.kie.dmn.model.api.HitPolicy) CodegenStringUtil.blockHasComment(org.kie.dmn.feel.codegen.feel11.CodegenStringUtil.blockHasComment) List(java.util.List) StaticJavaParser.parseType(com.github.javaparser.StaticJavaParser.parseType) Expression(com.github.javaparser.ast.expr.Expression) CompilationUnit(com.github.javaparser.ast.CompilationUnit) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ArrayInitializerExpr(com.github.javaparser.ast.expr.ArrayInitializerExpr) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) BuiltinAggregator(org.kie.dmn.model.api.BuiltinAggregator) Expression(com.github.javaparser.ast.expr.Expression) ArrayInitializerExpr(com.github.javaparser.ast.expr.ArrayInitializerExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) ArrayCreationExpr(com.github.javaparser.ast.expr.ArrayCreationExpr)

Example 10 with InputClause

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

the class InputClauseConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    InputClause ic = (InputClause) parent;
    writeChildrenNode(writer, context, ic.getInputExpression(), INPUT_EXPRESSION);
    if (ic.getInputValues() != null)
        writeChildrenNode(writer, context, ic.getInputValues(), INPUT_VALUES);
}
Also used : TInputClause(org.kie.dmn.model.v1_2.TInputClause) InputClause(org.kie.dmn.model.api.InputClause)

Aggregations

InputClause (org.kie.dmn.model.api.InputClause)17 DecisionTable (org.kie.dmn.model.api.DecisionTable)8 OutputClause (org.kie.dmn.model.api.OutputClause)7 DecisionRule (org.kie.dmn.model.api.DecisionRule)6 QName (javax.xml.namespace.QName)4 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 DMNType (org.kie.dmn.api.core.DMNType)3 HitPolicy (org.kie.dmn.model.api.HitPolicy)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 Msg (org.kie.dmn.core.util.Msg)2 MsgUtil (org.kie.dmn.core.util.MsgUtil)2 Decision (org.kie.dmn.model.api.Decision)2 InformationItem (org.kie.dmn.model.api.InformationItem)2 RuleAnnotationClause (org.kie.dmn.model.api.RuleAnnotationClause)2 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)2 Logger (org.slf4j.Logger)2