use of pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException in project taskana by Taskana.
the class TaskQueryImpl method list.
@Override
public List<TaskSummary> list(int offset, int limit) {
LOGGER.debug("entry to list(offset = {}, limit = {}), this = {}", offset, limit, this);
List<TaskSummary> result = new ArrayList<>();
try {
taskanaEngine.openConnection();
checkOpenPermissionForSpecifiedWorkbaskets();
RowBounds rowBounds = new RowBounds(offset, limit);
List<TaskSummaryImpl> tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds);
result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
return result;
} catch (PersistenceException e) {
if (e.getMessage().contains("ERRORCODE=-4470")) {
TaskanaRuntimeException ex = new TaskanaRuntimeException("The offset beginning was set over the amount of result-rows.", e.getCause());
ex.setStackTrace(e.getStackTrace());
throw ex;
}
throw e;
} catch (NotAuthorizedException e) {
throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(offset,limit). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
}
use of pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException in project taskana by Taskana.
the class ClassificationServiceImpl method deleteClassification.
@Override
public void deleteClassification(String classificationKey, String domain) throws ClassificationInUseException, ClassificationNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to deleteClassification(key = {}, domain = {})", classificationKey, domain);
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
try {
taskanaEngine.openConnection();
Classification classification = this.classificationMapper.findByKeyAndDomain(classificationKey, domain);
if (classification == null) {
throw new ClassificationNotFoundException(classificationKey, domain, "The classification " + classificationKey + "wasn't found in the domain " + domain);
}
List<AttachmentSummaryImpl> attachments = taskanaEngine.getSqlSession().getMapper(AttachmentMapper.class).findAttachmentSummariesByClassificationId(classification.getId());
if (!attachments.isEmpty()) {
throw new ClassificationInUseException("Classification " + classification.getId() + " is used by Attachment " + attachments.get(0).getId());
}
if (domain.equals("")) {
// master mode - delete all associated classifications in every domain.
List<String> domains = this.classificationMapper.getDomainsForClassification(classificationKey);
domains.remove("");
for (String classificationDomain : domains) {
deleteClassification(classificationKey, classificationDomain);
}
}
TaskServiceImpl taskService = (TaskServiceImpl) taskanaEngine.getTaskService();
try {
List<TaskSummary> classificationTasks = taskService.createTaskQuery().classificationKeyIn(classificationKey).list();
if (classificationTasks.stream().anyMatch(t -> domain.equals(t.getClassificationSummary().getDomain()))) {
throw new ClassificationInUseException("There are Tasks that belong to this classification or a child classification. Please complete them and try again.");
}
} catch (NotAuthorizedToQueryWorkbasketException e) {
LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
}
List<String> childKeys = this.classificationMapper.getChildrenOfClassification(classification.getId());
for (String key : childKeys) {
this.deleteClassification(key, domain);
}
this.classificationMapper.deleteClassificationInDomain(classificationKey, domain);
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteClassification()");
}
}
use of pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException in project taskana by Taskana.
the class UpdateWorkbasketAuthorizationsAccTest method testUpdatedAccessItemLeadsToNotAuthorizedException.
@WithAccessId(userName = "user_1_1", groupNames = { "group_2", "businessadmin" })
@Test
public void testUpdatedAccessItemLeadsToNotAuthorizedException() throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException {
TaskService taskService = taskanaEngine.getTaskService();
WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
String wbKey = "USER_2_1";
String wbDomain = "DOMAIN_A";
String groupName = "group_2";
Task newTask = taskService.newTask(wbKey, wbDomain);
newTask.setClassificationKey("T2100");
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
Task createdTask = taskService.createTask(newTask);
List<TaskSummary> tasks = taskService.createTaskQuery().workbasketKeyDomainIn(new KeyDomain(wbKey, wbDomain)).list();
Assert.assertEquals(1, tasks.size());
assertThat(createdTask, not(equalTo(null)));
List<WorkbasketAccessItem> accessItems = workbasketService.getWorkbasketAccessItems("WBI:100000000000000000000000000000000008");
WorkbasketAccessItem theAccessItem = accessItems.stream().filter(x -> groupName.equals(x.getAccessId())).findFirst().orElse(null);
Assert.assertTrue(theAccessItem != null);
theAccessItem.setPermOpen(false);
workbasketService.updateWorkbasketAccessItem(theAccessItem);
try {
taskService.createTaskQuery().workbasketKeyDomainIn(new KeyDomain(wbKey, wbDomain)).list();
fail("NotAuthorizedToQueryWorkbasketException was expected ");
} catch (NotAuthorizedToQueryWorkbasketException ignored) {
// nothing to do
}
}
use of pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException in project taskana by Taskana.
the class TaskQueryImpl method single.
@Override
public TaskSummary single() {
LOGGER.debug("entry to single(), this = {}", this);
TaskSummary result = null;
try {
taskanaEngine.openConnection();
checkOpenPermissionForSpecifiedWorkbaskets();
TaskSummaryImpl taskSummaryImpl = taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this);
if (taskSummaryImpl == null) {
return null;
}
List<TaskSummaryImpl> tasks = new ArrayList<>();
tasks.add(taskSummaryImpl);
List<TaskSummary> augmentedList = taskService.augmentTaskSummariesByContainedSummaries(tasks);
result = augmentedList.get(0);
return result;
} catch (NotAuthorizedException e) {
throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from single(). Returning result {} ", result);
}
}
use of pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException in project taskana by Taskana.
the class TaskQueryImpl method list.
@Override
public List<TaskSummary> list() {
List<TaskSummary> result = new ArrayList<>();
try {
LOGGER.debug("entry to list(), this = {}", this);
taskanaEngine.openConnection();
checkOpenPermissionForSpecifiedWorkbaskets();
List<TaskSummaryImpl> tasks = new ArrayList<>();
tasks = taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("mapper returned {} resulting Objects: {} ", tasks.size(), LoggerUtils.listToString(tasks));
}
result = taskService.augmentTaskSummariesByContainedSummaries(tasks);
return result;
} catch (NotAuthorizedException e) {
throw new NotAuthorizedToQueryWorkbasketException(e.getMessage());
} finally {
taskanaEngine.returnConnection();
if (LOGGER.isDebugEnabled()) {
int numberOfResultObjects = result == null ? 0 : result.size();
LOGGER.debug("exit from list(). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
}
}
}
Aggregations