use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
ItemDefinition id = (ItemDefinition) parent;
if (id.getTypeRef() != null)
writeChildrenNode(writer, context, id.getTypeRef(), TYPE_REF);
if (id.getAllowedValues() != null)
writeChildrenNode(writer, context, id.getAllowedValues(), ALLOWED_VALUES);
for (ItemDefinition ic : id.getItemComponent()) {
writeChildrenNode(writer, context, ic, ITEM_COMPONENT);
}
if (id.getFunctionItem() != null) {
writeChildrenNode(writer, context, id.getFunctionItem(), FUNCTION_ITEM);
}
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class DecisionServiceCompiler method checkFnConsistency.
private void checkFnConsistency(DMNModelImpl model, DecisionServiceNodeImpl ni, DMNType type, List<DecisionNode> outputDecisions) {
SimpleFnTypeImpl fnType = ((SimpleFnTypeImpl) type);
FunctionItem fi = fnType.getFunctionItem();
if (fi.getParameters().size() != ni.getInputParameters().size()) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_COUNT_MISMATCH_COMPILING, ni.getName(), fi.getParameters().size(), ni.getInputParameters().size());
return;
}
for (int i = 0; i < fi.getParameters().size(); i++) {
InformationItem fiII = fi.getParameters().get(i);
String fpName = ni.getInputParameters().keySet().stream().skip(i).findFirst().orElse(null);
if (!fiII.getName().equals(fpName)) {
List<String> fiParamNames = fi.getParameters().stream().map(InformationItem::getName).collect(Collectors.toList());
List<String> funcDefParamNames = ni.getInputParameters().keySet().stream().collect(Collectors.toList());
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_NAMES_MISMATCH_COMPILING, ni.getName(), fiParamNames, funcDefParamNames);
return;
}
QName fiQname = fiII.getTypeRef();
QName fdQname = null;
DMNNode fpDMNNode = ni.getInputParameters().get(fpName);
if (fpDMNNode instanceof InputDataNodeImpl) {
fdQname = ((InputDataNodeImpl) fpDMNNode).getInputData().getVariable().getTypeRef();
} else if (fpDMNNode instanceof DecisionNodeImpl) {
fdQname = ((DecisionNodeImpl) fpDMNNode).getDecision().getVariable().getTypeRef();
}
if (fiQname != null && fdQname != null && !fiQname.equals(fdQname)) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.PARAMETER_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiII.getName(), fiQname, fdQname);
}
}
QName fiReturnType = fi.getOutputTypeRef();
if (ni.getDecisionService().getOutputDecision().size() == 1) {
QName fdReturnType = outputDecisions.get(0).getDecision().getVariable().getTypeRef();
if (fiReturnType != null && fdReturnType != null && !fiReturnType.equals(fdReturnType)) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiReturnType, fdReturnType);
}
} else if (ni.getDecisionService().getOutputDecision().size() > 1) {
final Function<QName, QName> lookupFn = (in) -> DMNCompilerImpl.getNamespaceAndName(ni.getDecisionService(), model.getImportAliasesForNS(), in, model.getNamespace());
LinkedHashMap<String, QName> fdComposite = new LinkedHashMap<>();
for (DecisionNode dn : outputDecisions) {
fdComposite.put(dn.getName(), lookupFn.apply(dn.getDecision().getVariable().getTypeRef()));
}
final QName lookup = lookupFn.apply(fiReturnType);
Optional<ItemDefNodeImpl> composite = model.getItemDefinitions().stream().filter(id -> id.getModelNamespace().equals(lookup.getNamespaceURI()) && id.getName().equals(lookup.getLocalPart())).map(ItemDefNodeImpl.class::cast).findFirst();
if (!composite.isPresent()) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), lookup, fdComposite);
return;
}
LinkedHashMap<String, QName> fiComposite = new LinkedHashMap<>();
for (ItemDefinition ic : composite.get().getItemDef().getItemComponent()) {
fiComposite.put(ic.getName(), lookupFn.apply(ic.getTypeRef()));
}
if (!fiComposite.equals(fdComposite)) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, ni.getDecisionService(), model, null, null, Msg.RETURNTYPE_TYPEREF_MISMATCH_COMPILING, ni.getName(), fiComposite, fdComposite);
}
}
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesSorter method dfVisit.
/**
* Performs a depth first visit, but keeping a separate reference of visited/visiting nodes, _also_ to avoid potential issues of circularities.
*/
private void dfVisit(ItemDefinition node, List<ItemDefinition> allNodes, Collection<ItemDefinition> visited, List<ItemDefinition> dfv) {
visited.add(node);
List<ItemDefinition> neighbours = allNodes.stream().filter(// filter out `node`
n -> !n.getName().equals(node.getName())).filter(// I pick from allNodes, those referenced by this `node`. Only neighbours of `node`, because N is referenced by NODE.
n -> recurseFind(node, new QName(modelNamespace, n.getName()))).collect(Collectors.toList());
for (ItemDefinition n : neighbours) {
if (!visited.contains(n)) {
dfVisit(n, allNodes, visited, dfv);
}
}
dfv.add(node);
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesSorter method displayDependencies.
public static void displayDependencies(List<ItemDefinition> ins, String namespaceURI) {
for (ItemDefinition in : ins) {
System.out.println(in.getName());
List<ItemDefinition> others = new ArrayList<>(ins);
others.remove(in);
for (ItemDefinition other : others) {
QName otherQName = new QName(namespaceURI, other.getName());
if (directFind(in, otherQName)) {
System.out.println(" direct depends on: " + other.getName());
} else if (recurseFind(in, otherQName)) {
System.out.println(" indir. depends on: " + other.getName());
}
}
}
}
use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.
the class ItemDefinitionDependenciesSorter method sort.
/**
* Return a new list of ItemDefinition sorted by dependencies (required dependencies comes first)
*/
public List<ItemDefinition> sort(List<ItemDefinition> ins) {
// In a graph A -> B -> {C, D}
// showing that A requires B, and B requires C,D
// then a depth-first visit would satisfy required ordering, for example a valid depth first visit is also a valid sort here: C, D, B, A.
Collection<ItemDefinition> visited = new ArrayList<>(ins.size());
List<ItemDefinition> dfv = new ArrayList<>(ins.size());
for (ItemDefinition node : ins) {
if (!visited.contains(node)) {
dfVisit(node, ins, visited, dfv);
}
}
return dfv;
}
Aggregations