Search in sources :

Example 1 with NotAuthorizedToQueryWorkbasketException

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));
        }
    }
}
Also used : TaskSummary(pro.taskana.TaskSummary) ArrayList(java.util.ArrayList) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) TaskanaRuntimeException(pro.taskana.exceptions.TaskanaRuntimeException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException)

Example 2 with NotAuthorizedToQueryWorkbasketException

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()");
    }
}
Also used : ClassificationInUseException(pro.taskana.exceptions.ClassificationInUseException) SystemException(pro.taskana.exceptions.SystemException) Classification(pro.taskana.Classification) TaskSummary(pro.taskana.TaskSummary) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) AttachmentMapper(pro.taskana.mappings.AttachmentMapper)

Example 3 with NotAuthorizedToQueryWorkbasketException

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
    }
}
Also used : Task(pro.taskana.Task) WorkbasketService(pro.taskana.WorkbasketService) TaskService(pro.taskana.TaskService) WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) TaskSummary(pro.taskana.TaskSummary) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) KeyDomain(pro.taskana.KeyDomain) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 4 with NotAuthorizedToQueryWorkbasketException

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);
    }
}
Also used : TaskSummary(pro.taskana.TaskSummary) ArrayList(java.util.ArrayList) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException)

Example 5 with NotAuthorizedToQueryWorkbasketException

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));
        }
    }
}
Also used : TaskSummary(pro.taskana.TaskSummary) ArrayList(java.util.ArrayList) NotAuthorizedToQueryWorkbasketException(pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException)

Aggregations

TaskSummary (pro.taskana.TaskSummary)5 NotAuthorizedToQueryWorkbasketException (pro.taskana.exceptions.NotAuthorizedToQueryWorkbasketException)5 ArrayList (java.util.ArrayList)3 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)3 AbstractAccTest (acceptance.AbstractAccTest)1 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)1 RowBounds (org.apache.ibatis.session.RowBounds)1 Test (org.junit.Test)1 Classification (pro.taskana.Classification)1 KeyDomain (pro.taskana.KeyDomain)1 Task (pro.taskana.Task)1 TaskService (pro.taskana.TaskService)1 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)1 WorkbasketService (pro.taskana.WorkbasketService)1 ClassificationInUseException (pro.taskana.exceptions.ClassificationInUseException)1 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)1 SystemException (pro.taskana.exceptions.SystemException)1 TaskanaRuntimeException (pro.taskana.exceptions.TaskanaRuntimeException)1 AttachmentMapper (pro.taskana.mappings.AttachmentMapper)1 WithAccessId (pro.taskana.security.WithAccessId)1