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 DefinitionsConverter method assignChildElement.
@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
Definitions def = (Definitions) parent;
if (IMPORT.equals(nodeName)) {
def.getImport().add((Import) child);
} else if (ITEM_DEFINITION.equals(nodeName)) {
def.getItemDefinition().add((ItemDefinition) child);
} else if (child instanceof DRGElement) {
def.getDrgElement().add((DRGElement) child);
} else if (child instanceof Artifact) {
def.getArtifact().add((Artifact) child);
} else if (ELEMENT_COLLECTION.equals(nodeName)) {
def.getElementCollection().add((ElementCollection) child);
} else if (child instanceof BusinessContextElement) {
def.getBusinessContextElement().add((BusinessContextElement) child);
} else if (child instanceof DMNDI) {
DMNDI dmndi = (DMNDI) child;
dmndi.normalize();
def.setDMNDI(dmndi);
} else {
super.assignChildElement(def, nodeName, child);
}
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNModelImpl method readExternal.
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
this.serializedAs = (SerializationFormat) in.readObject();
this.resource = (Resource) in.readObject();
this.messages = new DefaultDMNMessagesManager(this.resource);
String xml = (String) in.readObject();
if (!(in instanceof DroolsObjectInputStream)) {
throw new UnsupportedOperationException();
// TODO assume some defaults
}
DroolsObjectInputStream is = (DroolsObjectInputStream) in;
DMNCompilerImpl compiler = (DMNCompilerImpl) is.getCustomExtensions().get(DMNAssemblerService.DMN_COMPILER_CACHE_KEY);
List<DMNExtensionRegister> dmnRegisteredExtensions = compiler.getRegisteredExtensions();
Definitions definitions = DMNMarshallerFactory.newMarshallerWithExtensions(dmnRegisteredExtensions).unmarshal(xml);
this.definitions = definitions;
this.wireTypeRegistry(definitions);
DMNModelImpl compiledModel = (DMNModelImpl) compiler.compile(definitions);
this.inputs = compiledModel.inputs;
this.decisions = compiledModel.decisions;
this.bkms = compiledModel.bkms;
this.itemDefs = compiledModel.itemDefs;
this.messages = compiledModel.messages;
this.types = compiledModel.types;
this.runtimeTypeCheck = compiledModel.runtimeTypeCheck;
this.importAliases = compiledModel.importAliases;
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testSharedDependency.
@Test
public void testSharedDependency() {
final Definitions defs = buildSimplifiedDefinitions("ns", "a", "b", "c");
final DecisionNodeImpl a = buildSimplifiedDecisionNode(defs, "a");
final DecisionNodeImpl b = buildSimplifiedDecisionNode(defs, "b");
final DecisionNodeImpl c = buildSimplifiedDecisionNode(defs, "c");
a.addDependency("c", c);
b.addDependency("c", c);
final DMNModelImpl model = new DMNModelImpl(defs);
model.setDefinitions(defs);
model.addDecision(a);
model.addDecision(b);
model.addDecision(c);
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(this.getClass());
final DMNResult result = runtime.evaluateAll(model, DMNFactory.newContext());
assertFalse(result.hasErrors());
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method test_countCSATradeRatings.
@Test
public void test_countCSATradeRatings() {
// DROOLS-1563
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("countCSATradeRatings.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_1a7d184c-2e38-4462-ae28-15591ef6d534", "countCSATradeRatings");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext ctx = runtime.newContext();
final List<Map<?, ?>> ratings = new ArrayList<>();
ratings.add(prototype(entry("Agency", "FITCH"), entry("Value", "val1")));
ratings.add(prototype(entry("Agency", "MOODY"), entry("Value", "val2")));
ctx.set("CSA Trade Ratings", ratings);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, ctx);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("Trade Ratings"), is(new BigDecimal(2)));
final DMNContext ctx2 = runtime.newContext();
ctx2.set("CSA Trade Ratings", null);
final DMNResult dmnResult2 = runtime.evaluateAll(dmnModel, ctx2);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult2.getMessages()), dmnResult2.hasErrors(), is(true));
assertThat(dmnResult2.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.FEEL_EVALUATION_ERROR)), is(true));
assertThat(dmnResult2.getDecisionResultByName("Trade Ratings").getEvaluationStatus(), is(DecisionEvaluationStatus.FAILED));
final DMNResult dmnResult3 = runtime.evaluateAll(dmnModel, runtime.newContext());
assertThat(DMNRuntimeUtil.formatMessages(dmnResult3.getMessages()), dmnResult3.hasErrors(), is(true));
assertThat(dmnResult3.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.REQ_NOT_FOUND)), is(true));
}
Aggregations