Search in sources :

Example 1 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem in project drools by kiegroup.

the class XLS2DMNParser method appendInputData.

private void appendInputData(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
    Set<String> usedRI = new LinkedHashSet<>();
    for (DTHeaderInfo hi : headerInfos.values()) {
        for (String ri : hi.getRequiredInput()) {
            if (!usedRI.contains(ri)) {
                InputData id = new TInputData();
                id.setName(ri);
                id.setId("id_" + CodegenStringUtil.escapeIdentifier(ri));
                InformationItem variable = new TInformationItem();
                variable.setName(ri);
                variable.setId("idvar_" + CodegenStringUtil.escapeIdentifier(ri));
                variable.setTypeRef(new QName("Any"));
                id.setVariable(variable);
                definitions.getDrgElement().add(id);
            }
            usedRI.add(ri);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TInputData(org.kie.dmn.model.v1_2.TInputData) QName(javax.xml.namespace.QName) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) TInputData(org.kie.dmn.model.v1_2.TInputData) InputData(org.kie.dmn.model.api.InputData)

Example 2 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem 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 3 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem in project drools by kiegroup.

the class DMNCompilerImpl method processDrgElements.

private void processDrgElements(DMNCompilerContext ctx, DMNModelImpl model, Definitions dmndefs) {
    for (DRGElement e : dmndefs.getDrgElement()) {
        boolean foundIt = false;
        for (DRGElementCompiler dc : drgCompilers) {
            if (dc.accept(e)) {
                foundIt = true;
                dc.compileNode(e, this, model);
                continue;
            }
        }
        if (!foundIt) {
            MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, e, model, null, null, Msg.UNSUPPORTED_ELEMENT, e.getClass().getSimpleName(), e.getId());
        }
    }
    // in DMN v1.1 the DecisionService is not on the DRGElement but as an extension
    if (dmndefs.getExtensionElements() != null) {
        List<DecisionServices> decisionServices = dmndefs.getExtensionElements().getAny().stream().filter(DecisionServices.class::isInstance).map(DecisionServices.class::cast).collect(Collectors.toList());
        for (DecisionServices dss : decisionServices) {
            for (DecisionService ds : dss.getDecisionService()) {
                // compatibility with DMN v1.1, create Decision Service's variable:
                if (ds.getVariable() == null) {
                    InformationItem variable = new TInformationItem();
                    variable.setId(UUID.randomUUID().toString());
                    variable.setName(ds.getName());
                    variable.setParent(ds);
                    // the introduction of an on-the-fly ItemDefinition has been removed. The variable type will be evaluated as feel:any, or in v1.2 will receive the (user-defined, explicit) ItemDefinition type.
                    ds.setVariable(variable);
                }
                // continuing with normal compilation of Decision Service:
                boolean foundIt = false;
                for (DRGElementCompiler dc : drgCompilers) {
                    if (dc.accept(ds)) {
                        foundIt = true;
                        dc.compileNode(ds, this, model);
                        continue;
                    }
                }
            }
        }
    }
    for (DecisionServiceNode ds : model.getDecisionServices()) {
        DecisionServiceNodeImpl dsi = (DecisionServiceNodeImpl) ds;
        dsi.addModelImportAliases(model.getImportAliasesForNS());
        for (DRGElementCompiler dc : drgCompilers) {
            if (dsi.getEvaluator() == null && dc.accept(dsi)) {
                // will compile in fact all DS belonging to this model (not the imported ones).
                dc.compileEvaluator(dsi, this, ctx, model);
            }
        }
    }
    for (BusinessKnowledgeModelNode bkm : model.getBusinessKnowledgeModels()) {
        BusinessKnowledgeModelNodeImpl bkmi = (BusinessKnowledgeModelNodeImpl) bkm;
        bkmi.addModelImportAliases(model.getImportAliasesForNS());
        for (DRGElementCompiler dc : drgCompilers) {
            if (bkmi.getEvaluator() == null && dc.accept(bkm)) {
                dc.compileEvaluator(bkm, this, ctx, model);
            }
        }
    }
    for (DecisionNode d : model.getDecisions()) {
        DecisionNodeImpl di = (DecisionNodeImpl) d;
        di.addModelImportAliases(model.getImportAliasesForNS());
        for (DRGElementCompiler dc : drgCompilers) {
            if (di.getEvaluator() == null && dc.accept(d)) {
                dc.compileEvaluator(d, this, ctx, model);
            }
        }
    }
    for (AfterProcessDrgElements callback : afterDRGcallbacks) {
        logger.debug("About to invoke callback: {}", callback);
        callback.callback(this, ctx, model);
    }
    detectCycles(model);
}
Also used : DecisionServiceNode(org.kie.dmn.api.core.ast.DecisionServiceNode) DecisionServices(org.kie.dmn.model.v1_1.extensions.DecisionServices) TInformationItem(org.kie.dmn.model.v1_1.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) DecisionService(org.kie.dmn.model.api.DecisionService) TInformationItem(org.kie.dmn.model.v1_1.TInformationItem) BusinessKnowledgeModelNodeImpl(org.kie.dmn.core.ast.BusinessKnowledgeModelNodeImpl) DRGElement(org.kie.dmn.model.api.DRGElement) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl)

Example 4 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem in project kie-wb-common by kiegroup.

the class InformationItemPrimaryPropertyConverter method dmnFromWB.

public static TInformationItem dmnFromWB(final InformationItemPrimary wb, final DMNModelInstrumentedBase parent) {
    if (wb == null) {
        return null;
    }
    final TInformationItem result = new TInformationItem();
    final QName typeRef = wb.getTypeRef();
    result.setId(wb.getId().getValue());
    result.setName(getParentName(parent));
    QNamePropertyConverter.setDMNfromWB(typeRef, result::setTypeRef);
    return result;
}
Also used : QName(org.kie.workbench.common.dmn.api.property.dmn.QName) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem)

Example 5 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem in project kie-wb-common by kiegroup.

the class DMNMarshallerImportsHelperStandaloneImpl method updateInformationItem.

private void updateInformationItem(final String namespace, final DRGElement drgElement) {
    getInformationItem(drgElement).ifPresent(informationItem -> {
        final InformationItem tInformationItem = new TInformationItem();
        final QName qName = informationItem.getTypeRef();
        if (qName != null && !isBuiltInType(qName.getLocalPart())) {
            tInformationItem.setTypeRef(new QName(qName.getNamespaceURI(), namespace + "." + qName.getLocalPart(), qName.getPrefix()));
            setInformationItem(drgElement, tInformationItem);
        }
    });
}
Also used : QName(javax.xml.namespace.QName) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem)

Aggregations

TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)14 Test (org.junit.Test)9 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)7 QName (javax.xml.namespace.QName)5 InformationItem (org.kie.dmn.model.api.InformationItem)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)4 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)4 TDecision (org.kie.dmn.model.v1_2.TDecision)3 TInputData (org.kie.dmn.model.v1_2.TInputData)3 DRGElement (org.kie.dmn.model.api.DRGElement)2 TContextEntry (org.kie.dmn.model.v1_2.TContextEntry)2 TDecisionService (org.kie.dmn.model.v1_2.TDecisionService)2 TFunctionDefinition (org.kie.dmn.model.v1_2.TFunctionDefinition)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2 LinkedHashSet (java.util.LinkedHashSet)1 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)1 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)1 DecisionServiceNode (org.kie.dmn.api.core.ast.DecisionServiceNode)1