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;
}
}
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);
}
}
Aggregations