use of io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent 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.api.event.process.ProcessNodeTriggeredEvent 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.api.event.process.ProcessNodeTriggeredEvent in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireBeforeNodeTriggered.
public void fireBeforeNodeTriggered(final NodeInstance nodeInstance, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final ProcessNodeTriggeredEvent event = new ProcessNodeTriggeredEventImpl(nodeInstance, runtime);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.beforeNodeTriggered(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
delayedListeners.forEach(l -> l.beforeNodeTriggered(e));
}));
}
use of io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent in project automatiko-engine by automatiko-io.
the class ProcessInstanceEventBatch method events.
@Override
public Collection<DataEvent<?>> events() {
Map<String, ProcessInstanceEventBody> processInstances = new LinkedHashMap<>();
Map<String, UserTaskInstanceEventBody> userTaskInstances = new LinkedHashMap<>();
Set<VariableInstanceEventBody> variables = new LinkedHashSet<>();
for (ProcessEvent event : rawEvents) {
ProcessInstanceEventBody body = processInstances.computeIfAbsent(event.getProcessInstance().getId(), key -> create(event));
if (event instanceof ProcessNodeTriggeredEvent) {
handleProcessNodeTriggeredEvent((ProcessNodeTriggeredEvent) event, body);
} else if (event instanceof ProcessNodeLeftEvent) {
handleProcessNodeLeftEvent((ProcessNodeLeftEvent) event, body);
} else if (event instanceof ProcessCompletedEvent) {
handleProcessCompletedEvent((ProcessCompletedEvent) event, body);
} else if (event instanceof ProcessWorkItemTransitionEvent) {
handleProcessWorkItemTransitionEvent((ProcessWorkItemTransitionEvent) event, userTaskInstances);
} else if (event instanceof ProcessVariableChangedEvent) {
handleProcessVariableChangedEvent((ProcessVariableChangedEvent) event, variables);
}
}
Collection<DataEvent<?>> processedEvents = new ArrayList<>();
processInstances.values().stream().map(pi -> new ProcessInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
userTaskInstances.values().stream().map(pi -> new UserTaskInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
variables.stream().map(pi -> new VariableInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
return processedEvents;
}
Aggregations