Search in sources :

Example 26 with DecisionNode

use of org.kie.dmn.api.core.ast.DecisionNode in project drools by kiegroup.

the class DMNInputRuntimeTest method testOrdering.

@Test
public void testOrdering() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Order.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6318588b-c32f-4070-848b-bd8017e6b94e", "Drawing 1");
    int index = 1;
    for (InputDataNode node : dmnModel.getInputs()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
    index = 1;
    for (DecisionNode node : dmnModel.getDecisions()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
    index = 1;
    for (BusinessKnowledgeModelNode node : dmnModel.getBusinessKnowledgeModels()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
    index = 1;
    for (ItemDefNode node : dmnModel.getItemDefinitions()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
    index = 1;
    for (DecisionServiceNode node : dmnModel.getDecisionServices()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
}
Also used : DecisionServiceNode(org.kie.dmn.api.core.ast.DecisionServiceNode) ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 27 with DecisionNode

use of org.kie.dmn.api.core.ast.DecisionNode in project drools by kiegroup.

the class DMNCompilerImpl method detectCycles.

private void detectCycles(DMNModelImpl model) {
    /*
        Boolean.TRUE = node is either safe or already reported for having a cyclic dependency
        Boolean.FALSE = node is being checked at the moment
         */
    final Map<DecisionNodeImpl, Boolean> registry = new HashMap<>();
    for (DecisionNode decision : model.getDecisions()) {
        final DecisionNodeImpl decisionNode = (DecisionNodeImpl) decision;
        detectCycles(decisionNode, registry, model);
    }
}
Also used : HashMap(java.util.HashMap) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl)

Example 28 with DecisionNode

use of org.kie.dmn.api.core.ast.DecisionNode in project drools by kiegroup.

the class DMNCompilerImpl method linkRequirements.

public void linkRequirements(DMNModelImpl model, DMNBaseNode node) {
    for (InformationRequirement ir : node.getInformationRequirement()) {
        if (ir.getRequiredInput() != null) {
            String id = getId(ir.getRequiredInput());
            InputDataNode input = model.getInputById(id);
            if (input != null) {
                node.addDependency(input.getName(), input);
            } else {
                MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, ir.getRequiredInput(), model, null, null, Msg.REQ_INPUT_NOT_FOUND_FOR_NODE, id, node.getName());
            }
        } else if (ir.getRequiredDecision() != null) {
            String id = getId(ir.getRequiredDecision());
            DecisionNode dn = model.getDecisionById(id);
            if (dn != null) {
                node.addDependency(dn.getName(), dn);
            } else {
                MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, ir.getRequiredDecision(), model, null, null, Msg.REQ_DECISION_NOT_FOUND_FOR_NODE, id, node.getName());
            }
        }
    }
    for (KnowledgeRequirement kr : node.getKnowledgeRequirement()) {
        if (kr.getRequiredKnowledge() != null) {
            String id = getId(kr.getRequiredKnowledge());
            BusinessKnowledgeModelNode bkmn = model.getBusinessKnowledgeModelById(id);
            DecisionServiceNode dsn = model.getDecisionServiceById(id);
            if (bkmn != null) {
                node.addDependency(bkmn.getName(), bkmn);
            } else if (dsn != null) {
                node.addDependency(dsn.getName(), dsn);
            } else {
                MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, kr.getRequiredKnowledge(), model, null, null, // TODO or a DS ?
                Msg.REQ_BKM_NOT_FOUND_FOR_NODE, id, node.getName());
            }
        }
    }
}
Also used : KnowledgeRequirement(org.kie.dmn.model.api.KnowledgeRequirement) DecisionServiceNode(org.kie.dmn.api.core.ast.DecisionServiceNode) InformationRequirement(org.kie.dmn.model.api.InformationRequirement) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)

Example 29 with DecisionNode

use of org.kie.dmn.api.core.ast.DecisionNode in project drools by kiegroup.

the class DMNEvaluatorCompiler method compileContext.

private DMNExpressionEvaluator compileContext(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String contextName, Context expression) {
    Context ctxDef = expression;
    DMNContextEvaluator ctxEval = new DMNContextEvaluator(node.getName(), ctxDef);
    ctx.enterFrame();
    try {
        for (ContextEntry ce : ctxDef.getContextEntry()) {
            if (ce.getVariable() != null) {
                String entryName = ce.getVariable().getName();
                DMNCompilerHelper.checkVariableName(model, node.getSource(), entryName);
                DMNType entryType = compiler.resolveTypeRef(model, ce.getVariable(), ce.getVariable(), ce.getVariable().getTypeRef());
                // add context entry to the list of available variables for the following entries
                ctx.setVariable(entryName, entryType);
                DMNExpressionEvaluator evaluator = compileExpression(ctx, model, node, entryName, ce.getExpression());
                ctxEval.addEntry(entryName, entryType, evaluator, ce);
            } else {
                // if the variable is not defined, then it should be the last
                // entry in the context and the result of this context evaluation is the
                // result of this expression itself
                // TODO: if it is not the last entry, raise error message
                DMNType type = null;
                if (ctxDef.getParent() instanceof ContextEntry && ((ContextEntry) ctxDef.getParent()).getVariable() != null) {
                    ContextEntry parentEntry = (ContextEntry) ctxDef.getParent();
                    type = compiler.resolveTypeRef(model, parentEntry.getVariable(), parentEntry.getVariable(), parentEntry.getVariable().getTypeRef());
                } else if (node instanceof BusinessKnowledgeModelNode) {
                    type = ((BusinessKnowledgeModelNode) node).getResultType();
                } else if (node instanceof DecisionNode) {
                    type = ((DecisionNode) node).getResultType();
                }
                ctxEval.addEntry(DMNContextEvaluator.RESULT_ENTRY, type, compileExpression(ctx, model, node, contextName, ce.getExpression()), ce);
            }
        }
    } finally {
        ctx.exitFrame();
    }
    return ctxEval;
}
Also used : Context(org.kie.dmn.model.api.Context) DMNContextEvaluator(org.kie.dmn.core.ast.DMNContextEvaluator) DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) ContextEntry(org.kie.dmn.model.api.ContextEntry) DMNType(org.kie.dmn.api.core.DMNType)

Example 30 with DecisionNode

use of org.kie.dmn.api.core.ast.DecisionNode in project drools-wb by kiegroup.

the class DMNTypeServiceImplTest method verifyFactModelTree.

/**
 * Verify the <code>FactModelTree</code> generated for a <b>given</b> <code>DMNNode</code> (<code>InputDataNode</code> or <code>DecisionNode</code>)
 * @param factModelTuple
 * @param dmnNode
 * @param hiddenFacts
 */
private void verifyFactModelTree(FactModelTuple factModelTuple, DMNNode dmnNode, SortedMap<String, FactModelTree> hiddenFacts, Map<String, String> importedModelsMap) {
    final String name = importedModelsMap.containsKey(dmnNode.getModelNamespace()) ? importedModelsMap.get(dmnNode.getModelNamespace()) + "." + dmnNode.getName() : dmnNode.getName();
    // Check the FactModelTree has been mapped between visible facts
    assertTrue(factModelTuple.getVisibleFacts().containsKey(name));
    final FactModelTree mappedFactModelTree = factModelTuple.getVisibleFacts().get(name);
    // Check the FactModelTree is not null
    assertNotNull(mappedFactModelTree);
    DMNType originalType;
    // Retrieving DMNType mapped by original DMNNode
    if (dmnNode instanceof InputDataNode) {
        originalType = ((InputDataNode) dmnNode).getType();
    } else if (dmnNode instanceof DecisionNode) {
        originalType = ((DecisionNode) dmnNode).getResultType();
    } else {
        fail("Unrecognized node type " + name + " -> " + dmnNode.getClass().getCanonicalName());
        return;
    }
    if (originalType.isCollection()) {
        // if original type is a collection
        verifyCollectionDMNType(mappedFactModelTree, originalType, hiddenFacts);
    } else {
        // Otherwise look inside for specific cases
        if (originalType.isComposite()) {
            verifyCompositeDMNType(mappedFactModelTree, originalType, hiddenFacts);
        } else {
            verifySimpleDMNType(mappedFactModelTree, originalType);
        }
    }
}
Also used : InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) DMNType(org.kie.dmn.api.core.DMNType)

Aggregations

DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)32 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)16 DMNType (org.kie.dmn.api.core.DMNType)12 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)10 DecisionServiceNode (org.kie.dmn.api.core.ast.DecisionServiceNode)9 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)9 DMNMessage (org.kie.dmn.api.core.DMNMessage)7 DMNModel (org.kie.dmn.api.core.DMNModel)7 DMNDecisionResult (org.kie.dmn.api.core.DMNDecisionResult)6 DMNNode (org.kie.dmn.api.core.ast.DMNNode)6 Optional (java.util.Optional)5 DMNContext (org.kie.dmn.api.core.DMNContext)5 DMNResult (org.kie.dmn.api.core.DMNResult)5 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)5 DMNBaseNode (org.kie.dmn.core.ast.DMNBaseNode)5 DecisionServiceNodeImpl (org.kie.dmn.core.ast.DecisionServiceNodeImpl)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 List (java.util.List)4 HashMap (java.util.HashMap)3