Search in sources :

Example 16 with ConnectionImpl

use of io.automatiko.engine.workflow.process.core.impl.ConnectionImpl in project automatiko-engine by automatiko-io.

the class ProcessEventSupportTest method testProcessEventListenerWithStartEvent.

@Test
public void testProcessEventListenerWithStartEvent() 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);
    EventTrigger trigger = new EventTrigger();
    EventTypeFilter eventFilter = new EventTypeFilter();
    eventFilter.setType("signal");
    trigger.addEventFilter(eventFilter);
    startNode.addTrigger(trigger);
    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<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
    final ProcessEventListener processEventListener = new ProcessEventListener() {

        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            processEventList.add(event);
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            processEventList.add(event);
        }

        public void afterProcessCompleted(ProcessCompletedEvent event) {
            processEventList.add(event);
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
            processEventList.add(event);
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent event) {
            processEventList.add(event);
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            processEventList.add(event);
        }

        public void beforeProcessCompleted(ProcessCompletedEvent event) {
            processEventList.add(event);
        }

        public void beforeProcessStarted(ProcessStartedEvent event) {
            processEventList.add(event);
        }

        public void beforeVariableChanged(ProcessVariableChangedEvent event) {
            processEventList.add(event);
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            processEventList.add(event);
        }
    };
    processRuntime.addEventListener(processEventListener);
    // execute the process
    // session.startProcess("org.company.core.process.event");
    processRuntime.signalEvent("signal", null);
    assertEquals(16, processEventList.size());
    assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(0)).getProcessInstance().getProcessId());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(6)).getNodeInstance().getNodeName());
    assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(7)).getProcessInstance().getProcessId());
    assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(8)).getProcessInstance().getProcessId());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(11)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(12)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(13)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(14)).getNodeInstance().getNodeName());
    assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(15)).getProcessInstance().getProcessId());
}
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) ProcessEvent(io.automatiko.engine.api.event.process.ProcessEvent) 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) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) 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) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 17 with ConnectionImpl

use of io.automatiko.engine.workflow.process.core.impl.ConnectionImpl 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 18 with ConnectionImpl

use of io.automatiko.engine.workflow.process.core.impl.ConnectionImpl in project automatiko-engine by automatiko-io.

the class StartNodeInstanceTest method testStartNode.

@Test
public void testStartNode() {
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory mockNodeFactory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance().register(mockNode.getClass(), mockNodeFactory);
    ExecutableProcess process = new ExecutableProcess();
    process.setId("test");
    InternalProcessRuntime processRuntime = createProcessRuntime(process);
    StartNode startNode = new StartNode();
    startNode.setId(1);
    startNode.setName("start node");
    mockNode.setId(2);
    new ConnectionImpl(startNode, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, mockNode, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(startNode);
    process.addNode(mockNode);
    ExecutableProcessInstance processInstance = new ExecutableProcessInstance();
    processInstance.setProcess(process);
    processInstance.setProcessRuntime(processRuntime);
    assertEquals(ProcessInstance.STATE_PENDING, processInstance.getState());
    processInstance.start();
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    MockNodeInstance mockNodeInstance = mockNodeFactory.getMockNodeInstance();
    List<NodeInstance> triggeredBy = mockNodeInstance.getTriggers().get(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
    assertNotNull(triggeredBy);
    assertEquals(1, triggeredBy.size());
    assertSame(startNode.getId(), triggeredBy.get(0).getNodeId());
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 19 with ConnectionImpl

use of io.automatiko.engine.workflow.process.core.impl.ConnectionImpl in project automatiko-engine by automatiko-io.

the class ConnectionHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    String fromId = attrs.getValue("from");
    emptyAttributeCheck(localName, "from", fromId, parser);
    String toId = attrs.getValue("to");
    emptyAttributeCheck(localName, "to", toId, parser);
    String bendpoints = attrs.getValue("bendpoints");
    String fromType = attrs.getValue("fromType");
    if (fromType == null || fromType.trim().length() == 0) {
        fromType = NodeImpl.CONNECTION_DEFAULT_TYPE;
    }
    String toType = attrs.getValue("toType");
    if (toType == null || toType.trim().length() == 0) {
        toType = NodeImpl.CONNECTION_DEFAULT_TYPE;
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    Node fromNode = nodeContainer.getNode(new Long(fromId));
    Node toNode = nodeContainer.getNode(new Long(toId));
    if (fromNode == null) {
        throw new SAXParseException("Node '" + fromId + "'cannot be found", parser.getLocator());
    }
    if (toNode == null) {
        throw new SAXParseException("Node '" + toId + "' cannot be found", parser.getLocator());
    }
    ConnectionImpl connection = new ConnectionImpl(fromNode, fromType, toNode, toType);
    connection.setMetaData("bendpoints", bendpoints);
    return connection;
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Node(io.automatiko.engine.api.definition.process.Node) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer)

Example 20 with ConnectionImpl

use of io.automatiko.engine.workflow.process.core.impl.ConnectionImpl in project automatiko-engine by automatiko-io.

the class ProcessHandler method linkIntermediateLinks.

public static void linkIntermediateLinks(NodeContainer process, List<IntermediateLink> links) {
    if (null != links) {
        // Search throw links
        ArrayList<IntermediateLink> throwLinks = new ArrayList<IntermediateLink>();
        for (IntermediateLink aLinks : links) {
            if (aLinks.isThrowLink()) {
                throwLinks.add(aLinks);
            }
        }
        // Look for catch links for a throw link
        for (IntermediateLink throwLink : throwLinks) {
            ArrayList<IntermediateLink> linksWithSharedNames = new ArrayList<IntermediateLink>();
            for (IntermediateLink aLink : links) {
                if (throwLink.getName().equals(aLink.getName())) {
                    linksWithSharedNames.add(aLink);
                }
            }
            if (linksWithSharedNames.size() < 2) {
                throw new IllegalArgumentException("There should be at least 2 link events to make a connection");
            }
            linksWithSharedNames.remove(throwLink);
            // Make the connections
            Node t = findNodeByIdOrUniqueIdInMetadata(process, throwLink.getUniqueId());
            // connect throw to catch
            for (IntermediateLink catchLink : linksWithSharedNames) {
                Node c = findNodeByIdOrUniqueIdInMetadata(process, catchLink.getUniqueId());
                if (t != null && c != null) {
                    Connection result = new ConnectionImpl(t, NodeImpl.CONNECTION_DEFAULT_TYPE, c, NodeImpl.CONNECTION_DEFAULT_TYPE);
                    result.setMetaData("linkNodeHidden", "yes");
                }
            }
            // Remove processed links
            links.remove(throwLink);
            links.removeAll(linksWithSharedNames);
        }
        if (links.size() > 0) {
            throw new IllegalArgumentException(links.size() + " links were not processed");
        }
    }
}
Also used : StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ArrayList(java.util.ArrayList) Connection(io.automatiko.engine.workflow.process.core.Connection) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) IntermediateLink(io.automatiko.engine.workflow.bpmn2.core.IntermediateLink)

Aggregations

ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)22 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)11 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)11 Node (io.automatiko.engine.api.definition.process.Node)10 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)10 ArrayList (java.util.ArrayList)9 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)7 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)7 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)7 Test (org.junit.jupiter.api.Test)7 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)6 Connection (io.automatiko.engine.api.definition.process.Connection)5 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)5 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)5 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)5 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)5 ProcessStartedEvent (io.automatiko.engine.api.event.process.ProcessStartedEvent)5 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)5 ProcessContext (io.automatiko.engine.api.runtime.process.ProcessContext)5 ProcessRuntimeImpl (io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl)5