use of org.kie.dmn.core.ast.DMNDecisionServiceEvaluator in project drools by kiegroup.
the class DMNRuntimeImpl method evaluateDecisionService.
@Override
public DMNResult evaluateDecisionService(DMNModel model, DMNContext context, String decisionServiceName) {
Objects.requireNonNull(model, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "model"));
Objects.requireNonNull(context, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "context"));
Objects.requireNonNull(decisionServiceName, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "decisionServiceName"));
boolean typeCheck = performRuntimeTypeCheck(model);
DMNResultImpl result = createResultImpl(model, context);
// the engine should evaluate all belonging to the "local" model namespace, not imported nodes explicitly.
Optional<DecisionServiceNode> lookupDS = ((DMNModelImpl) model).getDecisionServices().stream().filter(d -> d.getModelNamespace().equals(model.getNamespace())).filter(ds -> ds.getName().equals(decisionServiceName)).findFirst();
if (lookupDS.isPresent()) {
DecisionServiceNodeImpl decisionService = (DecisionServiceNodeImpl) lookupDS.get();
for (DMNNode dep : decisionService.getInputParameters().values()) {
if (!isNodeValueDefined(result, decisionService, dep)) {
DMNMessage message = MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, decisionService.getSource(), result, null, null, Msg.REQ_INPUT_NOT_FOUND_FOR_DS, getDependencyIdentifier(decisionService, dep), getIdentifier(decisionService));
final boolean walkingIntoScope = walkIntoImportScope(result, decisionService, dep);
result.getContext().set(dep.getName(), null);
if (walkingIntoScope) {
result.getContext().popScope();
}
} else {
final boolean walkingIntoScope = walkIntoImportScope(result, decisionService, dep);
final Object originalValue = result.getContext().get(dep.getName());
DMNType depType = ((DMNModelImpl) model).getTypeRegistry().unknown();
if (dep instanceof InputDataNode) {
depType = ((InputDataNode) dep).getType();
} else if (dep instanceof DecisionNode) {
depType = ((DecisionNode) dep).getResultType();
}
Object c = coerceUsingType(originalValue, depType, typeCheck, (r, t) -> MsgUtil.reportMessage(logger, DMNMessage.Severity.WARN, decisionService.getDecisionService(), result, null, null, Msg.PARAMETER_TYPE_MISMATCH_DS, dep.getName(), t, MsgUtil.clipString(r.toString(), 50)));
if (c != originalValue) {
// intentional by-reference
result.getContext().set(dep.getName(), c);
}
if (walkingIntoScope) {
result.getContext().popScope();
}
}
}
// please note singleton output coercion does not influence anyway when invoked DS on a model.
EvaluatorResult evaluate = new DMNDecisionServiceEvaluator(decisionService, true, false).evaluate(this, result);
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, null, result, null, null, Msg.DECISION_SERVICE_NOT_FOUND_FOR_NAME, decisionServiceName);
}
return result;
}
Aggregations