Search in sources :

Example 1 with ExceptionScopeInstance

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);
    }
}
Also used : ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) EventTransformerImpl(io.automatiko.engine.workflow.base.core.event.EventTransformerImpl) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 2 with ExceptionScopeInstance

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);
}
Also used : WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 3 with ExceptionScopeInstance

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);
    }
}
Also used : WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 4 with ExceptionScopeInstance

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());
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) Process(io.automatiko.engine.api.definition.process.Process) Date(java.util.Date) Collection(java.util.Collection) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 5 with ExceptionScopeInstance

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;
    }
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) HashMap(java.util.HashMap) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Aggregations

ExceptionScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)8 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)4 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)2 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)2 ProcessInstanceImpl (io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl)2 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)2 Process (io.automatiko.engine.api.definition.process.Process)1 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)1 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 ProcessContext (io.automatiko.engine.workflow.base.core.context.ProcessContext)1 EventTransformerImpl (io.automatiko.engine.workflow.base.core.event.EventTransformerImpl)1 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)1 DefaultWorkItemManager (io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)1 NodeInstanceContainer (io.automatiko.engine.workflow.process.instance.NodeInstanceContainer)1 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1