Search in sources :

Example 1 with CloudTaskAssignedEvent

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");
    });
}
Also used : PagedResources(org.springframework.hateoas.PagedResources) CloudTaskAssignedEvent(org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with CloudTaskAssignedEvent

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);
}
Also used : Task(org.activiti.api.task.model.Task) QueryException(org.activiti.cloud.services.query.model.QueryException) TaskEntity(org.activiti.cloud.services.query.model.TaskEntity) CloudTaskAssignedEvent(org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent) Date(java.util.Date)

Example 3 with CloudTaskAssignedEvent

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);
}
Also used : CloudTaskAssignedEvent(org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with CloudTaskAssignedEvent

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));
}
Also used : TaskEntity(org.activiti.cloud.services.query.model.TaskEntity) CloudTaskAssignedEvent(org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with CloudTaskAssignedEvent

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);
    });
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) DirtiesContext(org.springframework.test.annotation.DirtiesContext) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ActiveProfiles(org.springframework.test.context.ActiveProfiles) SignalRestTemplate(org.activiti.cloud.starter.tests.helper.SignalRestTemplate) CloudTask(org.activiti.cloud.api.task.model.CloudTask) PagedResources(org.springframework.hateoas.PagedResources) MESSAGE_SUBSCRIPTION_CANCELLED(org.activiti.api.process.model.events.MessageSubscriptionEvent.MessageSubscriptionEvents.MESSAGE_SUBSCRIPTION_CANCELLED) SIGNAL_RECEIVED(org.activiti.api.process.model.events.BPMNSignalEvent.SignalEvents.SIGNAL_RECEIVED) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Awaitility.await(org.awaitility.Awaitility.await) Collection(java.util.Collection) TestPropertySource(org.springframework.test.context.TestPropertySource) SEQUENCE_FLOW_TAKEN(org.activiti.api.process.model.events.SequenceFlowEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) TASK_UPDATED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_UPDATED) List(java.util.List) Stream(java.util.stream.Stream) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) TASK_CREATED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_CREATED) TASK_CANDIDATE_GROUP_REMOVED(org.activiti.api.task.model.events.TaskCandidateGroupEvent.TaskCandidateGroupEvents.TASK_CANDIDATE_GROUP_REMOVED) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) TASK_ASSIGNED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED) Value(org.springframework.beans.factory.annotation.Value) TaskRestTemplate(org.activiti.cloud.starter.tests.helper.TaskRestTemplate) SignalPayload(org.activiti.api.process.model.payloads.SignalPayload) ProcessEvents(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents) CloudBPMNActivityCompletedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityCompletedEvent) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) TASK_CANDIDATE_GROUP_ADDED(org.activiti.api.task.model.events.TaskCandidateGroupEvent.TaskCandidateGroupEvents.TASK_CANDIDATE_GROUP_ADDED) CloudTaskCreatedEvent(org.activiti.cloud.api.task.model.events.CloudTaskCreatedEvent) MESSAGE_RECEIVED(org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED) CloudProcessDefinition(org.activiti.cloud.api.process.model.CloudProcessDefinition) Execution(org.activiti.engine.runtime.Execution) TASK_COMPLETED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_COMPLETED) Assertions.tuple(org.assertj.core.api.Assertions.tuple) CloudBPMNActivityStartedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent) HttpMethod(org.springframework.http.HttpMethod) TASK_CANCELLED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_CANCELLED) CloudTaskAssignedEvent(org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent) StartProcessPayload(org.activiti.api.process.model.payloads.StartProcessPayload) HttpStatus(org.springframework.http.HttpStatus) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) MESSAGE_WAITING(org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_WAITING) ACTIVITY_CANCELLED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ResponseEntity(org.springframework.http.ResponseEntity) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Task(org.activiti.api.task.model.Task) CloudTask(org.activiti.cloud.api.task.model.CloudTask) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) PagedResources(org.springframework.hateoas.PagedResources) CloudBPMNActivityCompletedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNActivityCompletedEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CloudTaskAssignedEvent (org.activiti.cloud.api.task.model.events.CloudTaskAssignedEvent)5 Test (org.junit.jupiter.api.Test)3 Date (java.util.Date)2 Task (org.activiti.api.task.model.Task)2 CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)2 TaskEntity (org.activiti.cloud.services.query.model.TaskEntity)2 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 ProcessInstance (org.activiti.api.process.model.ProcessInstance)1 ProcessPayloadBuilder (org.activiti.api.process.model.builders.ProcessPayloadBuilder)1 ACTIVITY_CANCELLED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED)1 ACTIVITY_COMPLETED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED)1 ACTIVITY_STARTED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED)1 MESSAGE_RECEIVED (org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED)1 MESSAGE_WAITING (org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_WAITING)1 SIGNAL_RECEIVED (org.activiti.api.process.model.events.BPMNSignalEvent.SignalEvents.SIGNAL_RECEIVED)1 MESSAGE_SUBSCRIPTION_CANCELLED (org.activiti.api.process.model.events.MessageSubscriptionEvent.MessageSubscriptionEvents.MESSAGE_SUBSCRIPTION_CANCELLED)1 ProcessEvents (org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents)1