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