Search in sources :

Example 46 with Workbasket

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

the class TaskServiceImpl method createTask.

@Override
public Task createTask(Task taskToCreate) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidArgumentException {
    LOGGER.debug("entry to createTask(task = {})", taskToCreate);
    TaskImpl task = (TaskImpl) taskToCreate;
    try {
        taskanaEngine.openConnection();
        if (task.getId() != "" && task.getId() != null) {
            throw new TaskAlreadyExistException(task.getId());
        } else {
            LOGGER.debug("Task {} cannot be be found, so it can be created.", task.getId());
            Workbasket workbasket;
            if (task.getWorkbasketSummary().getId() != null) {
                workbasket = workbasketService.getWorkbasket(task.getWorkbasketSummary().getId());
            } else if (task.getWorkbasketKey() != null) {
                workbasket = workbasketService.getWorkbasket(task.getWorkbasketKey(), task.getDomain());
            } else {
                throw new InvalidArgumentException("Cannot create a task outside a workbasket");
            }
            task.setWorkbasketSummary(workbasket.asSummary());
            task.setDomain(workbasket.getDomain());
            workbasketService.checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.APPEND);
            String classificationKey = task.getClassificationKey();
            if (classificationKey == null || classificationKey.length() == 0) {
                throw new InvalidArgumentException("classificationKey of task must not be empty");
            }
            Classification classification = this.classificationService.getClassification(classificationKey, workbasket.getDomain());
            task.setClassificationSummary(classification.asSummary());
            validateObjectReference(task.getPrimaryObjRef(), "primary ObjectReference", "Task");
            PrioDurationHolder prioDurationFromAttachments = handleAttachments(task);
            standardSettings(task, classification, prioDurationFromAttachments);
            this.taskMapper.insert(task);
            LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
        }
        return task;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from createTask(task = {})", task);
    }
}
Also used : TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) Classification(pro.taskana.Classification) Workbasket(pro.taskana.Workbasket)

Example 47 with Workbasket

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

the class TaskServiceImpl method transfer.

@Override
public Task transfer(String taskId, String destinationWorkbasketId) throws TaskNotFoundException, WorkbasketNotFoundException, NotAuthorizedException, InvalidWorkbasketException {
    LOGGER.debug("entry to transfer(taskId = {}, destinationWorkbasketId = {})", taskId, destinationWorkbasketId);
    TaskImpl task = null;
    try {
        taskanaEngine.openConnection();
        task = (TaskImpl) getTask(taskId);
        // transfer requires TRANSFER in source and APPEND on destination workbasket
        workbasketService.checkAuthorization(destinationWorkbasketId, WorkbasketPermission.APPEND);
        workbasketService.checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.TRANSFER);
        Workbasket destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketId);
        // reset read flag and set transferred flag
        task.setRead(false);
        task.setTransferred(true);
        // transfer task from source to destination workbasket
        task.setWorkbasketSummary(destinationWorkbasket.asSummary());
        task.setModified(Instant.now());
        task.setState(TaskState.READY);
        task.setOwner(null);
        taskMapper.update(task);
        LOGGER.debug("Method transfer() transferred Task '{}' to destination workbasket {}", taskId, destinationWorkbasketId);
        return task;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from transfer(). Returning result {} ", task);
    }
}
Also used : Workbasket(pro.taskana.Workbasket)

Example 48 with Workbasket

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

the class DeleteWorkbasketAccTest method testDeleteWorkbasketNotAuthorized.

@WithAccessId(userName = "elena")
@Test(expected = NotAuthorizedException.class)
public void testDeleteWorkbasketNotAuthorized() throws WorkbasketNotFoundException, NotAuthorizedException, WorkbasketInUseException, InvalidArgumentException {
    Workbasket wb = workbasketService.getWorkbasket("TEAMLEAD_2", "DOMAIN_A");
    workbasketService.deleteWorkbasket(wb.getId());
    workbasketService.getWorkbasket("TEAMLEAD_2", "DOMAIN_A");
    fail("NotAuthorizedException was expected.");
}
Also used : Workbasket(pro.taskana.Workbasket) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 49 with Workbasket

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

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

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