Search in sources :

Example 6 with TaskanaException

use of pro.taskana.exceptions.TaskanaException in project taskana by Taskana.

the class TaskServiceImpl method completeTasks.

@Override
public BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds) throws InvalidArgumentException {
    try {
        LOGGER.debug("entry to completeTasks(taskIds = {})", taskIds);
        taskanaEngine.openConnection();
        // Check pre-conditions with throwing Exceptions
        if (taskIds == null) {
            throw new InvalidArgumentException("TaskIds canĀ“t be used as NULL-Parameter.");
        }
        // process bulk-complete
        BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
        if (!taskIds.isEmpty()) {
            // remove null/empty taskIds with message
            Iterator<String> taskIdIterator = taskIds.iterator();
            while (taskIdIterator.hasNext()) {
                String currentTaskId = taskIdIterator.next();
                if (currentTaskId == null || currentTaskId.isEmpty()) {
                    bulkLog.addError("", new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed and invalid."));
                    taskIdIterator.remove();
                }
            }
            // query for existing tasks, modify values and LOG missing ones.
            List<TaskSummary> taskSummaries = this.createTaskQuery().idIn(taskIds.toArray(new String[0])).list();
            Instant now = Instant.now();
            taskIdIterator = taskIds.iterator();
            while (taskIdIterator.hasNext()) {
                String currentTaskId = taskIdIterator.next();
                TaskSummaryImpl taskSummary = (TaskSummaryImpl) taskSummaries.stream().filter(ts -> currentTaskId.equals(ts.getTaskId())).findFirst().orElse(null);
                if (taskSummary == null) {
                    bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId, "task with id " + currentTaskId + " was not found."));
                    taskIdIterator.remove();
                } else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) {
                    bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
                    taskIdIterator.remove();
                } else if (!CurrentUserContext.getAccessIds().contains(taskSummary.getOwner())) {
                    bulkLog.addError(currentTaskId, new InvalidOwnerException("TaskOwner is" + taskSummary.getOwner() + ", but current User is " + CurrentUserContext.getUserid()));
                    taskIdIterator.remove();
                } else {
                    taskSummary.setCompleted(now);
                    taskSummary.setModified(now);
                    taskSummary.setState(TaskState.COMPLETED);
                }
            }
            if (!taskIds.isEmpty() && !taskSummaries.isEmpty()) {
                taskMapper.updateCompleted(taskIds, (TaskSummaryImpl) taskSummaries.get(0));
            }
        }
        return bulkLog;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from to completeTasks(taskIds = {})", taskIds);
    }
}
Also used : Arrays(java.util.Arrays) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) IdGenerator(pro.taskana.impl.util.IdGenerator) LoggerFactory(org.slf4j.LoggerFactory) WorkbasketService(pro.taskana.WorkbasketService) ArrayList(java.util.ArrayList) CurrentUserContext(pro.taskana.security.CurrentUserContext) HashSet(java.util.HashSet) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SystemException(pro.taskana.exceptions.SystemException) CustomPropertySelector(pro.taskana.mappings.CustomPropertySelector) Task(pro.taskana.Task) InvalidStateException(pro.taskana.exceptions.InvalidStateException) Duration(java.time.Duration) Map(java.util.Map) TaskState(pro.taskana.TaskState) WorkbasketPermission(pro.taskana.WorkbasketPermission) WorkbasketSummary(pro.taskana.WorkbasketSummary) TimeIntervalColumnHeader(pro.taskana.impl.report.impl.TimeIntervalColumnHeader) ClassificationSummary(pro.taskana.ClassificationSummary) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskanaEngine(pro.taskana.TaskanaEngine) Attachment(pro.taskana.Attachment) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) TaskSummary(pro.taskana.TaskSummary) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) Logger(org.slf4j.Logger) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) Iterator(java.util.Iterator) Set(java.util.Set) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) AttachmentMapper(pro.taskana.mappings.AttachmentMapper) Classification(pro.taskana.Classification) LoggerUtils(pro.taskana.impl.util.LoggerUtils) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) TaskMapper(pro.taskana.mappings.TaskMapper) List(java.util.List) Workbasket(pro.taskana.Workbasket) TaskanaRole(pro.taskana.TaskanaRole) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) TaskanaException(pro.taskana.exceptions.TaskanaException) TaskQuery(pro.taskana.TaskQuery) Collections(java.util.Collections) Instant(java.time.Instant) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskanaException(pro.taskana.exceptions.TaskanaException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskSummary(pro.taskana.TaskSummary) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException)

Example 7 with TaskanaException

use of pro.taskana.exceptions.TaskanaException in project taskana by Taskana.

the class WorkOnTaskAccTest method testBulkCompleteTasks.

@WithAccessId(userName = "user_1_2", groupNames = { "group_1" })
@Test
public void testBulkCompleteTasks() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, ConcurrencyException, AttachmentPersistenceException {
    TaskService taskService = taskanaEngine.getTaskService();
    List<String> taskIdList = new ArrayList<>();
    taskIdList.add("TKI:000000000000000000000000000000000100");
    taskIdList.add("TKI:000000000000000000000000000000000101");
    BulkOperationResults<String, TaskanaException> results = taskService.completeTasks(taskIdList);
    assertFalse(results.containsErrors());
    Task completedTask1 = taskService.getTask("TKI:000000000000000000000000000000000100");
    assertEquals(TaskState.COMPLETED, completedTask1.getState());
    assertNotNull(completedTask1.getCompleted());
    Task completedTask2 = taskService.getTask("TKI:000000000000000000000000000000000101");
    assertEquals(TaskState.COMPLETED, completedTask2.getState());
    assertNotNull(completedTask2.getCompleted());
}
Also used : Task(pro.taskana.Task) TaskService(pro.taskana.TaskService) ArrayList(java.util.ArrayList) TaskanaException(pro.taskana.exceptions.TaskanaException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 8 with TaskanaException

use of pro.taskana.exceptions.TaskanaException in project taskana by Taskana.

the class WorkOnTaskAccTest method testBulkDeleteTasksWithException.

@WithAccessId(userName = "user_1_2", groupNames = { "group_1" })
@Test
public void testBulkDeleteTasksWithException() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, ConcurrencyException, AttachmentPersistenceException {
    TaskService taskService = taskanaEngine.getTaskService();
    List<String> taskIdList = new ArrayList<>();
    taskIdList.add("TKI:000000000000000000000000000000000102");
    taskIdList.add("TKI:000000000000000000000000000000003333");
    BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
    assertTrue(results.containsErrors());
    assertThat(results.getErrorMap().size(), equalTo(2));
    assertTrue(results.getErrorForId("TKI:000000000000000000000000000000003333") instanceof TaskNotFoundException);
    assertTrue(results.getErrorForId("TKI:000000000000000000000000000000000102") instanceof InvalidStateException);
}
Also used : TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskService(pro.taskana.TaskService) ArrayList(java.util.ArrayList) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskanaException(pro.taskana.exceptions.TaskanaException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 9 with TaskanaException

use of pro.taskana.exceptions.TaskanaException in project taskana by Taskana.

the class DeleteTaskAccTest method testBulkDeleteTask.

@WithAccessId(userName = "user_1_2", groupNames = { "group_1" })
@Test(expected = TaskNotFoundException.class)
public void testBulkDeleteTask() throws TaskNotFoundException, InvalidArgumentException, NotAuthorizedException {
    TaskService taskService = taskanaEngine.getTaskService();
    ArrayList<String> taskIdList = new ArrayList<>();
    taskIdList.add("TKI:000000000000000000000000000000000037");
    taskIdList.add("TKI:000000000000000000000000000000000038");
    BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
    assertFalse(results.containsErrors());
    taskService.getTask("TKI:000000000000000000000000000000000038");
}
Also used : TaskService(pro.taskana.TaskService) ArrayList(java.util.ArrayList) TaskanaException(pro.taskana.exceptions.TaskanaException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

TaskanaException (pro.taskana.exceptions.TaskanaException)9 ArrayList (java.util.ArrayList)7 TaskService (pro.taskana.TaskService)7 AbstractAccTest (acceptance.AbstractAccTest)6 Test (org.junit.Test)6 WithAccessId (pro.taskana.security.WithAccessId)6 Task (pro.taskana.Task)5 TaskNotFoundException (pro.taskana.exceptions.TaskNotFoundException)5 Instant (java.time.Instant)4 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)4 InvalidStateException (pro.taskana.exceptions.InvalidStateException)4 Workbasket (pro.taskana.Workbasket)3 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)3 HashSet (java.util.HashSet)2 WorkbasketSummary (pro.taskana.WorkbasketSummary)2 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1