Search in sources :

Example 1 with WorkflowRuntimeException

use of io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException in project automatiko-engine by automatiko-io.

the class ActionNodeInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    triggerTime = new Date();
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("An ActionNode only accepts default incoming connections!");
    }
    Action action = (Action) getActionNode().getAction().getMetaData("Action");
    try {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setNodeInstance(this);
        executeAction(action);
    } catch (WorkflowRuntimeException wre) {
        throw wre;
    } catch (Exception e) {
        // - or context.setNodeInstance(this)
        throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
    }
    triggerCompleted();
}
Also used : Action(io.automatiko.engine.workflow.base.instance.impl.Action) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) Date(java.util.Date) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)

Example 2 with WorkflowRuntimeException

use of io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException 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 WorkflowRuntimeException

use of io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException 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 WorkflowRuntimeException

use of io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException in project automatiko-engine by automatiko-io.

the class SplitInstance 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 Split only accepts default incoming connections!");
    }
    triggerTime = new Date();
    final Split split = getSplit();
    try {
        executeStrategy(split, type);
    } catch (WorkflowRuntimeException wre) {
        throw wre;
    } catch (Exception e) {
        throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Split: " + e.getMessage(), e);
    }
}
Also used : WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) Split(io.automatiko.engine.workflow.process.core.node.Split) Date(java.util.Date) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)

Example 5 with WorkflowRuntimeException

use of io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException 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

WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)7 ExceptionScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)4 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)2 ProcessContext (io.automatiko.engine.workflow.base.core.context.ProcessContext)2 Date (java.util.Date)2 Node (io.automatiko.engine.api.definition.process.Node)1 ContextContainer (io.automatiko.engine.workflow.base.core.ContextContainer)1 CompensationScope (io.automatiko.engine.workflow.base.core.context.exception.CompensationScope)1 CompensationScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.CompensationScopeInstance)1 Action (io.automatiko.engine.workflow.base.instance.impl.Action)1 DefaultWorkItemManager (io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)1 NodeImpl (io.automatiko.engine.workflow.process.core.impl.NodeImpl)1 Split (io.automatiko.engine.workflow.process.core.node.Split)1 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)1 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)1 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)1 CompositeNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance)1 HashMap (java.util.HashMap)1