use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError 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);
}
}
use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError in project automatiko-engine by automatiko-io.
the class RuleSetNodeInstance method handleException.
private void handleException(Throwable e) {
String exceptionName = e.getClass().getName();
Object param = e;
if (e instanceof WorkItemExecutionError) {
param = ((WorkItemExecutionError) e).getErrorData();
exceptionName = ((WorkItemExecutionError) e).getErrorCode();
}
ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(exceptionName);
if (exceptionScopeInstance != null) {
exceptionScopeInstance.handleException(this, exceptionName, param != null ? param : e);
} else {
Throwable rootCause = getRootException(e);
if (rootCause != null) {
exceptionName = rootCause.getClass().getName();
param = rootCause;
if (rootCause instanceof WorkItemExecutionError) {
param = ((WorkItemExecutionError) rootCause).getErrorData();
exceptionName = ((WorkItemExecutionError) rootCause).getErrorCode();
}
exceptionScopeInstance = getExceptionScopeInstance(exceptionName);
if (exceptionScopeInstance != null) {
exceptionScopeInstance.handleException(this, exceptionName, param != null ? param : e);
return;
}
}
if (e instanceof WorkItemExecutionError) {
throw (WorkItemExecutionError) e;
}
throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
}
}
use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError in project automatiko-engine by automatiko-io.
the class EventNodeInstance method handleAssignment.
private void handleAssignment(Assignment assignment, Object result) {
AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
if (action == null) {
return;
}
try {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setResult("workflowdata", result);
workItem.setResult("event", result);
action.execute(workItem, context);
} catch (WorkItemExecutionError e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("unable to execute Assignment", e);
}
}
use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError in project automatiko-engine by automatiko-io.
the class CompositeContextNodeInstance method handleAssignment.
private void handleAssignment(Assignment assignment, VariableScopeInstance compositeVariableScopeInstance) {
AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
try {
ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
context.setNodeInstance(this);
action.execute(null, context);
} catch (WorkItemExecutionError e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("unable to execute Assignment", e);
}
}
use of io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError in project automatiko-engine by automatiko-io.
the class WorkItemNodeInstance method internalTrigger.
@Override
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
WorkItemNode workItemNode = getWorkItemNode();
createWorkItem(workItemNode);
if (workItemNode.isWaitForCompletion()) {
addWorkItemListener();
}
((WorkItemImpl) workItem).setNodeInstanceId(this.getId());
((WorkItemImpl) workItem).setNodeId(getNodeId());
workItem.setNodeInstance(this);
workItem.setProcessInstance(getProcessInstance());
setProcessId();
try {
((DefaultWorkItemManager) getProcessInstance().getProcessRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);
} catch (WorkItemHandlerNotFoundException wihnfe) {
getProcessInstance().setState(STATE_ABORTED);
throw wihnfe;
} catch (ProcessWorkItemHandlerException handlerException) {
this.workItemId = workItem.getId();
removeEventListeners();
handleWorkItemHandlerException(handlerException, workItem);
} catch (WorkItemExecutionError e) {
removeEventListeners();
handleException(e.getErrorCode(), e);
} catch (Exception e) {
removeEventListeners();
String exceptionName = e.getClass().getName();
handleException(exceptionName, e);
}
if (!workItemNode.isWaitForCompletion()) {
triggerCompleted();
}
this.workItemId = workItem.getId();
}
Aggregations