Search in sources :

Example 1 with Task

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

the class TaskAdminRuntimeImpl method tasks.

@Override
public Page<Task> tasks(Pageable pageable, GetTasksPayload getTasksPayload) {
    TaskQuery taskQuery = taskService.createTaskQuery();
    if (getTasksPayload.getProcessInstanceId() != null) {
        taskQuery = taskQuery.processInstanceId(getTasksPayload.getProcessInstanceId());
    }
    if (getTasksPayload.getParentTaskId() != null) {
        taskQuery = taskQuery.taskParentTaskId(getTasksPayload.getParentTaskId());
    }
    List<Task> tasks = taskConverter.from(taskQuery.listPage(pageable.getStartIndex(), pageable.getMaxItems()));
    return new PageImpl<>(tasks, Math.toIntExact(taskQuery.count()));
}
Also used : PageImpl(org.activiti.runtime.api.query.impl.PageImpl) Task(org.activiti.api.task.model.Task) TaskQuery(org.activiti.engine.task.TaskQuery)

Example 2 with Task

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

the class TaskAdminRuntimeImpl method delete.

@Override
public Task delete(DeleteTaskPayload deleteTaskPayload) {
    // we might need to create an empty shell with the task ID and Status only
    Task task = task(deleteTaskPayload.getTaskId());
    TaskImpl deletedTaskData = new TaskImpl(task.getId(), task.getName(), Task.TaskStatus.CANCELLED);
    String authenticatedUserId = securityManager.getAuthenticatedUserId();
    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 3 with Task

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

the class TaskRuntimeImpl method claim.

@Override
public Task claim(ClaimTaskPayload claimTaskPayload) {
    // Validate that the task is visible by the currently authorized user
    Task task;
    try {
        task = task(claimTaskPayload.getTaskId());
    } catch (IllegalStateException ex) {
        throw new IllegalStateException("The authenticated user cannot claim task" + claimTaskPayload.getTaskId() + " due it is not a candidate for it");
    }
    // validate the the task doesn't have an assignee
    if (task.getAssignee() != null && !task.getAssignee().isEmpty()) {
        throw new IllegalStateException("The task was already claimed, the assignee of this task needs to release it first for you to claim it");
    }
    String authenticatedUserId = securityManager.getAuthenticatedUserId();
    claimTaskPayload.setAssignee(authenticatedUserId);
    taskService.claim(claimTaskPayload.getTaskId(), claimTaskPayload.getAssignee());
    return task(claimTaskPayload.getTaskId());
}
Also used : Task(org.activiti.api.task.model.Task)

Example 4 with Task

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

the class TaskRuntimeImpl method complete.

@Override
public Task complete(CompleteTaskPayload completeTaskPayload) {
    // @TODO: not the most efficient way to return the just completed task, improve
    // we might need to create an empty shell with the task ID and Status only
    Task task;
    String authenticatedUserId = securityManager.getAuthenticatedUserId();
    try {
        task = task(completeTaskPayload.getTaskId());
    } catch (IllegalStateException ex) {
        throw new IllegalStateException("The authenticated user cannot complete task" + completeTaskPayload.getTaskId() + " due he/she cannot access to the task");
    }
    // validate the the task does have an assignee
    if (task.getAssignee() == null || task.getAssignee().isEmpty()) {
        throw new IllegalStateException("The task needs to be claimed before trying to complete it");
    }
    if (!task.getAssignee().equals(authenticatedUserId)) {
        throw new IllegalStateException("You cannot complete the task if you are not assigned to it");
    }
    taskRuntimeHelper.handleCompleteTaskPayload(completeTaskPayload);
    taskService.complete(completeTaskPayload.getTaskId(), completeTaskPayload.getVariables(), true);
    ((TaskImpl) task).setStatus(Task.TaskStatus.COMPLETED);
    return task;
}
Also used : Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl)

Example 5 with Task

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

the class TaskRuntimeImpl method tasks.

@Override
public Page<Task> tasks(Pageable pageable, GetTasksPayload getTasksPayload) {
    TaskQuery taskQuery = taskService.createTaskQuery();
    if (getTasksPayload == null) {
        getTasksPayload = TaskPayloadBuilder.tasks().build();
    }
    String authenticatedUserId = securityManager.getAuthenticatedUserId();
    if (authenticatedUserId != null && !authenticatedUserId.isEmpty()) {
        List<String> userGroups = securityManager.getAuthenticatedUserGroups();
        getTasksPayload.setAssigneeId(authenticatedUserId);
        getTasksPayload.setGroups(userGroups);
    } else {
        throw new IllegalStateException("You need an authenticated user to perform a task query");
    }
    taskQuery = taskQuery.or().taskCandidateOrAssigned(getTasksPayload.getAssigneeId(), getTasksPayload.getGroups()).taskOwner(authenticatedUserId).endOr();
    if (getTasksPayload.getProcessInstanceId() != null) {
        taskQuery = taskQuery.processInstanceId(getTasksPayload.getProcessInstanceId());
    }
    if (getTasksPayload.getParentTaskId() != null) {
        taskQuery = taskQuery.taskParentTaskId(getTasksPayload.getParentTaskId());
    }
    List<Task> tasks = taskConverter.from(taskQuery.listPage(pageable.getStartIndex(), pageable.getMaxItems()));
    return new PageImpl<>(tasks, Math.toIntExact(taskQuery.count()));
}
Also used : PageImpl(org.activiti.runtime.api.query.impl.PageImpl) Task(org.activiti.api.task.model.Task) TaskQuery(org.activiti.engine.task.TaskQuery)

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