Search in sources :

Example 1 with TaskAlreadyExistException

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

the class TaskServiceImplTest method testCreateTaskThrowingAlreadyExistException.

@Test(expected = TaskAlreadyExistException.class)
public void testCreateTaskThrowingAlreadyExistException() throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, TaskAlreadyExistException, TaskNotFoundException, InvalidWorkbasketException, InvalidArgumentException {
    TaskServiceImpl cutSpy = Mockito.spy(cut);
    Classification dummyClassification = createDummyClassification();
    TaskImpl task = createUnitTestTask("12", "Task Name", "1", dummyClassification);
    doReturn(task).when(cutSpy).getTask(task.getId());
    try {
        cutSpy.createTask(task);
    } catch (TaskAlreadyExistException ex) {
        verify(taskanaEngineMock, times(1)).openConnection();
        verify(taskanaEngineMock, times(1)).returnConnection();
        verifyNoMoreInteractions(attachmentMapperMock, taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineMock, taskMapperMock, objectReferenceMapperMock, workbasketServiceMock, sqlSessionMock, classificationQueryImplMock, classificationServiceImplMock);
        throw ex;
    }
}
Also used : TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) Classification(pro.taskana.Classification) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with TaskAlreadyExistException

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

Aggregations

Classification (pro.taskana.Classification)2 TaskAlreadyExistException (pro.taskana.exceptions.TaskAlreadyExistException)2 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Workbasket (pro.taskana.Workbasket)1 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)1