Search in sources :

Example 26 with EndNode

use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.

the class ProcessEventSupportTest method testProcessEventListenerProcessState.

@Test
public void testProcessEventListenerProcessState() throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setId("org.company.core.process.event");
    process.setName("Event Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    process.addNode(startNode);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("Print");
    ProcessAction action = new ConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            logger.info("Executed action");
        }
    });
    actionNode.setAction(action);
    actionNode.setId(2);
    process.addNode(actionNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    process.addNode(endNode);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(Collections.singletonMap(process.getId(), process));
    final List<Integer> processEventStatusList = new ArrayList<Integer>();
    final ProcessEventListener processEventListener = new ProcessEventListener() {

        public void afterNodeLeft(ProcessNodeLeftEvent event) {
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
        }

        public void afterProcessCompleted(ProcessCompletedEvent event) {
            processEventStatusList.add(new Integer(event.getProcessInstance().getState()));
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent event) {
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
        }

        public void beforeProcessCompleted(ProcessCompletedEvent event) {
            processEventStatusList.add(new Integer(event.getProcessInstance().getState()));
        }

        public void beforeProcessStarted(ProcessStartedEvent event) {
        }

        public void beforeVariableChanged(ProcessVariableChangedEvent event) {
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
        }
    };
    processRuntime.addEventListener(processEventListener);
    // execute the process
    processRuntime.startProcess("org.company.core.process.event");
    assertEquals(2, processEventStatusList.size());
    assertEquals(new Integer(ProcessInstance.STATE_ACTIVE), processEventStatusList.get(0));
    assertEquals(new Integer(ProcessInstance.STATE_COMPLETED), processEventStatusList.get(1));
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ProcessRuntimeImpl(io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl) ArrayList(java.util.ArrayList) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 27 with EndNode

use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowFactory method endNode.

public EndNode endNode(long id, String name, boolean terminate, NodeContainer nodeContainer) {
    EndNode endNode = new EndNode();
    endNode.setId(id);
    endNode.setName(name);
    endNode.setTerminate(terminate);
    nodeContainer.addNode(endNode);
    return endNode;
}
Also used : EndNode(io.automatiko.engine.workflow.process.core.node.EndNode)

Example 28 with EndNode

use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowFactory method compensateEndNode.

public EndNode compensateEndNode(long id, String name, NodeContainer nodeContainer) {
    EndNode endNode = new EndNode();
    endNode.setId(id);
    endNode.setName(name);
    endNode.setMetaData(UNIQUE_ID_PARAM, Long.toString(id));
    endNode.setMetaData(Metadata.TRIGGER_TYPE, "Compensation");
    nodeContainer.addNode(endNode);
    return endNode;
}
Also used : EndNode(io.automatiko.engine.workflow.process.core.node.EndNode)

Example 29 with EndNode

use of io.automatiko.engine.workflow.process.core.node.EndNode in project automatiko-engine by automatiko-io.

the class EndNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    EndNode endNode = (EndNode) node;
    writeNode("end", endNode, xmlDump, includeMeta);
    boolean terminate = endNode.isTerminate();
    if (!terminate) {
        xmlDump.append("terminate=\"false\" ");
    }
    if (includeMeta && containsMetaData(endNode)) {
        xmlDump.append(">" + EOL);
        writeMetaData(endNode, xmlDump);
        endNode("end", xmlDump);
    } else {
        endNode(xmlDump);
    }
}
Also used : EndNode(io.automatiko.engine.workflow.process.core.node.EndNode)

Example 30 with EndNode

use of io.automatiko.engine.workflow.process.core.node.EndNode 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

EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)36 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)23 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)19 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)19 ArrayList (java.util.ArrayList)19 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)14 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)13 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)12 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)11 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)10 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)9 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)9 List (java.util.List)9 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)8 Action (io.automatiko.engine.workflow.base.instance.impl.Action)8 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)8 FaultNode (io.automatiko.engine.workflow.process.core.node.FaultNode)8 Test (org.junit.jupiter.api.Test)8 Node (io.automatiko.engine.api.definition.process.Node)7 ProcessContext (io.automatiko.engine.api.runtime.process.ProcessContext)7