use of org.activiti.cloud.api.task.model.events.CloudTaskCreatedEvent in project activiti-cloud by Activiti.
the class TaskCreatedEventHandler method handle.
@Override
public void handle(CloudRuntimeEvent<?, ?> event) {
CloudTaskCreatedEvent taskCreatedEvent = (CloudTaskCreatedEvent) event;
TaskEntity queryTaskEntity = new TaskEntity(taskCreatedEvent);
if (!queryTaskEntity.isStandalone()) {
// Get processInstanceEntity reference proxy without database query
ProcessInstanceEntity processInstanceEntity = entityManager.getReference(ProcessInstanceEntity.class, queryTaskEntity.getProcessInstanceId());
queryTaskEntity.setProcessInstance(processInstanceEntity);
}
persistIntoDatabase(event, queryTaskEntity);
}
use of org.activiti.cloud.api.task.model.events.CloudTaskCreatedEvent in project activiti-cloud by Activiti.
the class QueryEventHandlerContextTest method handleShouldSelectHandlerBasedOnEventType.
@Test
public void handleShouldSelectHandlerBasedOnEventType() {
// given
CloudTaskCreatedEvent event = new CloudTaskCreatedEventImpl();
// when
context.handle(event);
// then
verify(handler).handle(event);
}
use of org.activiti.cloud.api.task.model.events.CloudTaskCreatedEvent in project activiti-cloud by Activiti.
the class AuditProducerIT method shouldProduceEventsDuringSimpleProcessExecution.
@Test
public void shouldProduceEventsDuringSimpleProcessExecution() {
// when
ResponseEntity<CloudProcessInstance> startProcessEntity = processInstanceRestTemplate.startProcess(ProcessPayloadBuilder.start().withProcessDefinitionKey(SIMPLE_PROCESS).withProcessDefinitionId(processDefinitionIds.get(SIMPLE_PROCESS)).withVariable("name", "peter").withName("my instance name").withBusinessKey("my business key").build());
// then
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getLatestReceivedEvents();
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents).extracting(event -> event.getEventType().name()).containsExactly(PROCESS_CREATED.name(), VARIABLE_CREATED.name(), PROCESS_UPDATED.name(), PROCESS_STARTED.name(), ACTIVITY_STARTED.name(), /*start event*/
BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED.name(), /*start event*/
SEQUENCE_FLOW_TAKEN.name(), ACTIVITY_STARTED.name(), /*user task*/
VARIABLE_CREATED.name(), /*task variable copy of proc var*/
TASK_CANDIDATE_GROUP_ADDED.name(), TASK_CANDIDATE_USER_ADDED.name(), TASK_CREATED.name());
assertThat(receivedEvents).filteredOn(event -> ACTIVITY_STARTED.equals(event.getEventType())).extracting(event -> ((CloudBPMNActivityStartedEvent) event).getEntity().getActivityType()).containsExactly("startEvent", "userTask");
assertThat(receivedEvents).filteredOn(cloudRuntimeEvent -> PROCESS_CREATED.equals(cloudRuntimeEvent.getEventType())).extracting(cloudRuntimeEvent -> ((ProcessInstance) cloudRuntimeEvent.getEntity()).getBusinessKey()).containsExactly("my business key");
assertThat(receivedEvents).filteredOn(cloudRuntimeEvent -> PROCESS_STARTED.equals(cloudRuntimeEvent.getEventType())).extracting(cloudRuntimeEvent -> ((ProcessInstance) cloudRuntimeEvent.getEntity()).getName()).containsExactly("my instance name");
assertThat(receivedEvents).filteredOn(event -> TASK_CREATED.equals(event.getEventType())).extracting(event -> event.getProcessDefinitionVersion(), event -> event.getBusinessKey(), event -> ((CloudTaskCreatedEvent) event).getEntity().getTaskDefinitionKey(), event -> ((CloudTaskCreatedEvent) event).getEntity().getFormKey()).containsExactly(tuple(startProcessEntity.getBody().getProcessDefinitionVersion(), startProcessEntity.getBody().getBusinessKey(), "sid-CDFE7219-4627-43E9-8CA8-866CC38EBA94", "taskFormKey"));
});
// when
processInstanceRestTemplate.suspend(startProcessEntity);
// then
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents1 = streamHandler.getLatestReceivedEvents();
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents1).extracting(event -> event.getEventType().name()).containsExactly(PROCESS_SUSPENDED.name(), TASK_SUSPENDED.name());
assertThat(receivedEvents1.get(0).getEntity()).isInstanceOf(ProcessInstance.class);
assertThat(receivedEvents1.get(0).getProcessDefinitionKey()).isEqualTo(SIMPLE_PROCESS);
});
// when
processInstanceRestTemplate.resume(startProcessEntity);
// then
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents2 = streamHandler.getLatestReceivedEvents();
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents2).extracting(event -> event.getEventType().name()).containsExactly(PROCESS_RESUMED.name(), TASK_ACTIVATED.name());
assertThat(receivedEvents2.get(0).getEntity()).isInstanceOf(ProcessInstance.class);
assertThat(receivedEvents2.get(0).getProcessDefinitionKey()).isEqualTo(SIMPLE_PROCESS);
});
// when
processInstanceRestTemplate.setVariables(startProcessEntity.getBody().getId(), Collections.singletonMap("name", "paul"));
// then
await().untilAsserted(() -> {
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(streamHandler.getLatestReceivedEvents()).extracting(event -> event.getEventType().name()).containsExactly(VARIABLE_UPDATED.name());
});
// given
ResponseEntity<PagedResources<CloudTask>> tasks = processInstanceRestTemplate.getTasks(startProcessEntity);
Task task = tasks.getBody().iterator().next();
// when
taskRestTemplate.claim(task);
await().untilAsserted(() -> {
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(streamHandler.getLatestReceivedEvents()).extracting(event -> event.getEventType().name()).containsExactly(TASK_ASSIGNED.name(), TASK_UPDATED.name());
});
// when
taskRestTemplate.complete(task);
// then
await().untilAsserted(() -> {
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(streamHandler.getLatestReceivedEvents()).extracting(event -> event.getEventType().name()).containsExactly(TASK_COMPLETED.name(), TASK_CANDIDATE_GROUP_REMOVED.name(), TASK_CANDIDATE_USER_REMOVED.name(), VARIABLE_UPDATED.name(), /*task local var copied back to proc var*/
BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED.name(), /*user task*/
SEQUENCE_FLOW_TAKEN.name(), ACTIVITY_STARTED.name(), /*end event*/
BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED.name(), /*end event*/
PROCESS_COMPLETED.name());
});
assertThat(streamHandler.getLatestReceivedEvents()).filteredOn(event -> event.getEventType().equals(TASK_COMPLETED)).extracting(event -> ((Task) event.getEntity()).getStatus()).containsOnly(Task.TaskStatus.COMPLETED);
}
use of org.activiti.cloud.api.task.model.events.CloudTaskCreatedEvent in project activiti-cloud by Activiti.
the class EmbeddedSubProcessAuditIT method shouldExecuteProcessWithEmbeddedSubProcess.
@Test
public void shouldExecuteProcessWithEmbeddedSubProcess() {
// given
ResponseEntity<CloudProcessInstance> processInstance = processInstanceRestTemplate.startProcess(buildStartProcessPayload(SIMPLE_EMBEDDED_SUB_PROCESS));
String processInstanceId = processInstance.getBody().getId();
await().untilAsserted(() -> {
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getLatestReceivedEvents();
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getParentProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey).containsExactly(tuple(PROCESS_CREATED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(PROCESS_UPDATED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(PROCESS_STARTED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_STARTED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_COMPLETED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_STARTED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_STARTED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_COMPLETED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_STARTED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(TASK_CANDIDATE_GROUP_ADDED, null, null, null), tuple(TASK_CREATED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS));
assertThat(receivedEvents).filteredOn(event -> TASK_CREATED.equals(event.getEventType())).extracting(CloudRuntimeEvent::getProcessInstanceId, event -> ((CloudTaskCreatedEvent) event).getEntity().getProcessInstanceId()).containsExactly(tuple(processInstanceId, processInstanceId));
List<CloudRuntimeEvent<?, ?>> activitiStartedEvents = receivedEvents.stream().filter(event -> ACTIVITY_STARTED.equals(event.getEventType())).collect(Collectors.toList());
assertThat(activitiStartedEvents).filteredOn(event -> ACTIVITY_STARTED.equals(event.getEventType())).extracting(event -> ((CloudBPMNActivityStartedEvent) event).getEntity().getActivityType(), event -> ((CloudBPMNActivityStartedEvent) event).getEntity().getActivityName()).containsExactly(tuple("startEvent", null), tuple("subProcess", "subProcess"), tuple("startEvent", null), tuple("userTask", "Task in subprocess"));
});
ResponseEntity<PagedResources<CloudTask>> tasks = processInstanceRestTemplate.getTasks(processInstance);
Task task = tasks.getBody().iterator().next();
// when
taskRestTemplate.claim(task);
await().untilAsserted(() -> {
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getLatestReceivedEvents();
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getParentProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey).containsExactly(tuple(TASK_ASSIGNED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(TASK_UPDATED, processInstanceId, null, SIMPLE_EMBEDDED_SUB_PROCESS));
String entityProcessInstanceId = ((CloudTaskAssignedEvent) receivedEvents.get(0)).getEntity().getProcessInstanceId();
assertThat(entityProcessInstanceId).isNotNull();
assertThat(entityProcessInstanceId).isEqualTo(processInstanceId);
});
// when
taskRestTemplate.complete(task);
// then
await().untilAsserted(() -> {
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getLatestReceivedEvents();
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey).containsExactly(tuple(TASK_COMPLETED, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(TASK_CANDIDATE_GROUP_REMOVED, null, null), tuple(ACTIVITY_COMPLETED, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_STARTED, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_COMPLETED, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_COMPLETED, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), /*subProcess*/
tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_STARTED, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(ACTIVITY_COMPLETED, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS), tuple(PROCESS_COMPLETED, processInstanceId, SIMPLE_EMBEDDED_SUB_PROCESS));
CloudBPMNActivityCompletedEvent subprocessCompletedEvent = (CloudBPMNActivityCompletedEvent) receivedEvents.stream().filter(event -> ACTIVITY_COMPLETED.equals(event.getEventType()) && "subProcess".equals(((CloudBPMNActivityCompletedEvent) event).getEntity().getActivityType())).collect(Collectors.toList()).get(0);
assertThat(subprocessCompletedEvent).isNotNull();
assertThat(subprocessCompletedEvent.getProcessInstanceId()).isEqualTo(processInstanceId);
});
}
Aggregations