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