Search in sources :

Example 56 with Workbasket

use of pro.taskana.Workbasket in project taskana by Taskana.

the class CreateWorkbasketAccTest method testCreateWorkbasketWithMissingRequiredField.

@WithAccessId(userName = "dummy", groupNames = { "businessadmin" })
@Test
public void testCreateWorkbasketWithMissingRequiredField() throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketAlreadyExistException, DomainNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    Workbasket workbasket = workbasketService.newWorkbasket(null, "novatec");
    workbasket.setName("Megabasket");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket.setOrgLevel1("company");
    try {
        // missing key
        workbasketService.createWorkbasket(workbasket);
        fail("InvalidWorkbasketException was expected");
    } catch (InvalidWorkbasketException e) {
    }
    workbasket = workbasketService.newWorkbasket("key", "novatec");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket.setOrgLevel1("company");
    try {
        // missing name
        workbasketService.createWorkbasket(workbasket);
        fail("InvalidWorkbasketException was expected");
    } catch (InvalidWorkbasketException e) {
    }
    workbasket = workbasketService.newWorkbasket("key", "novatec");
    workbasket.setName("Megabasket");
    workbasket.setOrgLevel1("company");
    try {
        // missing type
        workbasketService.createWorkbasket(workbasket);
        fail("InvalidWorkbasketException was expected");
    } catch (InvalidWorkbasketException e) {
    }
    workbasket = workbasketService.newWorkbasket("key", null);
    workbasket.setName("Megabasket");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket.setOrgLevel1("company");
    try {
        // missing domain
        workbasketService.createWorkbasket(workbasket);
        fail("InvalidWorkbasketException was expected");
    } catch (InvalidWorkbasketException e) {
    }
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) Workbasket(pro.taskana.Workbasket) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 57 with Workbasket

use of pro.taskana.Workbasket in project taskana by Taskana.

the class WorkbasketServiceImpl method getDistributionTargets.

@Override
public List<WorkbasketSummary> getDistributionTargets(String workbasketKey, String domain) throws NotAuthorizedException, WorkbasketNotFoundException {
    LOGGER.debug("entry to getDistributionTargets(workbasketKey = {}, domain = {})", workbasketKey, domain);
    List<WorkbasketSummary> result = new ArrayList<>();
    try {
        taskanaEngine.openConnection();
        // check that source workbasket exists
        Workbasket workbasket = getWorkbasket(workbasketKey, domain);
        if (!taskanaEngine.isUserInRole(TaskanaRole.ADMIN, TaskanaRole.BUSINESS_ADMIN)) {
            checkAuthorization(workbasket.getId(), WorkbasketPermission.READ);
        }
        List<WorkbasketSummaryImpl> distributionTargets = workbasketMapper.findByDistributionTargets(workbasket.getId());
        result.addAll(distributionTargets);
        return result;
    } finally {
        taskanaEngine.returnConnection();
        if (LOGGER.isDebugEnabled()) {
            int numberOfResultObjects = result.size();
            LOGGER.debug("exit from getDistributionTargets(workbasketId). Returning {} resulting Objects: {} ", numberOfResultObjects, LoggerUtils.listToString(result));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Workbasket(pro.taskana.Workbasket) WorkbasketSummary(pro.taskana.WorkbasketSummary)

Example 58 with Workbasket

use of pro.taskana.Workbasket 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);
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketInUseException(pro.taskana.exceptions.WorkbasketInUseException) Workbasket(pro.taskana.Workbasket)

Example 59 with Workbasket

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

Example 60 with Workbasket

use of pro.taskana.Workbasket in project taskana by Taskana.

the class DistributionTargetSerializer method serialize.

@Override
public void serialize(List<Workbasket> workbaskets, JsonGenerator gen, SerializerProvider provider) throws IOException {
    List<String> ids = new ArrayList<>();
    for (Workbasket item : workbaskets) {
        ids.add(item.getId());
    }
    gen.writeObject(ids);
}
Also used : ArrayList(java.util.ArrayList) Workbasket(pro.taskana.Workbasket)

Aggregations

Workbasket (pro.taskana.Workbasket)62 Test (org.junit.Test)47 WithAccessId (pro.taskana.security.WithAccessId)23 AbstractAccTest (acceptance.AbstractAccTest)18 Task (pro.taskana.Task)18 Classification (pro.taskana.Classification)17 WorkbasketService (pro.taskana.WorkbasketService)13 ArrayList (java.util.ArrayList)11 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)10 WorkbasketSummary (pro.taskana.WorkbasketSummary)9 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)9 WorkbasketNotFoundException (pro.taskana.exceptions.WorkbasketNotFoundException)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)7 Attachment (pro.taskana.Attachment)6 InvalidWorkbasketException (pro.taskana.exceptions.InvalidWorkbasketException)6 Instant (java.time.Instant)5 Transactional (org.springframework.transaction.annotation.Transactional)5 WorkbasketResource (pro.taskana.rest.resource.WorkbasketResource)5 Connection (java.sql.Connection)4