Search in sources :

Example 1 with TaskImpl

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

the class APITaskConverter method fromWithCandidates.

public Task fromWithCandidates(org.activiti.engine.task.Task internalTask) {
    TaskImpl task = (TaskImpl) from(internalTask, calculateStatus(internalTask));
    extractCandidateUsersAndGroups(internalTask, task);
    return task;
}
Also used : TaskImpl(org.activiti.api.task.model.impl.TaskImpl)

Example 2 with TaskImpl

use of org.activiti.api.task.model.impl.TaskImpl 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 TaskImpl

use of org.activiti.api.task.model.impl.TaskImpl 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 4 with TaskImpl

use of org.activiti.api.task.model.impl.TaskImpl 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 5 with TaskImpl

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

the class ToTaskCancelledConverterTest method should_returnConvertedTask_when_entityIsACancelledTask.

@Test
public void should_returnConvertedTask_when_entityIsACancelledTask() {
    // given
    Task internalTask = taskEntityBuilder().withCancelled(true).build();
    ActivitiEntityEventImpl internalEvent = new ActivitiEntityEventImpl(internalTask, ActivitiEventType.ENTITY_DELETED);
    TaskImpl apiTask = new TaskImpl("id", "myTask", org.activiti.api.task.model.Task.TaskStatus.CANCELLED);
    given(taskConverter.from(internalTask, org.activiti.api.task.model.Task.TaskStatus.CANCELLED)).willReturn(apiTask);
    // when
    TaskCancelledEvent convertedTaskCancelledEvent = eventConverter.from(internalEvent).orElse(null);
    // then
    assertThat(convertedTaskCancelledEvent).isNotNull();
    assertThat(convertedTaskCancelledEvent.getEntity()).isEqualTo(apiTask);
    assertThat(convertedTaskCancelledEvent.getEventType()).isEqualTo(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED);
}
Also used : Task(org.activiti.engine.task.Task) ActivitiEntityEventImpl(org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) TaskCancelledEvent(org.activiti.api.task.runtime.events.TaskCancelledEvent) Test(org.junit.jupiter.api.Test)

Aggregations

TaskImpl (org.activiti.api.task.model.impl.TaskImpl)11 Task (org.activiti.api.task.model.Task)7 Test (org.junit.jupiter.api.Test)5 List (java.util.List)2 TaskPayloadBuilder (org.activiti.api.task.model.builders.TaskPayloadBuilder)2 UpdateTaskPayload (org.activiti.api.task.model.payloads.UpdateTaskPayload)2 TaskAdminRuntime (org.activiti.api.task.runtime.TaskAdminRuntime)2 TaskRuntime (org.activiti.api.task.runtime.TaskRuntime)2 Task (org.activiti.engine.task.Task)2 RuntimeTestConfiguration (org.activiti.spring.boot.RuntimeTestConfiguration)2 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)2 TaskCleanUpUtil (org.activiti.spring.boot.test.util.TaskCleanUpUtil)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 AfterEach (org.junit.jupiter.api.AfterEach)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 TaskCancelledEvent (org.activiti.api.task.runtime.events.TaskCancelledEvent)1 ActivitiEntityEventImpl (org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl)1 TaskQuery (org.activiti.engine.task.TaskQuery)1