Search in sources :

Example 6 with CompensationScope

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

the class ExecutableProcessFactory method addCompensationScope.

protected void addCompensationScope(final ExecutableProcess process, final Node node, final io.automatiko.engine.api.definition.process.NodeContainer parentContainer, final String compensationHandlerId) {
    process.getMetaData().put("Compensation", true);
    assert parentContainer instanceof ContextContainer : "Expected parent node to be a CompositeContextNode, not a " + parentContainer.getClass().getSimpleName();
    ContextContainer contextContainer = (ContextContainer) parentContainer;
    CompensationScope scope = null;
    boolean addScope = false;
    if (contextContainer.getContexts(CompensationScope.COMPENSATION_SCOPE) == null) {
        addScope = true;
    } else {
        scope = (CompensationScope) contextContainer.getContexts(CompensationScope.COMPENSATION_SCOPE).get(0);
        if (scope == null) {
            addScope = true;
        }
    }
    if (addScope) {
        scope = new CompensationScope();
        contextContainer.addContext(scope);
        contextContainer.setDefaultContext(scope);
        scope.setContextContainer(contextContainer);
    }
    CompensationHandler handler = new CompensationHandler();
    handler.setNode(node);
    if (scope.getExceptionHandler(compensationHandlerId) != null) {
        throw new IllegalArgumentException("More than one compensation handler per node (" + compensationHandlerId + ")" + " is not supported!");
    }
    scope.setExceptionHandler(compensationHandlerId, handler);
}
Also used : ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompensationHandler(io.automatiko.engine.workflow.base.core.context.exception.CompensationHandler) CompensationScope(io.automatiko.engine.workflow.base.core.context.exception.CompensationScope)

Aggregations

CompensationScope (io.automatiko.engine.workflow.base.core.context.exception.CompensationScope)6 ContextContainer (io.automatiko.engine.workflow.base.core.ContextContainer)4 CompensationHandler (io.automatiko.engine.workflow.base.core.context.exception.CompensationHandler)3 Node (io.automatiko.engine.api.definition.process.Node)2 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)2 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)1 ExceptionHandler (io.automatiko.engine.workflow.base.core.context.exception.ExceptionHandler)1 CompensationScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.CompensationScopeInstance)1 NodeImpl (io.automatiko.engine.workflow.process.core.impl.NodeImpl)1 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)1 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)1 CatchLinkNode (io.automatiko.engine.workflow.process.core.node.CatchLinkNode)1 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)1 DynamicNode (io.automatiko.engine.workflow.process.core.node.DynamicNode)1 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)1 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)1 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)1 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)1 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)1 ForEachJoinNode (io.automatiko.engine.workflow.process.core.node.ForEachNode.ForEachJoinNode)1