Search in sources :

Example 6 with Decision

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

the class DecisionCompiler method compileNode.

@Override
public void compileNode(DRGElement de, DMNCompilerImpl compiler, DMNModelImpl model) {
    Decision decision = (Decision) de;
    DecisionNodeImpl dn = new DecisionNodeImpl(decision);
    DMNType type = null;
    if (decision.getVariable() == null) {
        DMNCompilerHelper.reportMissingVariable(model, de, decision, Msg.MISSING_VARIABLE_FOR_DECISION);
        return;
    }
    DMNCompilerHelper.checkVariableName(model, decision, decision.getName());
    if (decision.getVariable() != null && decision.getVariable().getTypeRef() != null) {
        type = compiler.resolveTypeRef(model, decision, decision.getVariable(), decision.getVariable().getTypeRef());
    } else {
        type = compiler.resolveTypeRef(model, decision, decision, null);
    }
    dn.setResultType(type);
    model.addDecision(dn);
}
Also used : DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) Decision(org.kie.dmn.model.api.Decision) DMNType(org.kie.dmn.api.core.DMNType)

Example 7 with Decision

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

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

the class DMNRuntimeTest method buildSimplifiedDefinitions.

private Definitions buildSimplifiedDefinitions(final String namespace, final String... decisions) {
    final Definitions def = new TDefinitions();
    def.setNamespace(namespace);
    for (final String d : decisions) {
        final Decision dec = new TDecision();
        dec.setName(d);
        def.getDrgElement().add(dec);
        def.addChildren(dec);
        dec.setParent(def);
    }
    return def;
}
Also used : TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) TDecision(org.kie.dmn.model.v1_1.TDecision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) TDecision(org.kie.dmn.model.v1_1.TDecision) Decision(org.kie.dmn.model.api.Decision)

Example 9 with Decision

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

the class DefinitionsConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    Definitions def = (Definitions) parent;
    for (Import i : def.getImport()) {
        writeChildrenNode(writer, context, i, IMPORT);
    }
    for (ItemDefinition id : def.getItemDefinition()) {
        writeChildrenNode(writer, context, id, ITEM_DEFINITION);
    }
    for (DRGElement e : def.getDrgElement()) {
        String nodeName = DRG_ELEMENT;
        if (e instanceof BusinessKnowledgeModel) {
            nodeName = "businessKnowledgeModel";
        } else if (e instanceof Decision) {
            nodeName = "decision";
        } else if (e instanceof InputData) {
            nodeName = "inputData";
        } else if (e instanceof KnowledgeSource) {
            nodeName = "knowledgeSource";
        } else if (e instanceof DecisionService) {
            nodeName = "decisionService";
        }
        writeChildrenNode(writer, context, e, nodeName);
    }
    for (Artifact a : def.getArtifact()) {
        String nodeName = ARTIFACT;
        if (a instanceof Association) {
            nodeName = "association";
        } else if (a instanceof TextAnnotation) {
            nodeName = "textAnnotation";
        }
        writeChildrenNode(writer, context, a, nodeName);
    }
    for (ElementCollection ec : def.getElementCollection()) {
        writeChildrenNode(writer, context, ec, ELEMENT_COLLECTION);
    }
    for (BusinessContextElement bce : def.getBusinessContextElement()) {
        String nodeName = BUSINESS_CONTEXT_ELEMENT;
        if (bce instanceof OrganizationUnit) {
            nodeName = "organizationUnit";
        } else if (bce instanceof PerformanceIndicator) {
            nodeName = "performanceIndicator";
        }
        writeChildrenNode(writer, context, bce, nodeName);
    }
    if (def.getDMNDI() != null) {
        writeChildrenNode(writer, context, def.getDMNDI(), "DMNDI");
    }
}
Also used : Import(org.kie.dmn.model.api.Import) PerformanceIndicator(org.kie.dmn.model.api.PerformanceIndicator) TDefinitions(org.kie.dmn.model.v1_2.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) BusinessContextElement(org.kie.dmn.model.api.BusinessContextElement) Decision(org.kie.dmn.model.api.Decision) Artifact(org.kie.dmn.model.api.Artifact) DecisionService(org.kie.dmn.model.api.DecisionService) Association(org.kie.dmn.model.api.Association) KnowledgeSource(org.kie.dmn.model.api.KnowledgeSource) OrganizationUnit(org.kie.dmn.model.api.OrganizationUnit) BusinessKnowledgeModel(org.kie.dmn.model.api.BusinessKnowledgeModel) ElementCollection(org.kie.dmn.model.api.ElementCollection) InputData(org.kie.dmn.model.api.InputData) TextAnnotation(org.kie.dmn.model.api.TextAnnotation) DRGElement(org.kie.dmn.model.api.DRGElement)

Example 10 with Decision

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

the class DMNRuntimeTest method buildSimplifiedDefinitions.

private Definitions buildSimplifiedDefinitions(final String namespace, final String... decisions) {
    final Definitions def = new TDefinitions();
    def.setNamespace(namespace);
    for (final String d : decisions) {
        final Decision dec = new TDecision();
        dec.setName(d);
        def.getDrgElement().add(dec);
        def.addChildren(dec);
        dec.setParent(def);
    }
    return def;
}
Also used : TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) TDecision(org.kie.dmn.model.v1_1.TDecision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) TDecision(org.kie.dmn.model.v1_1.TDecision) Decision(org.kie.dmn.model.api.Decision)

Aggregations

Decision (org.kie.dmn.model.api.Decision)19 Definitions (org.kie.dmn.model.api.Definitions)8 InputData (org.kie.dmn.model.api.InputData)6 BusinessKnowledgeModel (org.kie.dmn.model.api.BusinessKnowledgeModel)5 DMNElementReference (org.kie.dmn.model.api.DMNElementReference)5 DRGElement (org.kie.dmn.model.api.DRGElement)5 InformationRequirement (org.kie.dmn.model.api.InformationRequirement)5 Artifact (org.kie.dmn.model.api.Artifact)4 Association (org.kie.dmn.model.api.Association)4 AuthorityRequirement (org.kie.dmn.model.api.AuthorityRequirement)4 BusinessContextElement (org.kie.dmn.model.api.BusinessContextElement)4 ElementCollection (org.kie.dmn.model.api.ElementCollection)4 Expression (org.kie.dmn.model.api.Expression)4 Import (org.kie.dmn.model.api.Import)4 ItemDefinition (org.kie.dmn.model.api.ItemDefinition)4 KnowledgeRequirement (org.kie.dmn.model.api.KnowledgeRequirement)4 KnowledgeSource (org.kie.dmn.model.api.KnowledgeSource)4 OrganizationUnit (org.kie.dmn.model.api.OrganizationUnit)4 PerformanceIndicator (org.kie.dmn.model.api.PerformanceIndicator)4 TextAnnotation (org.kie.dmn.model.api.TextAnnotation)4