diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java index 068c25c34..64680d32c 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/TaskServiceImpl.java @@ -281,36 +281,38 @@ public class TaskServiceImpl implements TaskService { throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException { LOGGER.debug("entry to createTask(task = {})", taskToCreate); + TaskImpl task = (TaskImpl) taskToCreate; try { taskanaEngine.openConnection(); - TaskImpl task = (TaskImpl) taskToCreate; if (task.getId() != "" && task.getId() != null) { - throw new TaskAlreadyExistException(taskToCreate.getId()); + throw new TaskAlreadyExistException(task.getId()); } else { - LOGGER.debug("Task {} cannot be be found, so it can be created.", taskToCreate.getId()); + LOGGER.debug("Task {} cannot be be found, so it can be created.", task.getId()); Workbasket workbasket; - if (taskToCreate.getWorkbasketSummary().getId() != null) { - workbasket = workbasketService.getWorkbasket(taskToCreate.getWorkbasketSummary().getId()); - } else if (taskToCreate.getWorkbasketKey() != null) { + 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); - task.setDomain(workbasket.getDomain()); standardSettings(task, classification, prioDurationFromAttachments); this.taskMapper.insert(task); LOGGER.debug("Method createTask() created Task '{}'.", task.getId()); @@ -318,7 +320,7 @@ public class TaskServiceImpl implements TaskService { return task; } finally { taskanaEngine.returnConnection(); - LOGGER.debug("exit from createTask(task = {})"); + LOGGER.debug("exit from createTask(task = {})", task); } } @@ -547,19 +549,18 @@ public class TaskServiceImpl implements TaskService { public Task setTaskRead(String taskId, boolean isRead) throws TaskNotFoundException { LOGGER.debug("entry to setTaskRead(taskId = {}, isRead = {})", taskId, isRead); - Task result = null; + TaskImpl task = null; try { taskanaEngine.openConnection(); - TaskImpl task = (TaskImpl) getTask(taskId); + task = (TaskImpl) getTask(taskId); task.setRead(true); task.setModified(Instant.now()); taskMapper.update(task); - result = getTask(taskId); - LOGGER.debug("Method setTaskRead() set read property of Task '{}' to {} ", result, isRead); - return result; + LOGGER.debug("Method setTaskRead() set read property of Task '{}' to {} ", task, isRead); + return task; } finally { taskanaEngine.returnConnection(); - LOGGER.debug("exit from setTaskRead(taskId, isRead). Returning result {} ", result); + LOGGER.debug("exit from setTaskRead(taskId, isRead). Returning result {} ", task); } } diff --git a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketServiceImpl.java index 715bdb1d7..f487106a7 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/impl/WorkbasketServiceImpl.java @@ -133,7 +133,6 @@ public class WorkbasketServiceImpl implements WorkbasketService { throws InvalidWorkbasketException, NotAuthorizedException { LOGGER.debug("entry to createtWorkbasket(workbasket)", newWorkbasket); taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN); - Workbasket result = null; WorkbasketImpl workbasket = (WorkbasketImpl) newWorkbasket; try { taskanaEngine.openConnection(); @@ -147,11 +146,10 @@ public class WorkbasketServiceImpl implements WorkbasketService { workbasketMapper.insert(workbasket); LOGGER.debug("Method createWorkbasket() created Workbasket '{}'", workbasket); - result = workbasketMapper.findById(workbasket.getId()); - return result; + return workbasket; } finally { taskanaEngine.returnConnection(); - LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", result); + LOGGER.debug("exit from createWorkbasket(workbasket). Returning result {} ", workbasket); } } @@ -161,18 +159,16 @@ public class WorkbasketServiceImpl implements WorkbasketService { LOGGER.debug("entry to updateWorkbasket(workbasket)", workbasketToUpdate); taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN); - Workbasket result = null; WorkbasketImpl workbasket = (WorkbasketImpl) workbasketToUpdate; try { taskanaEngine.openConnection(); workbasket.setModified(Instant.now()); workbasketMapper.update(workbasket); LOGGER.debug("Method updateWorkbasket() updated workbasket '{}'", workbasket.getId()); - result = workbasketMapper.findById(workbasket.getId()); - return result; + return workbasket; } finally { taskanaEngine.returnConnection(); - LOGGER.debug("exit from updateWorkbasket(). Returning result {} ", result); + LOGGER.debug("exit from updateWorkbasket(). Returning result {} ", workbasket); } } diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java index 4ea87a34c..0ad024485 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/WorkbasketServiceImplTest.java @@ -335,7 +335,7 @@ public class WorkbasketServiceImplTest { verify(taskanaEngineImplMock, times(2)).getConfiguration(); verify(taskanaEngineConfigurationMock, times(2)).isSecurityEnabled(); verify(workbasketMapperMock, times(1)).insert(expectedWb); - verify(workbasketMapperMock, times(4)).findById(expectedWb.getId()); + verify(workbasketMapperMock, times(3)).findById(expectedWb.getId()); verify(workbasketMapperMock, times(1)).update(any()); verify(taskanaEngineImplMock, times(5)).returnConnection(); verify(taskanaEngineImplMock, times(2)).checkRoleMembership(any()); @@ -371,7 +371,7 @@ public class WorkbasketServiceImplTest { verify(cutSpy, times(distTargetAmount + 1)).getWorkbasket(any()); verify(distributionTargetMapperMock, times(1)).deleteAllDistributionTargetsBySourceId(any()); verify(distributionTargetMapperMock, times(distTargetAmount)).insert(any(), any()); - verify(workbasketMapperMock, times(4)).findById(any()); + verify(workbasketMapperMock, times(1)).findById(any()); verify(workbasketMapperMock, times(1)).update(any()); verify(taskanaEngineImplMock, times(5)).returnConnection(); verify(taskanaEngineImplMock, times(4)).checkRoleMembership(any()); @@ -401,7 +401,7 @@ public class WorkbasketServiceImplTest { } catch (WorkbasketNotFoundException e) { verify(taskanaEngineImplMock, times(3)).openConnection(); verify(workbasketMapperMock, times(1)).insert(expectedWb); - verify(workbasketMapperMock, times(2)).findById(any()); + verify(workbasketMapperMock, times(1)).findById(any()); verify(cutSpy, times(1)).getWorkbasket(any()); verify(taskanaEngineImplMock, times(3)).returnConnection(); verify(taskanaEngineImplMock, times(2)).checkRoleMembership(any());