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++));
}
}
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);
}
}
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());
}
}
}
}
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;
}
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);
}
}
}
Aggregations