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()));
}
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;
}
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());
}
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;
}
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()));
}
Aggregations