use of org.kie.dmn.model.api.Decision in project drools by kiegroup.
the class DecisionConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Decision dec = (Decision) parent;
if (dec.getQuestion() != null)
writeChildrenNodeAsValue(writer, context, dec.getQuestion(), QUESTION);
if (dec.getAllowedAnswers() != null)
writeChildrenNodeAsValue(writer, context, dec.getAllowedAnswers(), ALLOWED_ANSWERS);
if (dec.getVariable() != null)
writeChildrenNode(writer, context, dec.getVariable(), VARIABLE);
for (InformationRequirement ir : dec.getInformationRequirement()) {
writeChildrenNode(writer, context, ir, INFORMATION_REQUIREMENT);
}
for (KnowledgeRequirement kr : dec.getKnowledgeRequirement()) {
writeChildrenNode(writer, context, kr, KNOWLEDGE_REQUIREMENT);
}
for (AuthorityRequirement ar : dec.getAuthorityRequirement()) {
writeChildrenNode(writer, context, ar, AUTHORITY_REQUIREMENT);
}
for (DMNElementReference so : dec.getSupportedObjective()) {
writeChildrenNode(writer, context, so, SUPPORTED_OBJECTIVE);
}
for (DMNElementReference ipi : dec.getImpactedPerformanceIndicator()) {
writeChildrenNode(writer, context, ipi, IMPACTED_PERFORMANCE_INDICATOR);
}
for (DMNElementReference dm : dec.getDecisionMaker()) {
writeChildrenNode(writer, context, dm, DECISION_MAKER);
}
for (DMNElementReference downer : dec.getDecisionOwner()) {
writeChildrenNode(writer, context, downer, DECISION_OWNER);
}
for (DMNElementReference up : dec.getUsingProcess()) {
writeChildrenNode(writer, context, up, USING_PROCESS);
}
for (DMNElementReference ut : dec.getUsingTask()) {
writeChildrenNode(writer, context, ut, USING_TASK);
}
if (dec.getExpression() != null) {
Expression e = dec.getExpression();
String nodeName = MarshallingUtils.defineExpressionNodeName(e);
writeChildrenNode(writer, context, e, nodeName);
}
}
use of org.kie.dmn.model.api.Decision in project drools by kiegroup.
the class DecisionConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
Decision dec = (Decision) parent;
if (dec.getQuestion() != null)
writeChildrenNodeAsValue(writer, context, dec.getQuestion(), QUESTION);
if (dec.getAllowedAnswers() != null)
writeChildrenNodeAsValue(writer, context, dec.getAllowedAnswers(), ALLOWED_ANSWERS);
if (dec.getVariable() != null)
writeChildrenNode(writer, context, dec.getVariable(), VARIABLE);
for (InformationRequirement ir : dec.getInformationRequirement()) {
writeChildrenNode(writer, context, ir, INFORMATION_REQUIREMENT);
}
for (KnowledgeRequirement kr : dec.getKnowledgeRequirement()) {
writeChildrenNode(writer, context, kr, KNOWLEDGE_REQUIREMENT);
}
for (AuthorityRequirement ar : dec.getAuthorityRequirement()) {
writeChildrenNode(writer, context, ar, AUTHORITY_REQUIREMENT);
}
for (DMNElementReference so : dec.getSupportedObjective()) {
writeChildrenNode(writer, context, so, SUPPORTED_OBJECTIVE);
}
for (DMNElementReference ipi : dec.getImpactedPerformanceIndicator()) {
writeChildrenNode(writer, context, ipi, IMPACTED_PERFORMANCE_INDICATOR);
}
for (DMNElementReference dm : dec.getDecisionMaker()) {
writeChildrenNode(writer, context, dm, DECISION_MAKER);
}
for (DMNElementReference downer : dec.getDecisionOwner()) {
writeChildrenNode(writer, context, downer, DECISION_OWNER);
}
for (DMNElementReference up : dec.getUsingProcess()) {
writeChildrenNode(writer, context, up, USING_PROCESS);
}
for (DMNElementReference ut : dec.getUsingTask()) {
writeChildrenNode(writer, context, ut, USING_TASK);
}
if (dec.getExpression() != null) {
Expression e = dec.getExpression();
String nodeName = MarshallingUtils.defineExpressionNodeName(e);
writeChildrenNode(writer, context, e, nodeName);
}
}
use of org.kie.dmn.model.api.Decision in project drools by kiegroup.
the class DMNXMLLoaderTest method testLoadingDefinitions.
@Test
public void testLoadingDefinitions() {
final DMNMarshaller DMNMarshaller = DMNMarshallerFactory.newDefaultMarshaller();
final InputStream is = this.getClass().getResourceAsStream("0001-input-data-string.dmn");
final InputStreamReader isr = new InputStreamReader(is);
final Definitions def = DMNMarshaller.unmarshal(isr);
assertThat(def, not(nullValue()));
assertThat(def.getName(), is("0001-input-data-string"));
assertThat(def.getId(), is("_0001-input-data-string"));
assertThat(def.getNamespace(), is("https://github.com/agilepro/dmn-tck"));
assertThat(def.getDrgElement().size(), is(2));
assertThat(def.getDrgElement().get(0), is(instanceOf(Decision.class)));
Decision dec = (Decision) def.getDrgElement().get(0);
assertThat(dec.getName(), is("Greeting Message"));
assertThat(dec.getId(), is("d_GreetingMessage"));
assertThat(dec.getVariable().getName(), is("Greeting Message"));
assertThat(dec.getVariable().getTypeRef().getPrefix(), is("feel"));
assertThat(dec.getVariable().getTypeRef().getLocalPart(), is("string"));
assertThat(dec.getVariable().getTypeRef().getNamespaceURI(), is(XMLConstants.NULL_NS_URI));
assertThat(dec.getInformationRequirement().size(), is(1));
assertThat(dec.getInformationRequirement().get(0).getRequiredInput().getHref(), is("#i_FullName"));
assertThat(dec.getExpression(), is(instanceOf(LiteralExpression.class)));
LiteralExpression le = (LiteralExpression) dec.getExpression();
assertThat(le.getText(), is("\"Hello \" + Full Name"));
InputData idata = (InputData) def.getDrgElement().get(1);
assertThat(idata.getId(), is("i_FullName"));
assertThat(idata.getName(), is("Full Name"));
assertThat(idata.getVariable().getName(), is("Full Name"));
assertThat(idata.getVariable().getTypeRef().getPrefix(), is("feel"));
assertThat(idata.getVariable().getTypeRef().getLocalPart(), is("string"));
assertThat(idata.getVariable().getTypeRef().getNamespaceURI(), is(XMLConstants.NULL_NS_URI));
}
use of org.kie.dmn.model.api.Decision 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";
} else if (a instanceof Group) {
nodeName = "group";
}
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.Decision in project drools by kiegroup.
the class DMNEvaluatorCompiler method inferTypeRef.
public static BaseDMNTypeImpl inferTypeRef(DMNModelImpl model, DecisionTable dt, OutputClause oc) {
BaseDMNTypeImpl typeRef = (BaseDMNTypeImpl) model.getTypeRegistry().unknown();
if (oc.getTypeRef() != null) {
QName outputExpressionTypeRef = oc.getTypeRef();
QName resolvedOutputExpressionTypeRef = DMNCompilerImpl.getNamespaceAndName(oc, model.getImportAliasesForNS(), outputExpressionTypeRef, model.getNamespace());
typeRef = (BaseDMNTypeImpl) model.getTypeRegistry().resolveType(resolvedOutputExpressionTypeRef.getNamespaceURI(), resolvedOutputExpressionTypeRef.getLocalPart());
if (typeRef == null) {
typeRef = (BaseDMNTypeImpl) model.getTypeRegistry().unknown();
}
} else if (dt.getOutput().size() == 1 && (dt.getParent() instanceof Decision || dt.getParent() instanceof BusinessKnowledgeModel || dt.getParent() instanceof ContextEntry)) {
QName inferredTypeRef = recurseUpToInferTypeRef(model, oc, dt);
// if inferredTypeRef is null, a std err will have been reported
if (inferredTypeRef != null) {
QName resolvedInferredTypeRef = DMNCompilerImpl.getNamespaceAndName(oc, model.getImportAliasesForNS(), inferredTypeRef, model.getNamespace());
typeRef = (BaseDMNTypeImpl) model.getTypeRegistry().resolveType(resolvedInferredTypeRef.getNamespaceURI(), resolvedInferredTypeRef.getLocalPart());
}
}
return typeRef;
}
Aggregations