use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method checkDTCollectOperatorsMultipleOutputs.
private void checkDTCollectOperatorsMultipleOutputs(BuiltinAggregator aggregator, int level, int a, int b) {
// DROOLS-6590 DMN composite output on DT Collect with operators - this is beyond the spec.
final KieServices ks = KieServices.Factory.get();
DMNMarshaller marshaller = DMNMarshallerFactory.newDefaultMarshaller();
final Definitions definitions = marshaller.unmarshal(new InputStreamReader(this.getClass().getResourceAsStream("multipleOutputsCollectDT.dmn")));
DRGElement drgElement1 = definitions.getDrgElement().get(1);
assertThat(drgElement1).describedAs("xml of the test changed, unable to locate Decision Node").isInstanceOf(Decision.class);
((DecisionTable) ((Decision) drgElement1).getExpression()).setAggregation(aggregator);
final String dmnXml = marshaller.marshal(definitions);
final ReleaseId kjarReleaseId = ks.newReleaseId("org.kie.dmn.core", "DMNDecisionTableRuntimeTest", UUID.randomUUID().toString());
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/multipleOutputsCollectDT.dmn", dmnXml);
kfs.generateAndWritePomXML(kjarReleaseId);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertTrue(kieBuilder.getResults().getMessages().toString(), kieBuilder.getResults().getMessages().isEmpty());
final KieContainer container = ks.newKieContainer(kjarReleaseId);
final DMNRuntime runtime = KieRuntimeFactory.of(container.getKieBase()).get(DMNRuntime.class);
final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_943A3581-5FD1-4BCF-9A52-AC7242CC451C", "multipleOutputsCollectDT");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("level", level);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
LOG.debug("{}", dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
Object decision1 = dmnResult.getDecisionResultByName("Decision-1").getResult();
assertThat(decision1).hasFieldOrPropertyWithValue("a", new BigDecimal(a));
assertThat(decision1).hasFieldOrPropertyWithValue("b", new BigDecimal(b));
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DefinitionsConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Definitions def = (Definitions) parent;
for (Import i : def.getImport()) {
writeChildrenNode(writer, context, i, IMPORT);
}
for (ItemDefinition id : def.getItemDefinition()) {
writeChildrenNode(writer, context, id, ITEM_DEFINITION);
}
for (DRGElement e : def.getDrgElement()) {
String nodeName = DRG_ELEMENT;
if (e instanceof BusinessKnowledgeModel) {
nodeName = "businessKnowledgeModel";
} else if (e instanceof Decision) {
nodeName = "decision";
} else if (e instanceof InputData) {
nodeName = "inputData";
} else if (e instanceof KnowledgeSource) {
nodeName = "knowledgeSource";
} else if (e instanceof DecisionService) {
nodeName = "decisionService";
}
writeChildrenNode(writer, context, e, nodeName);
}
for (Artifact a : def.getArtifact()) {
String nodeName = ARTIFACT;
if (a instanceof Association) {
nodeName = "association";
} else if (a instanceof TextAnnotation) {
nodeName = "textAnnotation";
}
writeChildrenNode(writer, context, a, nodeName);
}
for (ElementCollection ec : def.getElementCollection()) {
writeChildrenNode(writer, context, ec, ELEMENT_COLLECTION);
}
for (BusinessContextElement bce : def.getBusinessContextElement()) {
String nodeName = BUSINESS_CONTEXT_ELEMENT;
if (bce instanceof OrganizationUnit) {
nodeName = "organizationUnit";
} else if (bce instanceof PerformanceIndicator) {
nodeName = "performanceIndicator";
}
writeChildrenNode(writer, context, bce, nodeName);
}
if (def.getDMNDI() != null) {
writeChildrenNode(writer, context, def.getDMNDI(), "DMNDI");
}
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DefinitionsConverter method assignAttributes.
@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
super.assignAttributes(reader, parent);
Definitions def = (Definitions) parent;
String exprLang = reader.getAttribute(EXPRESSION_LANGUAGE);
String typeLang = reader.getAttribute(TYPE_LANGUAGE);
String namespace = reader.getAttribute(NAMESPACE);
String exporter = reader.getAttribute(EXPORTER);
String exporterVersion = reader.getAttribute(EXPORTER_VERSION);
def.setExpressionLanguage(exprLang);
def.setTypeLanguage(typeLang);
def.setNamespace(namespace);
def.setExporter(exporter);
def.setExporterVersion(exporterVersion);
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method buildSimplifiedDefinitions.
private Definitions buildSimplifiedDefinitions(final String namespace, final String... decisions) {
final Definitions def = new TDefinitions();
def.setNamespace(namespace);
for (final String d : decisions) {
final Decision dec = new TDecision();
dec.setName(d);
def.getDrgElement().add(dec);
def.addChildren(dec);
dec.setParent(def);
}
return def;
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testNPE.
@Test
public void testNPE() {
// DROOLS-1512
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("NPE.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_95b7ee22-1964-4be5-b7db-7db66692c707", "Dessin 1");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = runtime.newContext();
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
assertThat(dmnResult.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.REQ_NOT_FOUND)), is(true));
}
Aggregations