use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class PublishEventTest method testBasicUserTaskProcessWithSensitiveData.
@Test
public void testBasicUserTaskProcessWithSensitiveData() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessSensitive.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("name", "john");
parameters.put("ssn", "123-456");
m.fromMap(parameters);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getTags()).hasSize(0);
assertThat(body.getVariables()).hasSize(1).containsEntry("name", "john");
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(3);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class PublishEventTest method testBasicUserTaskProcess.
@Test
public void testBasicUserTaskProcess() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(3);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class MockEventPublisher method waitForNodeEntered.
public boolean waitForNodeEntered(String nodeName, long elapsed) throws InterruptedException {
boolean found = false;
while (elapsed >= 0) {
elapsed -= 1000;
Thread.sleep(1000);
for (DataEvent<?> event : events) {
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;
found = piEvent.getData().getNodeInstances().stream().anyMatch(ni -> ni.getNodeName().equals(nodeName) && ni.getLeaveTime() == null);
if (found) {
break;
}
}
if (found) {
break;
}
}
return found;
}
use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class MockEventPublisher method waitForNodeCompleted.
public boolean waitForNodeCompleted(String nodeName, long elapsed) throws InterruptedException {
boolean found = false;
while (elapsed >= 0) {
elapsed -= 1000;
Thread.sleep(1000);
for (DataEvent<?> event : events) {
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;
found = piEvent.getData().getNodeInstances().stream().map(ni -> log(ni)).anyMatch(ni -> ni.getNodeName().equals(nodeName) && ni.getLeaveTime() != null);
if (found) {
break;
}
}
if (found) {
break;
}
}
return found;
}
use of io.automatiko.engine.api.event.DataEvent 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