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());
}
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));
}
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());
}
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;
}
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");
}
}
}
Aggregations