Search in sources :

Example 21 with NotAuthorizedException

use of pro.taskana.exceptions.NotAuthorizedException 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 22 with NotAuthorizedException

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

Example 23 with NotAuthorizedException

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

the class DeleteWorkbasketAccTest method testCreateAndDeleteWorkbasket.

@WithAccessId(userName = "user_1_2", groupNames = { "businessadmin" })
@Test
public void testCreateAndDeleteWorkbasket() throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, InvalidWorkbasketException, WorkbasketAlreadyExistException, DomainNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    int before = workbasketService.createWorkbasketQuery().domainIn("DOMAIN_A").list().size();
    Workbasket workbasket = workbasketService.newWorkbasket("NT1234", "DOMAIN_A");
    workbasket.setName("TheUltimate");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket.setOrgLevel1("company");
    workbasket = workbasketService.createWorkbasket(workbasket);
    try {
        workbasketService.deleteWorkbasket(workbasket.getId());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) Workbasket(pro.taskana.Workbasket) WorkbasketAlreadyExistException(pro.taskana.exceptions.WorkbasketAlreadyExistException) WorkbasketInUseException(pro.taskana.exceptions.WorkbasketInUseException) DomainNotFoundException(pro.taskana.exceptions.DomainNotFoundException) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SQLException(java.sql.SQLException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 24 with NotAuthorizedException

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

the class DistributionTargetsAccTest method testDistributionTargetCallsFailWithNotAuthorizedException.

@WithAccessId(userName = "user_3_1", groupNames = { "group_1" })
@Test
public void testDistributionTargetCallsFailWithNotAuthorizedException() throws NotAuthorizedException, WorkbasketNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    String existingWb = "WBI:100000000000000000000000000000000001";
    try {
        workbasketService.getDistributionTargets(existingWb);
        assertTrue("This line of code should not be reached", false);
    } catch (NotAuthorizedException ex) {
    // nothing to do
    }
    try {
        List<String> distributionTargets = new ArrayList<>(Arrays.asList("WBI:100000000000000000000000000000000002"));
        workbasketService.setDistributionTargets(existingWb, distributionTargets);
        assertTrue("This line of code should not be reached", false);
    } catch (NotAuthorizedException ex) {
    // nothing to do
    }
    try {
        workbasketService.addDistributionTarget(existingWb, "WBI:100000000000000000000000000000000002");
        assertTrue("This line of code should not be reached", false);
    } catch (NotAuthorizedException ex) {
    // nothing to do
    }
    try {
        workbasketService.removeDistributionTarget(existingWb, "WBI:100000000000000000000000000000000002");
        assertTrue("This line of code should not be reached", false);
    } catch (NotAuthorizedException ex) {
    // nothing to do
    }
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) ArrayList(java.util.ArrayList) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 25 with NotAuthorizedException

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

the class DistributionTargetsAccTest method testSetDistributionTargets.

@WithAccessId(userName = "user_2_2", groupNames = { "group_1", "group_2", "businessadmin" })
@Test
public void testSetDistributionTargets() throws NotAuthorizedException, WorkbasketNotFoundException, InvalidWorkbasketException, SQLException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    Workbasket sourceWorkbasket = workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
    List<WorkbasketSummary> initialDistributionTargets = workbasketService.getDistributionTargets(sourceWorkbasket.getId());
    assertEquals(4, initialDistributionTargets.size());
    List<WorkbasketSummary> newDistributionTargets = workbasketService.createWorkbasketQuery().keyIn("USER_1_1", "GPK_B_KSC_1").list();
    assertEquals(2, newDistributionTargets.size());
    List<String> newDistributionTargetIds = newDistributionTargets.stream().map(t -> t.getId()).collect(Collectors.toList());
    workbasketService.setDistributionTargets(sourceWorkbasket.getId(), newDistributionTargetIds);
    List<WorkbasketSummary> changedTargets = workbasketService.getDistributionTargets(sourceWorkbasket.getId());
    assertEquals(2, changedTargets.size());
    // reset DB to original state
    resetDb(false);
}
Also used : Arrays(java.util.Arrays) WithAccessId(pro.taskana.security.WithAccessId) RunWith(org.junit.runner.RunWith) AbstractAccTest(acceptance.AbstractAccTest) Assert.assertTrue(org.junit.Assert.assertTrue) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) Test(org.junit.Test) WorkbasketService(pro.taskana.WorkbasketService) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SQLException(java.sql.SQLException) List(java.util.List) Workbasket(pro.taskana.Workbasket) JAASRunner(pro.taskana.security.JAASRunner) WorkbasketSummary(pro.taskana.WorkbasketSummary) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) Assert.fail(org.junit.Assert.fail) Assert.assertEquals(org.junit.Assert.assertEquals) WorkbasketService(pro.taskana.WorkbasketService) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)27 Test (org.junit.Test)15 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)12 ArrayList (java.util.ArrayList)11 AbstractAccTest (acceptance.AbstractAccTest)10 Workbasket (pro.taskana.Workbasket)9 WithAccessId (pro.taskana.security.WithAccessId)9 List (java.util.List)8 WorkbasketService (pro.taskana.WorkbasketService)8 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)8 TaskSummary (pro.taskana.TaskSummary)7 WorkbasketSummary (pro.taskana.WorkbasketSummary)7 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)7 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)7 SQLException (java.sql.SQLException)6 Collectors (java.util.stream.Collectors)5 ClassificationSummary (pro.taskana.ClassificationSummary)5 TaskService (pro.taskana.TaskService)5 TaskNotFoundException (pro.taskana.exceptions.TaskNotFoundException)5 Classification (pro.taskana.Classification)4