use of org.kie.dmn.api.core.ast.DecisionNode in project drools by kiegroup.
the class DMNRuntimeImpl method evaluateByIdInternal.
private void evaluateByIdInternal(DMNModel model, DMNContext context, DMNResultImpl result, String id) {
boolean performRuntimeTypeCheck = performRuntimeTypeCheck(model);
DecisionNode decision = model.getDecisionById(id);
if (decision != null) {
evaluateDecision(context, result, decision, performRuntimeTypeCheck);
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, null, result, null, null, Msg.DECISION_NOT_FOUND_FOR_ID, id);
}
}
use of org.kie.dmn.api.core.ast.DecisionNode in project drools by kiegroup.
the class DMNRuntimeImpl method evaluateByNameInternal.
private void evaluateByNameInternal(DMNModel model, DMNContext context, DMNResultImpl result, String name) {
boolean performRuntimeTypeCheck = performRuntimeTypeCheck(model);
DecisionNode decision = model.getDecisionByName(name);
if (decision != null) {
evaluateDecision(context, result, decision, performRuntimeTypeCheck);
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, null, result, null, null, Msg.DECISION_NOT_FOUND_FOR_NAME, name);
}
}
use of org.kie.dmn.api.core.ast.DecisionNode in project drools by kiegroup.
the class DMNCompilerImpl method processDrgElements.
private void processDrgElements(DMNCompilerContext ctx, DMNFEELHelper feel, 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());
}
}
for (BusinessKnowledgeModelNode bkm : model.getBusinessKnowledgeModels()) {
BusinessKnowledgeModelNodeImpl bkmi = (BusinessKnowledgeModelNodeImpl) bkm;
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;
for (DRGElementCompiler dc : drgCompilers) {
if (di.getEvaluator() == null && dc.accept(d)) {
dc.compileEvaluator(d, this, ctx, model);
}
}
}
detectCycles(model);
}
use of org.kie.dmn.api.core.ast.DecisionNode in project kie-wb-common by kiegroup.
the class DMNMarshallerTest method test_function_java_WB_model.
@Test
public void test_function_java_WB_model() throws IOException {
final DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
@SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(null, this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final Stream<Node<?, ?>> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(g.nodes().iterator(), Spliterator.ORDERED), false);
final Optional<Decision> wbDecision = stream.filter(n -> n.getContent() instanceof ViewImpl).map(n -> (ViewImpl) n.getContent()).filter(n -> n.getDefinition() instanceof Decision).map(n -> (Decision) n.getDefinition()).findFirst();
wbDecision.ifPresent(d -> {
assertTrue(d.getExpression() instanceof FunctionDefinition);
final FunctionDefinition wbFunction = (FunctionDefinition) d.getExpression();
// This is what the WB expects
assertTrue(wbFunction.getAdditionalAttributes().containsKey(FunctionDefinition.KIND_QNAME));
assertEquals("J", wbFunction.getAdditionalAttributes().get(FunctionDefinition.KIND_QNAME));
});
final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
final DMNModel dmnModel = runtime.getModels().get(0);
final DecisionNode dmnDecision = dmnModel.getDecisions().iterator().next();
assertTrue(dmnDecision.getDecision().getExpression() instanceof org.kie.dmn.model.v1_1.FunctionDefinition);
final org.kie.dmn.model.v1_1.FunctionDefinition dmnFunction = (org.kie.dmn.model.v1_1.FunctionDefinition) dmnDecision.getDecision().getExpression();
assertTrue(dmnFunction.getAdditionalAttributes().containsKey(org.kie.dmn.model.v1_1.FunctionDefinition.KIND_QNAME));
assertEquals("J", dmnFunction.getAdditionalAttributes().get(org.kie.dmn.model.v1_1.FunctionDefinition.KIND_QNAME));
}
use of org.kie.dmn.api.core.ast.DecisionNode in project tck by dmn-tck.
the class DroolsTCKTest method executeTest.
@Override
public TestResult executeTest(Description description, TestSuiteContext context, TestCases.TestCase testCase) {
DroolsContext ctx = (DroolsContext) context;
logger.info("Executing test '{} / {}'\n", description.getClassName(), description.getMethodName());
DMNContext dmnctx = ctx.runtime.newContext();
testCase.getInputNode().forEach(in -> {
InputDataNode input = ctx.dmnmodel.getInputByName(in.getName());
DecisionNode decision = ctx.dmnmodel.getDecisionByName(in.getName());
if (input != null) {
// normally data input from file, should be pointing at a InputData in the model
dmnctx.set(in.getName(), parseValue(in, input));
} else if (decision != null) {
// the test case offers a pre-evaluated Decision
dmnctx.set(in.getName(), parseValue(in, decision));
} else {
throw new RuntimeException("Unable to locate InputData node or a Decision node for name: " + in.getName());
}
});
DMNContext resultctx = dmnctx;
List<String> failures = new ArrayList<>();
for (TestCases.TestCase.ResultNode rn : testCase.getResultNode()) {
try {
String name = rn.getName();
DMNResult dmnResult = ctx.runtime.evaluateDecisionByName(ctx.dmnmodel, name, resultctx);
if (!dmnResult.getMessages().isEmpty()) {
logger.info("Messages: \n-----\n{}-----\n", dmnResult.getMessages().stream().map(m -> m.toString()).collect(Collectors.joining("\n")));
}
resultctx = dmnResult.getContext();
Object expected = parseValue(rn, ctx.dmnmodel.getDecisionByName(name));
Object actual = resultctx.get(name);
if (rn.isErrorResult()) {
if (actual != null) {
failures.add("FAILURE: '" + name + "' expected error but found='" + actual + "'");
}
} else {
if (dmnResult.hasErrors()) {
for (DMNMessage msg : dmnResult.getMessages(DMNMessage.Severity.ERROR)) {
failures.add(msg.toString());
}
}
if (!isEquals(expected, actual)) {
failures.add("FAILURE: '" + name + "' expected='" + expected + "' but found='" + actual + "'");
}
}
} catch (Throwable t) {
failures.add("FAILURE: unnexpected exception executing test case '" + description.getClassName() + " / " + description.getMethodName() + "': " + t.getClass().getName());
logger.error("FAILURE: unnexpected exception executing test case '{} / {}'", description.getClassName(), description.getMethodName(), t);
}
}
// DMNResult dmnResult = ctx.runtime.evaluateAll( ctx.dmnmodel, dmnctx );
logger.info("Result context: {}\n", resultctx);
// if( ! dmnResult.getMessages().isEmpty() ) {
// logger.info( "Messages: \n-----\n{}-----\n", dmnResult.getMessages().stream().map( m -> m.toString() ).collect( Collectors.joining( "\n" ) ) );
// }
//
// List<String> failures = new ArrayList<>();
// if( dmnResult.hasErrors() ) {
// for( DMNMessage msg : dmnResult.getMessages( DMNMessage.Severity.ERROR ) ) {
// failures.add( msg.toString() );
// }
// }
// testCase.getResultNode().forEach( rn -> {
// try {
// String name = rn.getName();
// Object expected = parseValue( rn, ctx.dmnmodel.getDecisionByName( name ) );
// Object actual = resultctx.get( name );
// if( ! isEquals( expected, actual ) ) {
// failures.add( "FAILURE: '"+name+"' expected='"+expected+"' but found='"+actual+"'" );
// }
// } catch ( Throwable t ) {
// failures.add( "FAILURE: unnexpected exception executing test case '"+description.getClassName()+" / " +description.getMethodName()+"': "+t.getClass().getName() );
// logger.error( "FAILURE: unnexpected exception executing test case '{} / {}'", description.getClassName(), description.getMethodName(), t );
// }
// } );
TestResult.Result r = !failures.isEmpty() ? TestResult.Result.ERROR : TestResult.Result.SUCCESS;
return new TestResult(r, failures.stream().collect(Collectors.joining("\n")));
}
Aggregations