use of org.kie.dmn.model.v1_1.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();
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;
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;
}
use of org.kie.dmn.model.v1_1.Definitions 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!"));
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testDROOLS2147_message.
@Test
public void testDROOLS2147_message() {
// DROOLS-2147 truncate message length
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Ex_4_3simplified.dmn", this.getClass());
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));
DMNContext context = DMNFactory.newContext();
StringBuilder sb = new StringBuilder("abcdefghijklmnopqrstuvwxyz");
for (int i = 0; i < 100; i++) {
sb.append("abcdefghijklmnopqrstuvwxyz");
}
context.set("number", sb.toString());
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
System.out.println(dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
assertThat(dmnResult.getMessages().stream().filter(m -> m.getMessageType() == DMNMessageType.ERROR_EVAL_NODE).anyMatch(m -> m.getMessage().contains("... [string clipped after 50 chars, total length is")), is(true));
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testUnknownVariable1.
@Test
public void testUnknownVariable1() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("unknown_variable1.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9105d4a6-6049-4ace-a9cd-88f18d29bc8f", "Loan Recommendation - context");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.getMessages().size(), is(2));
assertEquals(1, dmnModel.getMessages().stream().filter(m -> m.getMessageType().equals(DMNMessageType.ERR_COMPILING_FEEL)).filter(m -> m.getMessage().contains("Unknown variable 'NonSalaryPct'")).count());
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class XStreamMarshaller method newXStream.
private XStream newXStream() {
XStream xStream = createTrustingXStream(staxDriver, Definitions.class.getClassLoader());
xStream.alias("artifact", Artifact.class);
xStream.alias("definitions", Definitions.class);
xStream.alias("inputData", InputData.class);
xStream.alias("decision", Decision.class);
xStream.alias("variable", InformationItem.class);
xStream.alias("informationRequirement", InformationRequirement.class);
xStream.alias("requiredInput", DMNElementReference.class);
xStream.alias("literalExpression", LiteralExpression.class);
// TODO will need to remove dups and find missing element not captured?
xStream.alias("DMNElement", DMNElement.class);
xStream.alias("allowedValues", UnaryTests.class);
xStream.alias("artifact", Artifact.class);
xStream.alias("association", Association.class);
xStream.alias("authorityRequirement", AuthorityRequirement.class);
xStream.alias("authorityRequirement", AuthorityRequirement.class);
xStream.alias("authorityRequirement", AuthorityRequirement.class);
xStream.alias("binding", Binding.class);
xStream.alias("businessContextElement", BusinessContextElement.class);
xStream.alias("businessKnowledgeModel", BusinessKnowledgeModel.class);
xStream.alias("column", InformationItem.class);
xStream.alias("context", Context.class);
xStream.alias("contextEntry", ContextEntry.class);
xStream.alias("decision", Decision.class);
xStream.alias("decisionMade", DMNElementReference.class);
xStream.alias("decisionMaker", DMNElementReference.class);
xStream.alias("decisionOwned", DMNElementReference.class);
xStream.alias("decisionOwner", DMNElementReference.class);
xStream.alias("decisionService", DecisionService.class);
xStream.alias("decisionTable", DecisionTable.class);
xStream.alias("defaultOutputEntry", LiteralExpression.class);
xStream.alias("definitions", Definitions.class);
xStream.alias("drgElement", DMNElementReference.class);
// xStream.alias("drgElement", DRGElement.class ); ambiguity, also referring to top-level xsd element just under xsd root.
xStream.alias("elementCollection", ElementCollection.class);
xStream.alias("elementCollection", ElementCollection.class);
xStream.alias("encapsulatedDecision", DMNElementReference.class);
xStream.alias("encapsulatedLogic", FunctionDefinition.class);
xStream.alias("expression", Expression.class);
xStream.alias("formalParameter", InformationItem.class);
xStream.alias("functionDefinition", FunctionDefinition.class);
xStream.alias("impactedPerformanceIndicator", DMNElementReference.class);
xStream.alias("impactingDecision", DMNElementReference.class);
xStream.alias("import", Import.class);
xStream.alias("import", Import.class);
// TODO where?
xStream.alias("importedElement", String.class);
xStream.alias("importedValues", ImportedValues.class);
xStream.alias("informationItem", InformationItem.class);
xStream.alias("informationRequirement", InformationRequirement.class);
xStream.alias("input", InputClause.class);
xStream.alias("inputData", DMNElementReference.class);
xStream.alias("inputData", InputData.class);
xStream.alias("inputDecision", DMNElementReference.class);
xStream.alias("inputEntry", UnaryTests.class);
xStream.alias("inputExpression", LiteralExpression.class);
xStream.alias("inputValues", UnaryTests.class);
xStream.alias("invocation", Invocation.class);
xStream.alias("itemComponent", ItemDefinition.class);
xStream.alias("itemDefinition", ItemDefinition.class);
xStream.alias("itemDefinition", ItemDefinition.class);
xStream.alias("knowledgeRequirement", KnowledgeRequirement.class);
xStream.alias("knowledgeRequirement", KnowledgeRequirement.class);
xStream.alias("knowledgeSource", KnowledgeSource.class);
xStream.alias("literalExpression", LiteralExpression.class);
xStream.alias("namedElement", NamedElement.class);
xStream.alias("organizationUnit", OrganizationUnit.class);
xStream.alias("output", OutputClause.class);
xStream.alias("outputDecision", DMNElementReference.class);
xStream.alias("outputEntry", LiteralExpression.class);
xStream.alias("outputValues", UnaryTests.class);
xStream.alias("owner", DMNElementReference.class);
xStream.alias("parameter", InformationItem.class);
xStream.alias("performanceIndicator", PerformanceIndicator.class);
xStream.alias("relation", Relation.class);
xStream.alias("requiredAuthority", DMNElementReference.class);
xStream.alias("requiredDecision", DMNElementReference.class);
xStream.alias("requiredDecision", DMNElementReference.class);
xStream.alias("requiredInput", DMNElementReference.class);
xStream.alias("requiredInput", DMNElementReference.class);
xStream.alias("requiredKnowledge", DMNElementReference.class);
xStream.alias("rule", DecisionRule.class);
xStream.alias("sourceRef", DMNElementReference.class);
xStream.alias("supportedObjective", DMNElementReference.class);
xStream.alias("targetRef", DMNElementReference.class);
xStream.alias("textAnnotation", TextAnnotation.class);
// TODO where?
xStream.alias("type", String.class);
xStream.alias("typeRef", QName.class);
xStream.alias("usingProcess", DMNElementReference.class);
xStream.alias("usingTask", DMNElementReference.class);
xStream.alias("variable", InformationItem.class);
xStream.alias("variable", InformationItem.class);
xStream.alias("variable", InformationItem.class);
xStream.alias("variable", InformationItem.class);
// xStream.alias("allowedAnswers", xsd:string.class );
// xStream.alias("description", xsd:string.class );
// xStream.alias("question", xsd:string.class );
// xStream.alias("text", xsd:string.class );
// xStream.alias("text", xsd:string.class );
// xStream.alias("text", xsd:string.class );
xStream.alias("row", org.kie.dmn.model.v1_1.List.class);
xStream.alias("list", org.kie.dmn.model.v1_1.List.class);
xStream.alias("extensionElements", DMNElement.ExtensionElements.class);
// Manually imported TEXT = String
xStream.alias(LiteralExpressionConverter.TEXT, String.class);
xStream.alias(TextAnnotationConverter.TEXT, String.class);
xStream.alias(UnaryTestsConverter.TEXT, String.class);
xStream.alias(DecisionConverter.QUESTION, String.class);
xStream.alias(DecisionConverter.ALLOWED_ANSWERS, String.class);
xStream.alias(DMNElementConverter.DESCRIPTION, String.class);
xStream.registerConverter(new AssociationConverter(xStream));
xStream.registerConverter(new AuthorityRequirementConverter(xStream));
xStream.registerConverter(new BindingConverter(xStream));
xStream.registerConverter(new BusinessKnowledgeModelConverter(xStream));
xStream.registerConverter(new ContextConverter(xStream));
xStream.registerConverter(new ContextEntryConverter(xStream));
xStream.registerConverter(new DecisionConverter(xStream));
xStream.registerConverter(new DecisionRuleConverter(xStream));
xStream.registerConverter(new DecisionServiceConverter(xStream));
xStream.registerConverter(new DecisionTableConverter(xStream));
xStream.registerConverter(new DefinitionsConverter(xStream));
xStream.registerConverter(new DMNElementReferenceConverter(xStream));
xStream.registerConverter(new FunctionDefinitionConverter(xStream));
xStream.registerConverter(new ImportConverter(xStream));
xStream.registerConverter(new ImportedValuesConverter(xStream));
xStream.registerConverter(new InformationItemConverter(xStream));
xStream.registerConverter(new InformationRequirementConverter(xStream));
xStream.registerConverter(new InputClauseConverter(xStream));
xStream.registerConverter(new InputDataConverter(xStream));
xStream.registerConverter(new InvocationConverter(xStream));
xStream.registerConverter(new ItemDefinitionConverter(xStream));
xStream.registerConverter(new KnowledgeRequirementConverter(xStream));
xStream.registerConverter(new KnowledgeSourceConverter(xStream));
xStream.registerConverter(new LiteralExpressionConverter(xStream));
xStream.registerConverter(new OrganizationUnitConverter(xStream));
xStream.registerConverter(new OutputClauseConverter(xStream));
xStream.registerConverter(new PerformanceIndicatorConverter(xStream));
xStream.registerConverter(new RelationConverter(xStream));
xStream.registerConverter(new TextAnnotationConverter(xStream));
xStream.registerConverter(new UnaryTestsConverter(xStream));
xStream.registerConverter(new QNameConverter());
xStream.registerConverter(new DMNListConverter(xStream));
xStream.registerConverter(new ElementCollectionConverter(xStream));
xStream.registerConverter(new ExtensionElementsConverter(xStream, extensionRegisters));
xStream.ignoreUnknownElements();
for (DMNExtensionRegister extensionRegister : extensionRegisters) {
extensionRegister.registerExtensionConverters(xStream);
}
return xStream;
}
Aggregations