Search in sources :

Example 6 with ExceptionScopeInstance

use of io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance in project automatiko-engine by automatiko-io.

the class LambdaSubProcessNodeInstance method processInstanceCompleted.

public void processInstanceCompleted(ProcessInstance processInstance) {
    removeEventListeners();
    String parentInstanceId = getProcessInstance().getId();
    if (getProcessInstance().getParentProcessInstanceId() != null && !getProcessInstance().getParentProcessInstanceId().isEmpty()) {
        parentInstanceId = getProcessInstance().getParentProcessInstanceId() + ":" + parentInstanceId;
    }
    ((ProcessInstanceImpl) getProcessInstance()).removeChild(processInstance.getProcess().getId(), parentInstanceId + ":" + processInstance.getId());
    handleOutMappings(processInstance);
    if (processInstance.getState() == ProcessInstance.STATE_ABORTED) {
        String faultName = processInstance.getOutcome() == null ? "" : processInstance.getOutcome();
        // handle exception as sub process failed with error code
        ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, faultName);
        if (exceptionScopeInstance != null) {
            exceptionScopeInstance.handleException(this, faultName, processInstance.getFaultData());
            if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
                cancel();
            }
            return;
        } else if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
            getProcessInstance().setState(ProcessInstance.STATE_ABORTED, faultName);
            return;
        }
    }
    // handle dynamic subprocess
    if (getNode() == null) {
        setMetaData("NodeType", "SubProcessNode");
    }
    // if there were no exception proceed normally
    triggerCompleted();
    if (getProcessInstance().getProcess().getType().equals(Process.FUNCTION_FLOW_TYPE)) {
        processInstance.getMetaData().put("ATK_FUNC_FLOW_NEXT", getProcessInstance().getMetaData().get("ATK_FUNC_FLOW_NEXT"));
        processInstance.getMetaData().put("ATK_FUNC_FLOW_ID", getProcessInstance().getId());
    }
}
Also used : ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 7 with ExceptionScopeInstance

use of io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance in project automatiko-engine by automatiko-io.

the class SubProcessNodeInstance method processInstanceCompleted.

public void processInstanceCompleted(ProcessInstance processInstance) {
    removeEventListeners();
    ((ProcessInstanceImpl) getProcessInstance()).removeChild(processInstance.getProcessId(), processInstance.getId());
    handleOutMappings(processInstance);
    if (processInstance.getState() == ProcessInstance.STATE_ABORTED) {
        String faultName = processInstance.getOutcome() == null ? "" : processInstance.getOutcome();
        // handle exception as sub process failed with error code
        ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, faultName);
        if (exceptionScopeInstance != null) {
            exceptionScopeInstance.handleException(this, faultName, processInstance.getFaultData());
            if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
                cancel();
            }
            return;
        } else if (getSubProcessNode() != null && !getSubProcessNode().isIndependent() && getSubProcessNode().isAbortParent()) {
            ((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName);
            return;
        }
    }
    // handle dynamic subprocess
    if (getNode() == null) {
        setMetaData("NodeType", "SubProcessNode");
    }
    // if there were no exception proceed normally
    triggerCompleted();
}
Also used : WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 8 with ExceptionScopeInstance

use of io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance in project automatiko-engine by automatiko-io.

the class NodeInstanceImpl method executeAction.

/**
 * This method is used in both instances of the {@link ExtendedNodeInstanceImpl}
 * and {@link ActionNodeInstance} instances in order to handle exceptions thrown
 * when executing actions.
 *
 * @param action An {@link Action} instance.
 */
protected void executeAction(Action action) {
    ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
    context.setNodeInstance(this);
    context.setProcessInstance(getProcessInstance());
    try {
        action.execute(context);
    } catch (Exception e) {
        String exceptionName = e.getClass().getName();
        ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName);
        if (exceptionScopeInstance == null) {
            throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
        }
        exceptionScopeInstance.handleException(this, exceptionName, e);
        cancel();
    }
}
Also used : WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) 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