Search in sources :

Example 6 with DRGElement

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

the class DefinitionsConverter method assignChildElement.

@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
    Definitions def = (Definitions) parent;
    if (IMPORT.equals(nodeName)) {
        def.getImport().add((Import) child);
    } else if (ITEM_DEFINITION.equals(nodeName)) {
        def.getItemDefinition().add((ItemDefinition) child);
    } else if (child instanceof DRGElement) {
        def.getDrgElement().add((DRGElement) child);
    } else if (child instanceof Artifact) {
        def.getArtifact().add((Artifact) child);
    } else if (ELEMENT_COLLECTION.equals(nodeName)) {
        def.getElementCollection().add((ElementCollection) child);
    } else if (child instanceof BusinessContextElement) {
        def.getBusinessContextElement().add((BusinessContextElement) child);
    } else if (child instanceof DMNDI) {
        DMNDI dmndi = (DMNDI) child;
        dmndi.normalize();
        def.setDMNDI(dmndi);
    } else {
        super.assignChildElement(def, nodeName, child);
    }
}
Also used : TDefinitions(org.kie.dmn.model.v1_2.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) DMNDI(org.kie.dmn.model.api.dmndi.DMNDI) BusinessContextElement(org.kie.dmn.model.api.BusinessContextElement) Artifact(org.kie.dmn.model.api.Artifact) DRGElement(org.kie.dmn.model.api.DRGElement)

Example 7 with DRGElement

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

the class DefinitionsConverter method assignChildElement.

@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
    Definitions def = (Definitions) parent;
    if (IMPORT.equals(nodeName)) {
        def.getImport().add((Import) child);
    } else if (ITEM_DEFINITION.equals(nodeName)) {
        def.getItemDefinition().add((ItemDefinition) child);
    } else if (child instanceof DRGElement) {
        def.getDrgElement().add((DRGElement) child);
    } else if (child instanceof Artifact) {
        def.getArtifact().add((Artifact) child);
    } else if (ELEMENT_COLLECTION.equals(nodeName)) {
        def.getElementCollection().add((ElementCollection) child);
    } else if (child instanceof BusinessContextElement) {
        def.getBusinessContextElement().add((BusinessContextElement) child);
    } else if (child instanceof DMNDI) {
        DMNDI dmndi = (DMNDI) child;
        dmndi.normalize();
        def.setDMNDI(dmndi);
    } else {
        super.assignChildElement(def, nodeName, child);
    }
}
Also used : TDefinitions(org.kie.dmn.model.v1_4.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) DMNDI(org.kie.dmn.model.api.dmndi.DMNDI) BusinessContextElement(org.kie.dmn.model.api.BusinessContextElement) Artifact(org.kie.dmn.model.api.Artifact) DRGElement(org.kie.dmn.model.api.DRGElement)

Example 8 with DRGElement

use of org.kie.dmn.model.api.DRGElement 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";
        } else if (a instanceof Group) {
            nodeName = "group";
        }
        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 : Group(org.kie.dmn.model.api.Group) Import(org.kie.dmn.model.api.Import) PerformanceIndicator(org.kie.dmn.model.api.PerformanceIndicator) Definitions(org.kie.dmn.model.api.Definitions) TDefinitions(org.kie.dmn.model.v1_3.TDefinitions) 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 9 with DRGElement

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

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

the class SignavioTest method testUnmarshall.

@Test
public void testUnmarshall() {
    DMNRuntime runtime = createRuntime("Test_Signavio_multiple.dmn");
    DMNModel model0 = runtime.getModels().get(0);
    Definitions definitions = model0.getDefinitions();
    DRGElement decision = definitions.getDrgElement().stream().filter(e -> e.getName().equals("greetingForEachPersonInPersons")).findFirst().orElseThrow(IllegalStateException::new);
    Object extElement = decision.getExtensionElements().getAny().get(0);
    assertThat(extElement, is(instanceOf(MultiInstanceDecisionLogic.class)));
    MultiInstanceDecisionLogic mid = (MultiInstanceDecisionLogic) extElement;
    LOG.info("{}", mid);
    assertThat(mid.getIterationExpression(), is("persons"));
    assertThat(mid.getIteratorShapeId(), is("id-707bbdf74438414623ac5d7067805b38"));
    assertThat(mid.getAggregationFunction(), is("COLLECT"));
    assertThat(mid.getTopLevelDecisionId(), is("id-7a23e2f201e3e0db3c991313cff5cd2b"));
}
Also used : Definitions(org.kie.dmn.model.api.Definitions) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DRGElement(org.kie.dmn.model.api.DRGElement) Test(org.junit.Test)

Aggregations

DRGElement (org.kie.dmn.model.api.DRGElement)25 Definitions (org.kie.dmn.model.api.Definitions)15 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 ItemDefinition (org.kie.dmn.model.api.ItemDefinition)8 Artifact (org.kie.dmn.model.api.Artifact)7 BusinessContextElement (org.kie.dmn.model.api.BusinessContextElement)7 Decision (org.kie.dmn.model.api.Decision)7 Import (org.kie.dmn.model.api.Import)7 BusinessKnowledgeModel (org.kie.dmn.model.api.BusinessKnowledgeModel)6 InputData (org.kie.dmn.model.api.InputData)6 DMNModel (org.kie.dmn.api.core.DMNModel)4 Association (org.kie.dmn.model.api.Association)4 DecisionService (org.kie.dmn.model.api.DecisionService)4 ElementCollection (org.kie.dmn.model.api.ElementCollection)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 DMNShape (org.kie.dmn.model.api.dmndi.DMNShape)4