use of io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance in project automatiko-engine by automatiko-io.
the class HandleEscalationAction method execute.
public void execute(ProcessContext context) throws Exception {
ExceptionScopeInstance scopeInstance = (ExceptionScopeInstance) ((NodeInstance) context.getNodeInstance()).resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, faultName);
if (scopeInstance != null) {
Object tVariable = variableName == null ? null : context.getVariable(variableName);
io.automatiko.engine.workflow.process.core.node.Transformation transformation = (io.automatiko.engine.workflow.process.core.node.Transformation) context.getNodeInstance().getNode().getMetaData().get("Transformation");
if (transformation != null) {
tVariable = new EventTransformerImpl(transformation).transformEvent(context.getProcessInstance().getVariables());
}
scopeInstance.handleException(context.getNodeInstance(), faultName, tVariable);
} else {
((ProcessInstance) context.getProcessInstance()).setState(STATE_ABORTED);
}
}
use of io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance in project automatiko-engine by automatiko-io.
the class WorkItemNodeInstance method handleException.
protected void handleException(String exceptionName, Exception e) {
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName);
if (exceptionScopeInstance == null) {
if (e instanceof WorkItemExecutionError) {
throw (WorkItemExecutionError) e;
}
throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
}
// workItemId must be set otherwise cancel activity will not find the right work
// item
this.workItemId = workItem.getId();
Object param = e;
if (e instanceof WorkItemExecutionError) {
param = ((WorkItemExecutionError) e).getErrorData();
}
exceptionScopeInstance.handleException(this, exceptionName, param != null ? param : e);
}
use of io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance 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.workflow.base.instance.context.exception.ExceptionScopeInstance in project automatiko-engine by automatiko-io.
the class FaultNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A FaultNode only accepts default incoming connections!");
}
triggerTime = new Date();
if (getProcessInstance().isFunctionFlow(this) && getNodeInstanceContainer() instanceof ProcessInstance) {
// only when running as function flow and node is in the top level node container meaning process instance
// and not subprocesses
getProcessInstance().getMetaData().compute("ATK_FUNC_FLOW_NEXT", (k, v) -> {
if (v == null) {
v = new ArrayList<String>();
}
Process process = getProcessInstance().getProcess();
String version = "";
if (process.getVersion() != null && !process.getVersion().trim().isEmpty()) {
version = ".v" + process.getVersion().replaceAll("\\.", "_");
}
String defaultNextNode = process.getPackageName() + "." + process.getId() + version + "." + getNodeName().toLowerCase();
((List<String>) v).add((String) getNode().getMetaData().getOrDefault("functionType", defaultNextNode));
return v;
});
}
String faultName = getFaultName();
ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(faultName);
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
nodeInstanceContainer.removeNodeInstance(this);
boolean exceptionHandled = false;
if (getFaultNode().isTerminateParent()) {
// events
if (exceptionScopeInstance != null) {
exceptionHandled = true;
handleException(faultName, exceptionScopeInstance);
}
if (nodeInstanceContainer instanceof CompositeNodeInstance) {
((CompositeNodeInstance) nodeInstanceContainer).cancel();
} else if (nodeInstanceContainer instanceof WorkflowProcessInstance) {
Collection<NodeInstance> nodeInstances = ((WorkflowProcessInstance) nodeInstanceContainer).getNodeInstances();
for (NodeInstance nodeInstance : nodeInstances) {
((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).cancel();
}
}
}
String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
if (uniqueId == null) {
uniqueId = ((NodeImpl) getNode()).getUniqueId();
}
((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
if (exceptionScopeInstance != null) {
if (!exceptionHandled) {
handleException(faultName, exceptionScopeInstance);
}
boolean hidden = false;
if (getNode().getMetaData().get("hidden") != null) {
hidden = true;
}
if (!hidden) {
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
}
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
if (!hidden) {
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
} else {
((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName, getFaultData());
}
}
use of io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance in project automatiko-engine by automatiko-io.
the class WorkItemNodeInstance method exceptionHandlingCompleted.
private void exceptionHandlingCompleted(ProcessInstance processInstance, ProcessWorkItemHandlerException handlerException) {
if (handlerException == null) {
handlerException = (ProcessWorkItemHandlerException) ((WorkflowProcessInstance) processInstance).getVariable("Error");
}
switch(handlerException.getStrategy()) {
case ABORT:
getProcessInstance().getProcessRuntime().getWorkItemManager().abortWorkItem(getWorkItem().getId());
break;
case RETHROW:
String exceptionName = handlerException.getCause().getClass().getName();
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName);
if (exceptionScopeInstance == null) {
throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute work item " + handlerException.getMessage(), handlerException.getCause());
}
exceptionScopeInstance.handleException(this, exceptionName, handlerException.getCause());
break;
case RETRY:
Map<String, Object> parameters = new HashMap<>(getWorkItem().getParameters());
parameters.putAll(processInstance.getVariables());
((DefaultWorkItemManager) getProcessInstance().getProcessRuntime().getWorkItemManager()).retryWorkItem(getWorkItem().getId(), parameters);
break;
case COMPLETE:
getProcessInstance().getProcessRuntime().getWorkItemManager().completeWorkItem(getWorkItem().getId(), processInstance.getVariables());
break;
default:
break;
}
}
Aggregations