use of io.automatiko.engine.api.decision.DecisionModel in project automatiko-engine by automatiko-io.
the class RuleSetNodeInstance method internalTrigger.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void internalTrigger(final NodeInstance from, String type) {
try {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A RuleSetNode only accepts default incoming connections!");
}
RuleSetNode ruleSetNode = getRuleSetNode();
Map<String, Object> inputs = evaluateParameters(ruleSetNode);
RuleSetNode.RuleType ruleType = ruleSetNode.getRuleType();
if (ruleType.isDecision()) {
RuleSetNode.RuleType.Decision decisionModel = (RuleSetNode.RuleType.Decision) ruleType;
String dName = resolveVariable(decisionModel.getDecision());
DecisionModel modelInstance = getRuleSetNode().getDecisionModel().get();
Object context = modelInstance.newContext(inputs);
Object dmnResult = null;
if (dName == null) {
dmnResult = modelInstance.evaluateAll(context);
} else if (decisionModel.isDecisionService()) {
dmnResult = modelInstance.evaluateDecisionService(context, dName);
} else {
dmnResult = modelInstance.evaluateDecisionByName(context, dName);
}
if (modelInstance.hasErrors(dmnResult)) {
throw new WorkItemExecutionError("DecisionEvaluationFailure", modelInstance.buildErrorMessage(dmnResult), modelInstance.getErrorData(dmnResult));
}
processOutputs(inputs, modelInstance.getResultData(dmnResult));
triggerCompleted();
} else {
throw new UnsupportedOperationException("Unsupported Rule Type: " + ruleType);
}
} catch (Exception e) {
handleException(e);
}
}
Aggregations