use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcess.
@Test
public void testBasicUserTaskProcess() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
final List<String> workItemTransitionEvents = new ArrayList<>();
app.config().process().processEventListeners().listeners().add(new DefaultProcessEventListener() {
@Override
public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("BEFORE:: " + event);
}
@Override
public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("AFTER:: " + event);
}
});
Process<? extends Model> p = app.processes().processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(workItemTransitionEvents).hasSize(8);
}
use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireBeforeWorkItemTransition.
public void fireBeforeWorkItemTransition(final ProcessInstance instance, WorkItem workitem, Transition<?> transition, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final ProcessWorkItemTransitionEvent event = new ProcessWorkItemTransitionEventImpl(instance, workitem, transition, runtime, false);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.beforeWorkItemTransition(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> {
delayedListeners.forEach(l -> l.beforeWorkItemTransition(e));
}));
}
use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireAfterWorkItemTransition.
public void fireAfterWorkItemTransition(final ProcessInstance instance, WorkItem workitem, Transition<?> transition, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final ProcessWorkItemTransitionEvent event = new ProcessWorkItemTransitionEventImpl(instance, workitem, transition, runtime, true);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.afterWorkItemTransition(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> {
delayedListeners.forEach(l -> l.afterWorkItemTransition(e));
}));
}
use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent 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;
}
use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessVersioned.
@Test
public void testBasicUserTaskProcessVersioned() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessVersion.bpmn2", "usertask/UserTasksProcessVersion2.bpmn2");
assertThat(app).isNotNull();
final List<String> workItemTransitionEvents = new ArrayList<>();
app.config().process().processEventListeners().listeners().add(new DefaultProcessEventListener() {
@Override
public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("BEFORE:: " + event);
}
@Override
public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("AFTER:: " + event);
}
});
// verify that both versions have corresponding process definitions
assertThat(app.processes().processById("UserTasksProcess_2")).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTasksProcess_1");
assertThat(p).isNotNull();
// verify that both version have corresponding data model classes
Class<?> model1Class = Class.forName("org.kie.kogito.test.UserTasksProcess_1Model", true, testClassLoader());
assertNotNull(model1Class);
Class<?> model2Class = Class.forName("org.kie.kogito.test.UserTasksProcess_2Model", true, testClassLoader());
assertNotNull(model2Class);
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(workItemTransitionEvents).hasSize(8);
}
Aggregations