Search in sources :

Example 1 with WorkbasketInUseException

use of pro.taskana.exceptions.WorkbasketInUseException 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

Workbasket (pro.taskana.Workbasket)1 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)1 WorkbasketInUseException (pro.taskana.exceptions.WorkbasketInUseException)1