Search in sources :

Example 41 with InvalidArgumentException

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

the class WorkbasketServiceImpl method deleteWorkbasket.

@Override
public void deleteWorkbasket(String workbasketId) throws NotAuthorizedException, WorkbasketNotFoundException, WorkbasketInUseException, InvalidArgumentException {
    LOGGER.debug("entry to deleteWorkbasket(workbasketId = {})", workbasketId);
    taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
    try {
        taskanaEngine.openConnection();
        if (workbasketId == null || workbasketId.isEmpty()) {
            throw new InvalidArgumentException("The WorkbasketId can´t be NULL or EMPTY for deleteWorkbasket()");
        }
        // check if the workbasket does exist and is empty (Task)
        Workbasket wb = this.getWorkbasket(workbasketId);
        long numTasksInWorkbasket = taskanaEngine.getSqlSession().getMapper(TaskMapper.class).countTasksInWorkbasket(workbasketId).longValue();
        if (numTasksInWorkbasket > 0) {
            throw new WorkbasketInUseException("Workbasket is used on tasks and can´t be deleted. WorkbasketId=" + workbasketId);
        }
        // delete workbasket and sub-tables
        distributionTargetMapper.deleteAllDistributionTargetsBySourceId(wb.getId());
        distributionTargetMapper.deleteAllDistributionTargetsByTargetId(wb.getId());
        workbasketAccessMapper.deleteAllAccessItemsForWorkbasketId(wb.getId());
        workbasketMapper.delete(workbasketId);
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from deleteWorkbasket(workbasketId = {})", workbasketId);
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketInUseException(pro.taskana.exceptions.WorkbasketInUseException) Workbasket(pro.taskana.Workbasket)

Aggregations

InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)41 Test (org.junit.Test)24 AbstractAccTest (acceptance.AbstractAccTest)21 WithAccessId (pro.taskana.security.WithAccessId)19 TaskService (pro.taskana.TaskService)18 TaskSummary (pro.taskana.TaskSummary)16 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)12 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)11 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Task (pro.taskana.Task)7 Workbasket (pro.taskana.Workbasket)7 Classification (pro.taskana.Classification)6 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)6 SQLException (java.sql.SQLException)5 ClassificationSummary (pro.taskana.ClassificationSummary)5 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)5 WorkbasketService (pro.taskana.WorkbasketService)5 Instant (java.time.Instant)4 Collectors (java.util.stream.Collectors)4