use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class SignavioTest method assertStartsWithAnA.
private void assertStartsWithAnA(final DMNRuntime runtime, final String testString, final boolean startsWithAnA) {
DMNContext context = runtime.newContext();
context.set("surname", testString);
DMNModel model0 = runtime.getModels().get(0);
DMNResult evaluateAll = runtime.evaluateAll(model0, context);
evaluateAll.getMessages().forEach(System.out::println);
assertFalse(evaluateAll.getMessages().toString(), evaluateAll.hasErrors());
assertEquals(startsWithAnA, evaluateAll.getContext().get("startsWithAnA"));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNRuntimeImpl method evaluateBKM.
private void evaluateBKM(DMNContext context, DMNResultImpl result, BusinessKnowledgeModelNode b, boolean typeCheck) {
BusinessKnowledgeModelNodeImpl bkm = (BusinessKnowledgeModelNodeImpl) b;
if (isNodeValueDefined(result, bkm)) {
// TODO: do we need to check if the defined variable is a function as it should?
return;
}
// TODO: do we need to check/resolve dependencies?
if (bkm.getEvaluator() == null) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, bkm.getSource(), result, null, null, Msg.MISSING_EXPRESSION_FOR_BKM, getIdentifier(bkm));
return;
}
try {
DMNRuntimeEventManagerUtils.fireBeforeEvaluateBKM(eventManager, bkm, result);
for (DMNNode dep : bkm.getDependencies().values()) {
if (typeCheck && !checkDependencyValueIsValid(dep, result)) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, ((DMNBaseNode) dep).getSource(), result, null, null, Msg.ERROR_EVAL_NODE_DEP_WRONG_TYPE, getIdentifier(bkm), getIdentifier(dep), MsgUtil.clipString(result.getContext().get(dep.getName()).toString(), 50), ((DMNBaseNode) dep).getType());
return;
}
if (!isNodeValueDefined(result, dep)) {
if (dep instanceof BusinessKnowledgeModelNode) {
evaluateBKM(context, result, (BusinessKnowledgeModelNode) dep, typeCheck);
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, bkm.getSource(), result, null, null, Msg.REQ_DEP_NOT_FOUND_FOR_NODE, getIdentifier(dep), getIdentifier(bkm));
return;
}
}
}
EvaluatorResult er = bkm.getEvaluator().evaluate(this, result);
if (er.getResultType() == EvaluatorResult.ResultType.SUCCESS) {
FEELFunction resultFn = (FEELFunction) er.getResult();
if (bkm.getModelNamespace().equals(result.getModel().getNamespace())) {
// TODO check of the return type will need calculation/inference of function return type.
result.getContext().set(bkm.getBusinessKnowledModel().getVariable().getName(), resultFn);
} else {
DMNModelImpl model = (DMNModelImpl) result.getModel();
Optional<String> importAlias = model.getImportAliasFor(bkm.getModelNamespace(), bkm.getModelName());
Map<String, Object> aliasContext = (Map) result.getContext().getAll().computeIfAbsent(importAlias.get(), x -> new LinkedHashMap<>());
aliasContext.put(bkm.getBusinessKnowledModel().getVariable().getName(), resultFn);
}
}
} catch (Throwable t) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, bkm.getSource(), result, t, null, Msg.ERROR_EVAL_BKM_NODE, getIdentifier(bkm), t.getMessage());
} finally {
DMNRuntimeEventManagerUtils.fireAfterEvaluateBKM(eventManager, bkm, result);
}
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNAssemblerTest method testStrictMode.
@Test
public void testStrictMode() {
System.setProperty("org.kie.dmn.strictConformance", "true");
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("strictMode.dmn", this.getClass());
DMNModel model = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ecf4ea54-2abc-4e2f-a101-4fe14e356a46", "strictMode");
DMNContext ctx = runtime.newContext();
ctx.set("timestring", "2016-12-20T14:30:22z");
DMNResult result = runtime.evaluateAll(model, ctx);
assertNull(result.getDecisionResultByName("time").getResult());
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNAssemblerTest method testStrictModeProp.
@Test
public void testStrictModeProp() {
final KieServices services = KieServices.Factory.get();
final KieFileSystem fileSystem = services.newKieFileSystem();
KieModuleModel moduleModel = services.newKieModuleModel();
moduleModel.setConfigurationProperty("org.kie.dmn.strictConformance", "true");
fileSystem.writeKModuleXML(moduleModel.toXML());
fileSystem.write(services.getResources().newClassPathResource("strictMode.dmn", this.getClass()));
services.newKieBuilder(fileSystem).buildAll();
final KieContainer container = services.newKieContainer(services.getRepository().getDefaultReleaseId());
DMNRuntime runtime = container.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel model = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ecf4ea54-2abc-4e2f-a101-4fe14e356a46", "strictMode");
DMNContext ctx = runtime.newContext();
ctx.set("timestring", "2016-12-20T14:30:22z");
DMNResult result = runtime.evaluateAll(model, ctx);
assertNull(result.getDecisionResultByName("time").getResult());
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNCompilerTest method testImport.
@Test
public void testImport() {
System.out.println(null instanceof Definitions);
DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Importing_Model.dmn", this.getClass(), "Imported_Model.dmn");
DMNModel importedModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df36", "Imported Model");
assertThat(importedModel, notNullValue());
for (DMNMessage message : importedModel.getMessages()) {
LOG.debug("{}", message);
}
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edab52", "Importing Model");
assertThat(dmnModel, notNullValue());
for (DMNMessage message : dmnModel.getMessages()) {
LOG.debug("{}", message);
}
DMNContext context = runtime.newContext();
context.set("A Person", mapOf(entry("name", "John"), entry("age", 47)));
DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context);
for (DMNMessage message : evaluateAll.getMessages()) {
LOG.debug("{}", message);
}
LOG.debug("{}", evaluateAll);
assertThat(evaluateAll.getDecisionResultByName("Greeting").getResult(), is("Hello John!"));
}
Aggregations