Search in sources :

Example 71 with Task

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

the class APITaskConverterTest method should_returnCandidates_when_convertATaskWithCandidates.

@Test
public void should_returnCandidates_when_convertATaskWithCandidates() {
    given(taskService.getIdentityLinksForTask(any())).willReturn(asList(buildIdentityLink(null, "group1", IdentityLinkType.CANDIDATE), buildIdentityLink("user1", null, IdentityLinkType.CANDIDATE), buildIdentityLink(null, "participant", IdentityLinkType.PARTICIPANT), buildIdentityLink("user2", null, IdentityLinkType.CANDIDATE)));
    org.activiti.engine.task.Task source = taskBuilder().withId("1111").build();
    Task convertedTask = taskConverter.fromWithCandidates(source);
    assertThat(convertedTask).isNotNull();
    assertThat(convertedTask.getCandidateGroups()).hasSize(1);
    assertThat(convertedTask.getCandidateGroups()).containsExactlyInAnyOrder("group1");
    assertThat(convertedTask.getCandidateUsers()).hasSize(2);
    assertThat(convertedTask.getCandidateUsers()).containsExactlyInAnyOrder("user1", "user2");
    verify(taskService).getIdentityLinksForTask(eq("1111"));
}
Also used : Task(org.activiti.api.task.model.Task) Test(org.junit.jupiter.api.Test)

Example 72 with Task

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

the class APITaskConverterTest method should_convertTask_when_appVersionNull.

@Test
public void should_convertTask_when_appVersionNull() {
    Task convertedTask = taskConverter.from(taskBuilder().withAppVersion(null).build());
    assertThat(convertedTask).isNotNull().extracting(Task::getAppVersion).isNull();
}
Also used : Task(org.activiti.api.task.model.Task) Test(org.junit.jupiter.api.Test)

Example 73 with Task

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

the class TaskRuntimeImplTest method should_returnResultOfHelper_when_updateTask.

@Test
public void should_returnResultOfHelper_when_updateTask() {
    // given
    UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId("taskId").withDescription("new description").build();
    TaskImpl updatedTask = new TaskImpl();
    given(taskRuntimeHelper.applyUpdateTaskPayload(false, updateTaskPayload)).willReturn(updatedTask);
    // when
    Task retrievedTask = taskRuntime.update(updateTaskPayload);
    // then
    assertThat(retrievedTask).isEqualTo(updatedTask);
}
Also used : Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Test(org.junit.jupiter.api.Test)

Example 74 with Task

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

the class TaskAdminRuntimeImpl method complete.

@Override
public Task complete(CompleteTaskPayload completeTaskPayload) {
    Task task = task(completeTaskPayload.getTaskId());
    if (task == null) {
        throw new IllegalStateException("Task with id: " + completeTaskPayload.getTaskId() + " cannot be completed because it cannot be found.");
    }
    taskRuntimeHelper.handleCompleteTaskPayload(completeTaskPayload);
    TaskImpl competedTaskData = new TaskImpl(task.getId(), task.getName(), Task.TaskStatus.COMPLETED);
    taskService.complete(completeTaskPayload.getTaskId(), completeTaskPayload.getVariables(), true);
    return competedTaskData;
}
Also used : Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl)

Example 75 with Task

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

the class TaskRuntimeImpl method release.

@Override
public Task release(ReleaseTaskPayload releaseTaskPayload) {
    // Validate that the task is visible by the currently authorized user
    Task task;
    try {
        task = task(releaseTaskPayload.getTaskId());
    } catch (IllegalStateException ex) {
        throw new IllegalStateException("The authenticated user cannot release task" + releaseTaskPayload.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("You cannot release a task that is not claimed");
    }
    String authenticatedUserId = securityManager.getAuthenticatedUserId();
    // validate that you are trying to release task where you are the assignee
    if (!task.getAssignee().equals(authenticatedUserId)) {
        throw new IllegalStateException("You cannot release a task where you are not the assignee");
    }
    taskService.unclaim(releaseTaskPayload.getTaskId());
    return task(releaseTaskPayload.getTaskId());
}
Also used : Task(org.activiti.api.task.model.Task)

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