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