From 650fcfde4da4c6ce23a13966f16139b459721b42 Mon Sep 17 00:00:00 2001 From: BVier <26220150+BVier@users.noreply.github.com> Date: Wed, 29 Nov 2017 16:02:08 +0100 Subject: [PATCH] TSK15: Throw ClassificationNotFoundError and insert createManualTask --- .../pro/taskana/impl/TaskServiceImpl.java | 78 +++++++++++++++++++ .../pro/taskana/impl/TaskServiceImplTest.java | 47 +++++++++++ 2 files changed, 125 insertions(+) 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 3195f8480..339316fca 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 @@ -263,6 +263,84 @@ public class TaskServiceImpl implements TaskService { taskanaEngineImpl.returnConnection(); } return (resultList == null) ? new ArrayList<>() : resultList; + } + + private void standardSettings(Task task) { + Timestamp now = new Timestamp(System.currentTimeMillis()); + task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK)); + task.setState(TaskState.READY); + task.setCreated(now); + task.setModified(now); + task.setRead(false); + task.setTransferred(false); + + if (task.getPlanned() == null) { + task.setPlanned(now); + } + + + // insert Classification specifications if Classification is given. + Classification classification = task.getClassification(); + if (classification != null) { + if (classification.getServiceLevel() != null) { + Duration serviceLevel = Duration.parse(task.getClassification().getServiceLevel()); + LocalDateTime due = task.getPlanned().toLocalDateTime().plus(serviceLevel); + task.setDue(Timestamp.valueOf(due)); + } + + if (task.getName() == null) { + task.setName(classification.getName()); + } + + if (task.getDescription() == null) { + task.setDescription(classification.getDescription()); + } + + if (task.getPriority() == 0) { + task.setPriority(classification.getPriority()); + } + } + + // insert ObjectReference if needed. + if (task.getPrimaryObjRef() != null) { + ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef()); + if (objectReference == null) { + objectReference = task.getPrimaryObjRef(); + objectReference.setId(IdGenerator.generateWithPrefix(ID_PREFIX_OBJECTR_EFERENCE)); + this.objectReferenceMapper.insert(objectReference); + } + task.setPrimaryObjRef(objectReference); + } + } + + private void setCustomers(Task task) { + if (task.getCustomAttributes() != null) { + for (String custom : task.getCustomAttributes().keySet()) { + if (task.getCustom1() == null) { + task.setCustom1(custom); + } else if (task.getCustom2() == null) { + task.setCustom2(custom); + } else if (task.getCustom3() == null) { + task.setCustom3(custom); + } else if (task.getCustom4() == null) { + task.setCustom4(custom); + } else if (task.getCustom5() == null) { + task.setCustom5(custom); + } else if (task.getCustom6() == null) { + task.setCustom6(custom); + } else if (task.getCustom7() == null) { + task.setCustom7(custom); + } else if (task.getCustom8() == null) { + task.setCustom8(custom); + } else if (task.getCustom9() == null) { + task.setCustom9(custom); + } else if (task.getCustom10() == null) { + task.setCustom10(custom); + } else { + break; + } + } + } } private void standardSettings(Task task) { diff --git a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java index 9a2f8c7b1..c4edda8a1 100644 --- a/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java +++ b/lib/taskana-core/src/test/java/pro/taskana/impl/TaskServiceImplTest.java @@ -171,6 +171,53 @@ public class TaskServiceImplTest { assertThat(actualTask.getPrimaryObjRef(), equalTo(expectedObjectReference)); } + @Test + public void testCreateManualTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { + ObjectReference expectedObjectReference = new ObjectReference(); + expectedObjectReference.setId("1"); + expectedObjectReference.setType("DUMMY"); + + Workbasket workbasket = new Workbasket(); + Classification classification = new Classification(); + classification.setName("Name"); + classification.setCategory("MANUAL"); + + Mockito.doReturn(classification).when(classificationServiceMock).getClassification(any(), any()); + Mockito.doNothing().when(taskMapperMock).insert(any()); + Mockito.doNothing().when(objectReferenceMapperMock).insert(any()); + + Task manualTask = cut.createManualTask("workbasketId", "classification", "domain", null, null, "simply awesome task", expectedObjectReference, null); + + Task manualTask2 = cut.createManualTask("workbasketId", "classification", "domain", Timestamp.valueOf(LocalDateTime.now().minusHours(1)), "Task2", "simply awesome task", expectedObjectReference, null); + + verify(taskanaEngineImpl, times(2)).openConnection(); + verify(taskanaEngineMock, times(2 + 2)).getWorkbasketService(); + verify(taskanaEngineMock, times(2)).getClassificationService(); + verify(workbasketServiceMock, times(2)).checkAuthorization(any(), any()); + verify(workbasketServiceMock, times(2)).getWorkbasket(any()); + verify(objectReferenceMapperMock, times(2)).findByObjectReference(any()); + verify(objectReferenceMapperMock, times(2)).insert(any()); + verify(taskMapperMock, times(1)).insert(manualTask); + verify(taskMapperMock, times(1)).insert(manualTask2); + verify(taskanaEngineImpl, times(2)).returnConnection(); + verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl, + taskMapperMock, objectReferenceMapperMock, workbasketServiceMock); + + assertNull(manualTask.getOwner()); + assertNotNull(manualTask.getCreated()); + assertNotNull(manualTask.getModified()); + assertNull(manualTask.getCompleted()); + assertNull(manualTask.getDue()); + assertThat(manualTask.getWorkbasketId(), equalTo(manualTask2.getWorkbasketId())); + assertThat(manualTask.getName(), equalTo(classification.getName())); + assertThat(manualTask.getState(), equalTo(TaskState.READY)); + assertThat(manualTask.getPrimaryObjRef(), equalTo(expectedObjectReference)); + assertThat(manualTask.getName(), not(manualTask2.getName())); + assertThat(manualTask.getPlanned(), not(manualTask2.getPlanned())); + assertThat(manualTask2.getPlanned(), not(manualTask2.getCreated())); + + } + @Test public void testCreateManualTask() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException { ObjectReference expectedObjectReference = new ObjectReference();