use of org.kie.dmn.core.impl.DMNRuntimeImpl in project drools by kiegroup.
the class DMNRuntimeTypeCheckTest method testAskTypeCheckInKModuleButOverrideRuntime.
@Test
public void testAskTypeCheckInKModuleButOverrideRuntime() {
DMNRuntime runtime = getRuntimeWithTypeCheckOption("true", ks.getResources().newClassPathResource("forTypeCheckTest.dmn", this.getClass()));
((DMNRuntimeImpl) runtime).setOption(new RuntimeTypeCheckOption(false));
assertPerformTypeCheck(runtime);
}
use of org.kie.dmn.core.impl.DMNRuntimeImpl in project drools by kiegroup.
the class DMNRuntimeTypeCheckTest method testExplicitDisableTypeCheckInKModuleButOverrideRuntime.
@Test
public void testExplicitDisableTypeCheckInKModuleButOverrideRuntime() {
DMNRuntime runtime = getRuntimeWithTypeCheckOption("false", ks.getResources().newClassPathResource("forTypeCheckTest.dmn", this.getClass()));
((DMNRuntimeImpl) runtime).setOption(new RuntimeTypeCheckOption(true));
assertPerformTypeCheck(runtime);
}
use of org.kie.dmn.core.impl.DMNRuntimeImpl in project drools by kiegroup.
the class DMNRuntimeTypeCheckTest method testDefaultNoTypeCheckButOverrideRuntime.
@Test
public void testDefaultNoTypeCheckButOverrideRuntime() {
// do NOT use the DMNRuntimeUtil as that enables typeSafe check override for runtime.
final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0"), ks.getResources().newClassPathResource("forTypeCheckTest.dmn", this.getClass()));
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
((DMNRuntimeImpl) runtime).setOption(new RuntimeTypeCheckOption(true));
assertPerformTypeCheck(runtime);
}
use of org.kie.dmn.core.impl.DMNRuntimeImpl in project drools by kiegroup.
the class DMNRuntimeUtil method typeSafeGetKieRuntime.
private static DMNRuntime typeSafeGetKieRuntime(final KieContainer kieContainer) {
DMNRuntime dmnRuntime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
((DMNRuntimeImpl) dmnRuntime).setOption(new RuntimeTypeCheckOption(true));
return dmnRuntime;
}
use of org.kie.dmn.core.impl.DMNRuntimeImpl in project drools by kiegroup.
the class DMNContextEvaluator method evaluate.
@Override
public EvaluatorResult evaluate(DMNRuntimeEventManager eventManager, DMNResult dmnr) {
DMNResultImpl result = (DMNResultImpl) dmnr;
// when this evaluator is executed, it should either return a Map of key/value pairs
// where keys are the name of the entries and values are the result of the evaluations
// OR if a default result is implemented, it should return the result instead
Map<String, Object> results = new HashMap<>();
DMNContext previousContext = result.getContext();
DMNContextImpl dmnContext = (DMNContextImpl) previousContext.clone();
result.setContext(dmnContext);
try {
for (ContextEntryDef ed : entries) {
try {
EvaluatorResult er = ed.getEvaluator().evaluate(eventManager, result);
if (er.getResultType() == ResultType.SUCCESS) {
Object value = er.getResult();
if (!ed.getType().isCollection() && value instanceof Collection && ((Collection) value).size() == 1) {
// spec defines that "a=[a]", i.e., singleton collections should be treated as the single element
// and vice-versa
value = ((Collection) value).toArray()[0];
}
if (((DMNRuntimeImpl) eventManager.getRuntime()).performRuntimeTypeCheck(result.getModel())) {
if (!(ed.getContextEntry().getExpression() instanceof FunctionDefinition)) {
// checking directly the result type...
if (ed.getType() != null && !ed.getType().isAssignableValue(value)) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, contextDef, result, null, null, Msg.ERROR_EVAL_NODE_RESULT_WRONG_TYPE, ed.getName(), ed.getType(), value);
return new EvaluatorResultImpl(results, ResultType.FAILURE);
}
} else {
// TODO ...will need calculation/inference of function return type.
}
}
results.put(ed.getName(), value);
dmnContext.set(ed.getName(), value);
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, contextDef, result, null, null, Msg.ERR_EVAL_CTX_ENTRY_ON_CTX, ed.getName(), name);
return new EvaluatorResultImpl(results, ResultType.FAILURE);
}
} catch (Exception e) {
logger.error("Error invoking expression for node '" + name + "'.", e);
return new EvaluatorResultImpl(results, ResultType.FAILURE);
}
}
} finally {
result.setContext(previousContext);
}
if (results.containsKey(RESULT_ENTRY)) {
return new EvaluatorResultImpl(results.get(RESULT_ENTRY), ResultType.SUCCESS);
} else {
return new EvaluatorResultImpl(results, ResultType.SUCCESS);
}
}
Aggregations