use of org.kie.dmn.model.api.Decision in project drools by kiegroup.
the class DMNCompilerImpl method resolveTypeRef.
/**
* Resolve the QName typeRef accordingly to definition of builtin (FEEL) types, local model ItemDef or imported definitions.
* If the typeRef cannot be resolved, (FEEL) UNKNOWN is returned and an error logged using standard DMN message logging.
*/
public DMNType resolveTypeRef(DMNModelImpl dmnModel, NamedElement model, DMNModelInstrumentedBase localElement, QName typeRef) {
if (typeRef != null) {
QName nsAndName = getNamespaceAndName(localElement, dmnModel.getImportAliasesForNS(), typeRef, dmnModel.getNamespace());
DMNType type = dmnModel.getTypeRegistry().resolveType(nsAndName.getNamespaceURI(), nsAndName.getLocalPart());
if (type == null && localElement.getURIFEEL().equals(nsAndName.getNamespaceURI())) {
if (model instanceof Decision && ((Decision) model).getExpression() instanceof DecisionTable) {
DecisionTable dt = (DecisionTable) ((Decision) model).getExpression();
if (dt.getOutput().size() > 1) {
// implicitly define a type for the decision table result
CompositeTypeImpl compType = new CompositeTypeImpl(dmnModel.getNamespace(), model.getName() + "_Type", model.getId(), dt.getHitPolicy().isMultiHit());
for (OutputClause oc : dt.getOutput()) {
DMNType fieldType = resolveTypeRef(dmnModel, model, oc, oc.getTypeRef());
compType.addField(oc.getName(), fieldType);
}
dmnModel.getTypeRegistry().registerType(compType);
return compType;
} else if (dt.getOutput().size() == 1) {
return resolveTypeRef(dmnModel, model, dt.getOutput().get(0), dt.getOutput().get(0).getTypeRef());
}
}
} else if (type == null) {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, localElement, dmnModel, null, null, Msg.UNKNOWN_TYPE_REF_ON_NODE, typeRef.toString(), localElement.getParentDRDElement().getIdentifierString());
type = dmnModel.getTypeRegistry().unknown();
}
return type;
}
return dmnModel.getTypeRegistry().unknown();
}
use of org.kie.dmn.model.api.Decision in project drools by kiegroup.
the class MessageReporterTest method aDecision.
private DMNModelInstrumentedBase aDecision() {
Decision d = new TDecision();
d.setId(UUID.randomUUID().toString());
return d;
}
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";
}
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);
}
}
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(xstream, e);
writeChildrenNode(writer, context, e, nodeName);
}
}
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");
}
}
Aggregations