Search in sources :

Example 6 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeImpl method delete.

@Override
public Task delete(DeleteTaskPayload deleteTaskPayload) {
    // @TODO: not the most efficient way to return the just deleted task, improve
    // we might need to create an empty shell with the task ID and Status only
    Task task;
    try {
        task = task(deleteTaskPayload.getTaskId());
    } catch (IllegalStateException ex) {
        throw new IllegalStateException("The authenticated user cannot delete the task" + deleteTaskPayload.getTaskId() + " due it is not the current assignee");
    }
    String authenticatedUserId = securityManager.getAuthenticatedUserId();
    // validate that you are trying to delete task where you are the assignee or the owner
    if ((task.getAssignee() == null || task.getAssignee().isEmpty() || !task.getAssignee().equals(authenticatedUserId)) && (task.getOwner() == null || task.getOwner().isEmpty() || !task.getOwner().equals(authenticatedUserId))) {
        throw new IllegalStateException("You cannot delete a task where you are not the assignee/owner");
    }
    TaskImpl deletedTaskData = new TaskImpl(task.getId(), task.getName(), Task.TaskStatus.CANCELLED);
    if (!deleteTaskPayload.hasReason()) {
        deleteTaskPayload.setReason("Task deleted by " + authenticatedUserId);
    }
    taskService.deleteTask(deleteTaskPayload.getTaskId(), deleteTaskPayload.getReason(), true);
    return deletedTaskData;
}
Also used : Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl)

Example 7 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class APITaskConverterTest method should_convertTask_when_allFieldsAreSet.

@Test
public void should_convertTask_when_allFieldsAreSet() {
    Date now = new Date();
    Task convertedTask = taskConverter.from(taskBuilder().withId("testTaskId").withAssignee("testUser").withName("testTaskName").withDescription("testTaskDescription").withCreatedDate(now).withClaimedDate(now).withDueDate(now).withPriority(112).withProcessDefinitionId("testProcessDefinitionId").withProcessInstanceId("testProcessInstanceId").withParentTaskId("testParentTaskId").withFormKey("testFormKey").withTaskDefinitionKey("taskDefinitionKey").withAppVersion(1).withBusinessKey("businessKey").build());
    assertThat(convertedTask).isNotNull().extracting(Task::getId, Task::getAssignee, Task::getName, Task::getDescription, Task::getCreatedDate, Task::getClaimedDate, Task::getDueDate, Task::getPriority, Task::getProcessDefinitionId, Task::getProcessInstanceId, Task::getParentTaskId, Task::getFormKey, Task::getStatus, Task::getTaskDefinitionKey, Task::getAppVersion, Task::getBusinessKey).containsExactly("testTaskId", "testUser", "testTaskName", "testTaskDescription", now, now, now, 112, "testProcessDefinitionId", "testProcessInstanceId", "testParentTaskId", "testFormKey", ASSIGNED, "taskDefinitionKey", "1", "businessKey");
}
Also used : Task(org.activiti.api.task.model.Task) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 8 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeOperations method complete.

@Override
public TaskAssertions complete(CompleteTaskPayload completeTaskPayload) {
    Task task = taskRuntime.task(completeTaskPayload.getTaskId());
    taskRuntime.complete(completeTaskPayload);
    return buildTaskAssertions(task);
}
Also used : Task(org.activiti.api.task.model.Task)

Example 9 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeMultiInstanceIT method sequentialMultiInstance_should_collectOutputValues.

@Test
public void sequentialMultiInstance_should_collectOutputValues() {
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miSequentialUserTasksOutputCollection");
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).hasSize(1);
    taskBaseRuntime.completeTask(tasks.get(0), singletonMap("meal", "pizza"));
    tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).hasSize(1);
    taskBaseRuntime.completeTask(tasks.get(0), singletonMap("meal", "pasta"));
    List<VariableInstance> variables = processBaseRuntime.getVariables(processInstance);
    assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("meals", asList("pizza", "pasta")));
}
Also used : Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOnUserTask_Boundary_Event.

@Test
public void processWithParallelMultiInstancesOnUserTask_Boundary_Event() {
    // when
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelUserTaskBoundaryEvent");
    // then
    assertThat(taskBaseRuntime.getTasks(processInstance)).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0", "My Task 1");
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
    // when
    long waitTime = 1 * 60 * 1000;
    Date startTime = new Date();
    Date dueDate = new Date(startTime.getTime() + waitTime);
    // set the clock so the timer fires
    localEventSource.clearEvents();
    processEngineConfiguration.getClock().setCurrentTime(new Date(dueDate.getTime()));
    await().untilAsserted(() -> {
        assertThat(localEventSource.getEvents(BPMNTimerEvent.class)).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).containsExactly(tuple(BPMNTimerEvent.TimerEvents.TIMER_FIRED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"), tuple(BPMNTimerEvent.TimerEvents.TIMER_EXECUTED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
        assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
        assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
        // need to login again before getting the list of tasks
        // because Awaitility will run this inside another thread
        securityUtil.logInAs("user");
        List<Task> availableTasks = taskBaseRuntime.getTasks(processInstance);
        assertThat(availableTasks).extracting(Task::getName).containsExactly("Escalation Task");
        localEventSource.clearEvents();
        taskBaseRuntime.completeTask(availableTasks.get(0));
    });
    assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactly(tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_COMPLETED));
    assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
    assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DummyBPMNTimerCancelledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerCancelledListener) ProcessRuntimeEvent(org.activiti.api.process.model.events.ProcessRuntimeEvent) Task(org.activiti.api.task.model.Task) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BPMNActivityStartedEvent(org.activiti.api.process.model.events.BPMNActivityStartedEvent) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) ProcessStartedEvent(org.activiti.api.process.runtime.events.ProcessStartedEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) ProcessCompletedEvent(org.activiti.api.process.runtime.events.ProcessCompletedEvent) ActiveProfiles(org.springframework.test.context.ActiveProfiles) DummyBPMNTimerScheduledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerScheduledListener) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) TaskCreatedEvent(org.activiti.api.task.runtime.events.TaskCreatedEvent) Arrays.asList(java.util.Arrays.asList) DummyBPMNTimerExecutedListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerExecutedListener) LocalEventSource(org.activiti.test.LocalEventSource) Collections.singletonMap(java.util.Collections.singletonMap) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) BPMNActivityCancelledEvent(org.activiti.api.process.model.events.BPMNActivityCancelledEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) BPMNActivityCompletedEvent(org.activiti.api.process.model.events.BPMNActivityCompletedEvent) Awaitility.await(org.awaitility.Awaitility.await) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TimerTestConfigurator(org.activiti.spring.boot.process.TimerTestConfigurator) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) BPMNActivityEvent(org.activiti.api.process.model.events.BPMNActivityEvent) Import(org.springframework.context.annotation.Import) Page(org.activiti.api.runtime.shared.query.Page) Collectors(java.util.stream.Collectors) TaskAssignedEvent(org.activiti.api.task.runtime.events.TaskAssignedEvent) DummyBPMNTimerFiredListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerFiredListener) Test(org.junit.jupiter.api.Test) ProcessRuntimeBPMNTimerIT(org.activiti.spring.boot.process.ProcessRuntimeBPMNTimerIT) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) ProcessBaseRuntime(org.activiti.spring.boot.process.ProcessBaseRuntime) Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Task (org.activiti.api.task.model.Task)115 Test (org.junit.jupiter.api.Test)99 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)95 ProcessInstance (org.activiti.api.process.model.ProcessInstance)59 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)29 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)25 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)23 AfterEach (org.junit.jupiter.api.AfterEach)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)22 Page (org.activiti.api.runtime.shared.query.Page)21 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)20 BeforeEach (org.junit.jupiter.api.BeforeEach)20 Import (org.springframework.context.annotation.Import)20 Date (java.util.Date)19 List (java.util.List)19 Collections.singletonMap (java.util.Collections.singletonMap)15 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)15 ProcessRuntimeEvent (org.activiti.api.process.model.events.ProcessRuntimeEvent)15 TaskRuntimeEvent (org.activiti.api.task.model.events.TaskRuntimeEvent)15