use of org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent in project activiti-cloud by Activiti.
the class AuditServiceIT method shouldBeAbleToFilterOnEventType.
@Test
public void shouldBeAbleToFilterOnEventType() {
// given
List<CloudRuntimeEvent> coveredEvents = getTestEvents();
producer.send(coveredEvents.toArray(new CloudRuntimeEvent[coveredEvents.size()]));
await().untilAsserted(() -> {
// when
ResponseEntity<PagedResources<CloudRuntimeEvent>> eventsPagedResources = eventsRestTemplate.executeFind(Collections.singletonMap("eventType", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED.name()));
// then
Collection<CloudRuntimeEvent> retrievedEvents = eventsPagedResources.getBody().getContent();
assertThat(retrievedEvents).hasSize(1);
CloudTaskAssignedEvent cloudTaskAssignedEvent = (CloudTaskAssignedEvent) retrievedEvents.iterator().next();
assertThat(cloudTaskAssignedEvent.getEventType()).isEqualTo(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED);
assertThat(cloudTaskAssignedEvent.getEntity().getProcessDefinitionId()).isEqualTo("27");
assertThat(cloudTaskAssignedEvent.getEntity().getProcessInstanceId()).isEqualTo("46");
});
}
use of org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent in project activiti-cloud by Activiti.
the class TaskAssignedEventHandler method handle.
@Override
public void handle(CloudRuntimeEvent<?, ?> event) {
CloudTaskAssignedEvent taskAssignedEvent = (CloudTaskAssignedEvent) event;
Task eventTask = taskAssignedEvent.getEntity();
Optional<TaskEntity> findResult = taskRepository.findById(eventTask.getId());
TaskEntity queryTaskEntity = findResult.orElseThrow(() -> new QueryException("Unable to find task with id: " + eventTask.getId()));
queryTaskEntity.setAssignee(eventTask.getAssignee());
queryTaskEntity.setStatus(Task.TaskStatus.ASSIGNED);
queryTaskEntity.setLastModified(new Date(taskAssignedEvent.getTimestamp()));
queryTaskEntity.setServiceName(taskAssignedEvent.getServiceName());
queryTaskEntity.setServiceFullName(taskAssignedEvent.getServiceFullName());
queryTaskEntity.setServiceVersion(taskAssignedEvent.getServiceVersion());
queryTaskEntity.setAppName(taskAssignedEvent.getAppName());
queryTaskEntity.setAppVersion(taskAssignedEvent.getAppVersion());
queryTaskEntity.setOwner(eventTask.getOwner());
queryTaskEntity.setClaimedDate(eventTask.getClaimedDate());
taskRepository.save(queryTaskEntity);
}
use of org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent in project activiti-cloud by Activiti.
the class TaskEntityAssignedEventHandlerTest method handleShouldThrowExceptionWhenNoTaskIsFoundForTheGivenId.
@Test
public void handleShouldThrowExceptionWhenNoTaskIsFoundForTheGivenId() {
// given
CloudTaskAssignedEvent event = buildTaskAssignedEvent();
String taskId = event.getEntity().getId();
given(taskRepository.findById(taskId)).willReturn(Optional.empty());
// then
// when
assertThatExceptionOfType(QueryException.class).isThrownBy(() -> handler.handle(event)).withMessageContaining("Unable to find task with id: " + taskId);
}
use of org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent in project activiti-cloud by Activiti.
the class TaskEntityAssignedEventHandlerTest method handleShouldUpdateTaskStatusToAssigned.
@Test
public void handleShouldUpdateTaskStatusToAssigned() {
// given
CloudTaskAssignedEvent event = buildTaskAssignedEvent();
String taskId = event.getEntity().getId();
TaskEntity taskEntity = aTask().withId(taskId).withAssignee("previousUser").build();
given(taskRepository.findById(taskId)).willReturn(Optional.of(taskEntity));
// when
handler.handle(event);
// then
verify(taskRepository).save(taskEntity);
verify(taskEntity).setStatus(Task.TaskStatus.ASSIGNED);
verify(taskEntity).setAssignee(event.getEntity().getAssignee());
verify(taskEntity).setLastModified(any(Date.class));
}
use of org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent 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