Remove custom synchronization in Task and change order of wb-invocations
This commit is contained in:
parent
62f957d467
commit
ccfefe0365
|
@ -105,8 +105,8 @@ public class TaskServiceImpl implements TaskService {
|
||||||
LOGGER.debug("entry to createTask(task = {})", task);
|
LOGGER.debug("entry to createTask(task = {})", task);
|
||||||
try {
|
try {
|
||||||
taskanaEngineImpl.openConnection();
|
taskanaEngineImpl.openConnection();
|
||||||
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
|
||||||
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasket(task.getWorkbasketId());
|
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasket(task.getWorkbasketId());
|
||||||
|
taskanaEngine.getWorkbasketService().checkAuthorization(task.getWorkbasketId(), WorkbasketAuthorization.APPEND);
|
||||||
|
|
||||||
Classification classification = task.getClassification();
|
Classification classification = task.getClassification();
|
||||||
if (classification == null) {
|
if (classification == null) {
|
||||||
|
@ -338,79 +338,5 @@ public class TaskServiceImpl implements TaskService {
|
||||||
}
|
}
|
||||||
task.setPrimaryObjRef(objectReference);
|
task.setPrimaryObjRef(objectReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
//guarantees redundancy of customers and customAttributes
|
|
||||||
this.checkCustomAttributes(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkCustomAttributes(Task task) {
|
|
||||||
List<String> customList = new ArrayList<>();
|
|
||||||
if (task.getCustom1() != null) {
|
|
||||||
customList.add(task.getCustom1());
|
|
||||||
}
|
|
||||||
if (task.getCustom2() != null) {
|
|
||||||
customList.add(task.getCustom2());
|
|
||||||
}
|
|
||||||
if (task.getCustom3() != null) {
|
|
||||||
customList.add(task.getCustom3());
|
|
||||||
}
|
|
||||||
if (task.getCustom4() != null) {
|
|
||||||
customList.add(task.getCustom4());
|
|
||||||
}
|
|
||||||
if (task.getCustom5() != null) {
|
|
||||||
customList.add(task.getCustom5());
|
|
||||||
}
|
|
||||||
if (task.getCustom6() != null) {
|
|
||||||
customList.add(task.getCustom6());
|
|
||||||
}
|
|
||||||
if (task.getCustom7() != null) {
|
|
||||||
customList.add(task.getCustom7());
|
|
||||||
}
|
|
||||||
if (task.getCustom8() != null) {
|
|
||||||
customList.add(task.getCustom8());
|
|
||||||
}
|
|
||||||
if (task.getCustom9() != null) {
|
|
||||||
customList.add(task.getCustom9());
|
|
||||||
}
|
|
||||||
if (task.getCustom10() != null) {
|
|
||||||
customList.add(task.getCustom10());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task.getCustomAttributes() != null) {
|
|
||||||
for (String custom : task.getCustomAttributes().keySet()) {
|
|
||||||
if (!customList.isEmpty() && customList.contains(custom)) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!customList.isEmpty()) {
|
|
||||||
for (String custom : customList) {
|
|
||||||
if (!task.getCustomAttributes().containsKey(custom)) {
|
|
||||||
task.getCustomAttributes().put(custom, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,8 @@ public class TaskServiceImplTest {
|
||||||
cut.createTask(task);
|
cut.createTask(task);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
verify(taskanaEngineMock, times(2)).getWorkbasketService();
|
||||||
|
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
|
||||||
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
||||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
|
@ -274,7 +275,7 @@ public class TaskServiceImplTest {
|
||||||
@Test(expected = WorkbasketNotFoundException.class)
|
@Test(expected = WorkbasketNotFoundException.class)
|
||||||
public void testCreateThrowsWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
public void testCreateThrowsWorkbasketNotFoundException() throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||||
try {
|
try {
|
||||||
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).checkAuthorization(any(), any());
|
Mockito.doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any());
|
||||||
Task task = new Task();
|
Task task = new Task();
|
||||||
task.setWorkbasketId("1");
|
task.setWorkbasketId("1");
|
||||||
|
|
||||||
|
@ -282,7 +283,7 @@ public class TaskServiceImplTest {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
verify(taskanaEngineImpl, times(1)).openConnection();
|
verify(taskanaEngineImpl, times(1)).openConnection();
|
||||||
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
verify(taskanaEngineMock, times(1)).getWorkbasketService();
|
||||||
verify(workbasketServiceMock, times(1)).checkAuthorization(any(), any());
|
verify(workbasketServiceMock, times(1)).getWorkbasket(any());
|
||||||
verify(taskanaEngineImpl, times(1)).returnConnection();
|
verify(taskanaEngineImpl, times(1)).returnConnection();
|
||||||
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
verifyNoMoreInteractions(taskanaEngineConfigurationMock, taskanaEngineMock, taskanaEngineImpl,
|
||||||
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
|
taskMapperMock, objectReferenceMapperMock, workbasketServiceMock,
|
||||||
|
|
|
@ -23,9 +23,7 @@ import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT.
|
* Integration Test for TaskServiceImpl transactions with connection management mode EXPLICIT.
|
||||||
|
@ -132,7 +130,7 @@ public class TaskServiceImplIntExplicitTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTaskWithCustomsAndPlanned() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
public void testCreateTaskWithPlannedAndName() throws SQLException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException {
|
||||||
Connection connection = dataSource.getConnection();
|
Connection connection = dataSource.getConnection();
|
||||||
taskanaEngineImpl.setConnection(connection);
|
taskanaEngineImpl.setConnection(connection);
|
||||||
|
|
||||||
|
@ -161,27 +159,19 @@ public class TaskServiceImplIntExplicitTest {
|
||||||
Assert.assertNotEquals(test.getPlanned(), test.getCreated());
|
Assert.assertNotEquals(test.getPlanned(), test.getCreated());
|
||||||
Assert.assertNotNull(test.getDue());
|
Assert.assertNotNull(test.getDue());
|
||||||
|
|
||||||
Map<String, Object> customs = new HashMap<String, Object>();
|
|
||||||
customs.put("Daimler", "Tons of money. And cars. And gold.");
|
|
||||||
customs.put("Audi", 2);
|
|
||||||
|
|
||||||
|
|
||||||
Task test2 = new Task();
|
Task test2 = new Task();
|
||||||
test2.setWorkbasketId(test.getWorkbasketId());
|
test2.setWorkbasketId(test.getWorkbasketId());
|
||||||
test2.setClassification(classification);
|
test2.setClassification(classification);
|
||||||
test2.setPrimaryObjRef(objectReference);
|
test2.setPrimaryObjRef(objectReference);
|
||||||
test2.setName("Name2");
|
|
||||||
test2.setDescription("desc");
|
test2.setDescription("desc");
|
||||||
test2.setCustomAttributes(customs);
|
|
||||||
test2.setCustom1("Daimler");
|
|
||||||
test2.setCustom5("BMW");
|
|
||||||
taskServiceImpl.createTask(test2);
|
taskServiceImpl.createTask(test2);
|
||||||
|
|
||||||
Assert.assertEquals(test2.getPlanned(), test2.getCreated());
|
Assert.assertEquals(test2.getPlanned(), test2.getCreated());
|
||||||
|
Assert.assertTrue(test2.getName().equals(classification.getName()));
|
||||||
|
|
||||||
Assert.assertEquals(2 + 1, test2.getCustomAttributes().size());
|
|
||||||
Assert.assertEquals(test.getClassification().getId(), test2.getClassification().getId());
|
Assert.assertEquals(test.getClassification().getId(), test2.getClassification().getId());
|
||||||
Assert.assertTrue(test.getDue().after(test2.getPlanned()));
|
Assert.assertTrue(test.getDue().after(test2.getDue()));
|
||||||
|
Assert.assertFalse(test.getName().equals(test2.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = WorkbasketNotFoundException.class)
|
@Test(expected = WorkbasketNotFoundException.class)
|
||||||
|
|
Loading…
Reference in New Issue