Search in sources :

Example 6 with WorkbasketNotFoundException

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

the class DeleteWorkbasketAccTest method testDeleteWorkbasketAlsoAsDistributionTarget.

@WithAccessId(userName = "user_1_1", groupNames = { "teamlead_1", "group_1", "businessadmin" })
@Test
public void testDeleteWorkbasketAlsoAsDistributionTarget() throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException {
    Workbasket wb = workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
    int distTargets = workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000001").size();
    // WB deleted
    workbasketService.deleteWorkbasket(wb.getId());
    try {
        workbasketService.getWorkbasket("GPK_KSC_1", "DOMAIN_A");
        fail("There should be no result for a deleted Workbasket.");
    } catch (WorkbasketNotFoundException e) {
    // Workbasket is deleted
    }
    int newDistTargets = workbasketService.getDistributionTargets("WBI:100000000000000000000000000000000001").size();
    assertThat(newDistTargets, equalTo(3));
    assertTrue(newDistTargets < distTargets);
}
Also used : WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) Workbasket(pro.taskana.Workbasket) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 7 with WorkbasketNotFoundException

use of pro.taskana.exceptions.WorkbasketNotFoundException 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 8 with WorkbasketNotFoundException

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

the class DeleteWorkbasketAccTest method testDeleteWorkbasket.

@WithAccessId(userName = "teamlead_2", groupNames = { "businessadmin" })
@Test
public void testDeleteWorkbasket() throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException {
    Workbasket wb = workbasketService.getWorkbasket("TEAMLEAD_2", "DOMAIN_A");
    workbasketService.deleteWorkbasket(wb.getId());
    try {
        workbasketService.getWorkbasket("TEAMLEAD_2", "DOMAIN_A");
        fail("There should be no result for a deleted Workbasket.");
    } catch (WorkbasketNotFoundException e) {
    // Workbasket is deleted
    }
}
Also used : WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) Workbasket(pro.taskana.Workbasket) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 9 with WorkbasketNotFoundException

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

Example 10 with WorkbasketNotFoundException

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

the class WorkbasketServiceImpl method getWorkbasket.

@Override
public Workbasket getWorkbasket(String workbasketKey, String domain) throws WorkbasketNotFoundException, NotAuthorizedException {
    LOGGER.debug("entry to getWorkbasketByKey(workbasketKey = {})", workbasketKey);
    Workbasket result = null;
    try {
        taskanaEngine.openConnection();
        result = workbasketMapper.findByKeyAndDomain(workbasketKey, domain);
        if (result == null) {
            LOGGER.error("Method getWorkbasketByKey() didn't find workbasket with key {}. Throwing WorkbasketNotFoundException", workbasketKey);
            throw new WorkbasketNotFoundException(workbasketKey, domain, "Workbasket with key " + workbasketKey + " and domain " + domain + " was not found.");
        }
        if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
            this.checkAuthorization(workbasketKey, domain, WorkbasketPermission.READ);
        }
        return result;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from getWorkbasket(workbasketId). Returning result {} ", result);
    }
}
Also used : WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) Workbasket(pro.taskana.Workbasket)

Aggregations

WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)10 Workbasket (pro.taskana.Workbasket)8 Test (org.junit.Test)7 AbstractAccTest (acceptance.AbstractAccTest)5 WithAccessId (pro.taskana.security.WithAccessId)5 ArrayList (java.util.ArrayList)4 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)4 WorkbasketService (pro.taskana.WorkbasketService)3 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)3 SQLException (java.sql.SQLException)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 WorkbasketSummary (pro.taskana.WorkbasketSummary)2 DomainNotFoundException (pro.taskana.exceptions.DomainNotFoundException)2 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)2 WorkbasketAlreadyExistException (pro.taskana.exceptions.WorkbasketAlreadyExistException)2 WorkbasketDefinition (pro.taskana.rest.resource.WorkbasketDefinition)2 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1