use of org.kie.dmn.core.ast.InputDataNodeImpl in project drools by kiegroup.
the class MultiInstanceDecisionLogicTest method input.
private DMNBaseNode input(String id) {
InputDataNodeImpl input = mock(InputDataNodeImpl.class);
doReturn(id).when(input).getId();
doReturn(input).when(model).getInputById(id);
return input;
}
use of org.kie.dmn.core.ast.InputDataNodeImpl 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.core.ast.InputDataNodeImpl in project drools by kiegroup.
the class DMNRuntimeImpl method checkDependencyValueIsValid.
private boolean checkDependencyValueIsValid(DMNNode dep, DMNResultImpl result) {
if (dep instanceof InputDataNode) {
InputDataNodeImpl inputDataNode = (InputDataNodeImpl) dep;
BaseDMNTypeImpl dmnType = (BaseDMNTypeImpl) inputDataNode.getType();
return dmnType.isAssignableValue(result.getContext().get(dep.getName()));
}
// if the dependency is NOT an InputData, the type coherence was checked at evaluation result assignment.
return true;
}
use of org.kie.dmn.core.ast.InputDataNodeImpl in project drools-wb by kiegroup.
the class AbstractDMNTest method getInputDataNode.
protected InputDataNode getInputDataNode(DMNType dmnType, String name) {
TInputData inputData = new TInputData();
inputData.setName(name);
InputDataNode toReturn = new InputDataNodeImpl(inputData, dmnType);
return toReturn;
}
use of org.kie.dmn.core.ast.InputDataNodeImpl in project drools by kiegroup.
the class InputDataCompiler method compileNode.
@Override
public void compileNode(DRGElement de, DMNCompilerImpl compiler, DMNModelImpl model) {
InputData input = (InputData) de;
InputDataNodeImpl idn = new InputDataNodeImpl(input);
if (input.getVariable() != null) {
DMNCompilerHelper.checkVariableName(model, input, input.getName());
DMNType type = compiler.resolveTypeRef(model, de, input.getVariable(), input.getVariable().getTypeRef());
idn.setType(type);
} else {
idn.setType(model.getTypeRegistry().unknown());
DMNCompilerHelper.reportMissingVariable(model, de, input, Msg.MISSING_VARIABLE_FOR_INPUT);
}
model.addInput(idn);
}
Aggregations