Search in sources :

Example 1 with ExceptionHandler

use of io.automatiko.engine.workflow.base.core.context.exception.ExceptionHandler in project automatiko-engine by automatiko-io.

the class CompensationScopeInstance method handleException.

public void handleException(io.automatiko.engine.api.runtime.process.NodeInstance nodeInstance, String activityRef, Object dunno) {
    assert activityRef != null : "It should not be possible for the compensation activity reference to be null here.";
    CompensationScope compensationScope = (CompensationScope) getExceptionScope();
    // broadcast/general compensation in reverse order
    if (activityRef.startsWith(IMPLICIT_COMPENSATION_PREFIX)) {
        activityRef = activityRef.substring(IMPLICIT_COMPENSATION_PREFIX.length());
        assert activityRef.equals(compensationScope.getContextContainerId()) : "Compensation activity ref [" + activityRef + "] does not match" + " Compensation Scope container id [" + compensationScope.getContextContainerId() + "]";
        Map<String, ExceptionHandler> handlers = compensationScope.getExceptionHandlers();
        List<String> completedNodeIds = ((WorkflowProcessInstanceImpl) getProcessInstance()).getCompletedNodeIds();
        ListIterator<String> iter = completedNodeIds.listIterator(completedNodeIds.size());
        while (iter.hasPrevious()) {
            String completedId = iter.previous();
            ExceptionHandler handler = handlers.get(completedId);
            if (handler != null) {
                handleException(nodeInstance, handler, completedId, null);
            }
        }
    } else {
        // Specific compensation
        ExceptionHandler handler = compensationScope.getExceptionHandler(activityRef);
        if (handler == null) {
            throw new IllegalArgumentException("Could not find CompensationHandler for " + activityRef);
        }
        handleException(nodeInstance, handler, activityRef, null);
    }
    // Cancel all node instances created for compensation
    while (!compensationInstances.isEmpty()) {
        NodeInstance generatedInstance = compensationInstances.pop();
        ((NodeInstanceContainer) generatedInstance.getNodeInstanceContainer()).removeNodeInstance(generatedInstance);
    }
}
Also used : ExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ExceptionHandler) NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) CompensationScope(io.automatiko.engine.workflow.base.core.context.exception.CompensationScope) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance) NodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)

Example 2 with ExceptionHandler

use of io.automatiko.engine.workflow.base.core.context.exception.ExceptionHandler in project automatiko-engine by automatiko-io.

the class ExceptionScopeInstance method handleException.

public void handleException(NodeInstance nodeInstance, String exception, Object params) {
    ExceptionHandler handler = getExceptionScope().getExceptionHandler(exception);
    if (handler == null) {
        throw new IllegalArgumentException("Could not find ExceptionHandler for " + exception);
    }
    handleException(nodeInstance, handler, exception, params);
}
Also used : ExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ExceptionHandler)

Example 3 with ExceptionHandler

use of io.automatiko.engine.workflow.base.core.context.exception.ExceptionHandler in project automatiko-engine by automatiko-io.

the class XmlWorkflowProcessDumper method visitExceptionHandlers.

public static void visitExceptionHandlers(Map<String, ExceptionHandler> exceptionHandlers, StringBuilder xmlDump) {
    if (exceptionHandlers != null && exceptionHandlers.size() > 0) {
        xmlDump.append("    <exceptionHandlers>" + EOL);
        for (Map.Entry<String, ExceptionHandler> entry : exceptionHandlers.entrySet()) {
            ExceptionHandler exceptionHandler = entry.getValue();
            if (exceptionHandler instanceof ActionExceptionHandler) {
                ActionExceptionHandler actionExceptionHandler = (ActionExceptionHandler) exceptionHandler;
                xmlDump.append("      <exceptionHandler faultName=\"" + entry.getKey() + "\" type=\"action\" ");
                String faultVariable = actionExceptionHandler.getFaultVariable();
                if (faultVariable != null && faultVariable.length() > 0) {
                    xmlDump.append("faultVariable=\"" + faultVariable + "\" ");
                }
                xmlDump.append(">" + EOL);
                ProcessAction action = actionExceptionHandler.getAction();
                if (action != null) {
                    AbstractNodeHandler.writeAction(action, xmlDump);
                }
                xmlDump.append("      </exceptionHandler>" + EOL);
            } else {
                throw new IllegalArgumentException("Unknown exception handler type: " + exceptionHandler);
            }
        }
        xmlDump.append("    </exceptionHandlers>" + EOL);
    }
}
Also used : ExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ExceptionHandler) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) Map(java.util.Map) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler)

Aggregations

ExceptionHandler (io.automatiko.engine.workflow.base.core.context.exception.ExceptionHandler)3 ActionExceptionHandler (io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler)1 CompensationScope (io.automatiko.engine.workflow.base.core.context.exception.CompensationScope)1 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)1 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)1 NodeInstanceContainer (io.automatiko.engine.workflow.process.instance.NodeInstanceContainer)1 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)1 EventNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)1 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)1 Map (java.util.Map)1