Search in sources :

Example 1 with ProcessInstanceCompensationAction

use of io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowFactory method compensationEventNode.

public ActionNode compensationEventNode(long id, String name, NodeContainer nodeContainer, ExecutableProcess process) {
    ActionNode compensationEventNode = new ActionNode();
    compensationEventNode.setId(id);
    compensationEventNode.setName(name);
    compensationEventNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
    ProcessInstanceCompensationAction pic = new ProcessInstanceCompensationAction("implicit:" + process.getId());
    ProcessAction processAction = new ProcessAction();
    processAction.setMetaData(ACTION, pic);
    compensationEventNode.setAction(processAction);
    compensationEventNode.setMetaData(Metadata.TRIGGER_TYPE, "Compensation");
    compensationEventNode.setMetaData("NodeType", "IntermediateThrowEvent-None");
    compensationEventNode.setMetaData("CompensationEvent", "implicit:" + process.getId());
    nodeContainer.addNode(compensationEventNode);
    return compensationEventNode;
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ProcessInstanceCompensationAction(io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction)

Example 2 with ProcessInstanceCompensationAction

use of io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction in project automatiko-engine by automatiko-io.

the class ProcessHandler method handleIntermediateOrEndThrowCompensationEvent.

protected void handleIntermediateOrEndThrowCompensationEvent(ExtendedNodeImpl throwEventNode) {
    if (throwEventNode.getMetaData("compensation-activityRef") != null) {
        String activityRef = (String) throwEventNode.getMetaData().remove("compensation-activityRef");
        NodeContainer nodeParent = (NodeContainer) throwEventNode.getParentContainer();
        if (nodeParent instanceof EventSubProcessNode) {
            boolean compensationEventSubProcess = false;
            List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers();
            CESP_CHECK: for (Trigger trigger : startTriggers) {
                if (trigger instanceof EventTrigger) {
                    for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
                        if (((EventTypeFilter) filter).getType().equals("Compensation")) {
                            compensationEventSubProcess = true;
                            break CESP_CHECK;
                        }
                    }
                }
            }
            if (compensationEventSubProcess) {
                // BPMN2 spec, p. 252, p. 248: intermediate and end compensation event
                // visibility scope
                nodeParent = (NodeContainer) ((NodeImpl) nodeParent).getParentContainer();
            }
        }
        String parentId;
        if (nodeParent instanceof ExecutableProcess) {
            parentId = ((ExecutableProcess) nodeParent).getId();
        } else {
            parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId");
        }
        String compensationEvent;
        if (activityRef.length() == 0) {
            // general/implicit compensation
            compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + parentId;
        } else {
            // specific compensation
            compensationEvent = activityRef;
        }
        throwEventNode.setMetaData("CompensationEvent", compensationEvent);
        ConsequenceAction compensationAction = new ConsequenceAction("java", "");
        compensationAction.setMetaData("Action", new ProcessInstanceCompensationAction(compensationEvent));
        if (throwEventNode instanceof ActionNode) {
            ((ActionNode) throwEventNode).setAction(compensationAction);
        } else if (throwEventNode instanceof EndNode) {
            List<ProcessAction> actions = new ArrayList<ProcessAction>();
            actions.add(compensationAction);
            ((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        throwEventNode.setMetaData("TriggerType", "Compensation");
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) ProcessInstanceCompensationAction(io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) List(java.util.List) ArrayList(java.util.ArrayList) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Aggregations

ProcessInstanceCompensationAction (io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction)2 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)2 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)2 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)1 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)1 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)1 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)1 ExtendedNodeImpl (io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl)1 NodeImpl (io.automatiko.engine.workflow.process.core.impl.NodeImpl)1 ConstraintTrigger (io.automatiko.engine.workflow.process.core.node.ConstraintTrigger)1 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)1 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)1 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)1 Trigger (io.automatiko.engine.workflow.process.core.node.Trigger)1 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1