use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DefinitionsConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
super.writeAttributes(writer, parent);
Definitions def = (Definitions) parent;
if (def.getExpressionLanguage() != null)
writer.addAttribute(EXPRESSION_LANGUAGE, def.getExpressionLanguage());
if (def.getTypeLanguage() != null)
writer.addAttribute(TYPE_LANGUAGE, def.getTypeLanguage());
if (def.getNamespace() != null)
writer.addAttribute(NAMESPACE, def.getNamespace());
if (def.getExporter() != null)
writer.addAttribute(EXPORTER, def.getExporter());
if (def.getExporterVersion() != null)
writer.addAttribute(EXPORTER_VERSION, def.getExporterVersion());
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNCompilerImpl method compile.
public DMNModel compile(Reader source, Collection<DMNModel> dmnModels, Resource resource) {
try {
Definitions dmndefs = getMarshaller().unmarshal(source);
DMNModel model = compile(dmndefs, dmnModels, resource, null);
return model;
} catch (Exception e) {
logger.error("Error compiling model from source.", e);
}
return null;
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testCycleDetection.
@Test
public void testCycleDetection() {
final Definitions defs = buildSimplifiedDefinitions("ns", "a", "b");
final DecisionNodeImpl a = buildSimplifiedDecisionNode(defs, "a");
final DecisionNodeImpl b = buildSimplifiedDecisionNode(defs, "b");
a.addDependency("b", b);
b.addDependency("a", b);
final DMNModelImpl model = new DMNModelImpl(defs);
model.setDefinitions(defs);
model.addDecision(a);
model.addDecision(b);
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(this.getClass());
final DMNResult result = runtime.evaluateAll(model, DMNFactory.newContext());
assertTrue(result.hasErrors());
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testEx_4_3simplifiedASD.
@Test
public void testEx_4_3simplifiedASD() {
// DROOLS-2117 improve Msg.ERROR_EVAL_NODE_DEP_WRONG_TYPE
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Ex_4_3simplified.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_5c5a9c72-627e-4666-ae85-31356fed3658", "Ex_4_3simplified");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("number", "ciao");
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
System.out.println(dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
// we want the error message to include not only which value was incompatible, but the type which was expected.
// in this case the value is `ciao` for a String
// but should have been a FEEL:number.
assertThat(dmnResult.getMessages().stream().filter(m -> m.getMessageType() == DMNMessageType.ERROR_EVAL_NODE).anyMatch(m -> m.getMessage().endsWith("is not allowed by the declared type (DMNType{ http://www.omg.org/spec/FEEL/20140401 : number })")), is(true));
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testCycleDetectionDeadlyDiamond.
@Test
public void testCycleDetectionDeadlyDiamond() {
final Definitions defs = buildSimplifiedDefinitions("ns", "a", "b", "c", "d");
final DecisionNodeImpl a = buildSimplifiedDecisionNode(defs, "a");
final DecisionNodeImpl b = buildSimplifiedDecisionNode(defs, "b");
final DecisionNodeImpl c = buildSimplifiedDecisionNode(defs, "c");
final DecisionNodeImpl d = buildSimplifiedDecisionNode(defs, "d");
a.addDependency("b", b);
a.addDependency("c", c);
b.addDependency("d", d);
c.addDependency("d", d);
final DMNModelImpl model = new DMNModelImpl(defs);
model.setDefinitions(defs);
model.addDecision(a);
model.addDecision(b);
model.addDecision(c);
model.addDecision(d);
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(this.getClass());
final DMNResult result = runtime.evaluateAll(model, DMNFactory.newContext());
assertFalse(result.hasErrors());
}
Aggregations