TSK-1177 update Planned of Task if only Due was changed
This commit is contained in:
parent
48595686de
commit
520eb4e295
|
@ -257,7 +257,7 @@ class ServiceLevelHandler {
|
|||
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
|
||||
} else if (oldTaskImpl.getDue().equals(newTaskImpl.getDue())
|
||||
&& newTaskImpl.getPlanned() != null) {
|
||||
// case 2: planned was changed
|
||||
// case 2: planned was changed and due not
|
||||
newTaskImpl.setDue(
|
||||
converter.addWorkingDaysToInstant(
|
||||
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
|
||||
|
@ -265,13 +265,14 @@ class ServiceLevelHandler {
|
|||
newTaskImpl.setPlanned(getFirstFollowingWorkingDay(newTaskImpl.getPlanned()));
|
||||
}
|
||||
} else {
|
||||
updatePlannedDueOnTaskUpdateWhenDueWasChanged(newTaskImpl, durationPrioHolder);
|
||||
updatePlannedDueOnTaskUpdateWhenDueWasChanged(newTaskImpl, oldTaskImpl, durationPrioHolder);
|
||||
}
|
||||
return newTaskImpl;
|
||||
}
|
||||
|
||||
private void updatePlannedDueOnTaskUpdateWhenDueWasChanged(TaskImpl newTaskImpl,
|
||||
DurationPrioHolder durationPrioHolder) throws InvalidArgumentException {
|
||||
private void updatePlannedDueOnTaskUpdateWhenDueWasChanged(
|
||||
TaskImpl newTaskImpl, TaskImpl oldTaskImpl, DurationPrioHolder durationPrioHolder)
|
||||
throws InvalidArgumentException {
|
||||
if (newTaskImpl.getDue() == null) {
|
||||
newTaskImpl.setDue(
|
||||
converter.addWorkingDaysToInstant(
|
||||
|
@ -283,7 +284,10 @@ class ServiceLevelHandler {
|
|||
Instant planned =
|
||||
(converter.subtractWorkingDaysFromInstant(
|
||||
newTaskImpl.getDue(), durationPrioHolder.getDuration()));
|
||||
ensureServiceLevelIsNotViolated(newTaskImpl, durationPrioHolder.getDuration(), planned);
|
||||
if (newTaskImpl.getPlanned() != null
|
||||
&& !newTaskImpl.getPlanned().equals(oldTaskImpl.getPlanned())) {
|
||||
ensureServiceLevelIsNotViolated(newTaskImpl, durationPrioHolder.getDuration(), planned);
|
||||
}
|
||||
newTaskImpl.setPlanned(planned);
|
||||
if (!converter.isWorkingDay(0, newTaskImpl.getDue())) {
|
||||
newTaskImpl.setDue(getFirstPreceedingWorkingDay(newTaskImpl.getDue()));
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.time.temporal.ChronoUnit;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
|
@ -45,7 +44,8 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "user_3_2",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedWithDuplicatesSucceeds() throws NotAuthorizedException, TaskNotFoundException {
|
||||
void should_SetPlanned_when_setPlannedRequestContainsDuplicateTaskIds()
|
||||
throws NotAuthorizedException, TaskNotFoundException {
|
||||
|
||||
// This test works with the following tasks (w/o attachments) and classifications
|
||||
//
|
||||
|
@ -83,7 +83,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "user_3_2",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedOnTasksWithDuplicatesAndNotExistingSucceeds()
|
||||
void should_setPlanned_when_RequestContainsDuplicatesAndNotExistingTaskIds()
|
||||
throws NotAuthorizedException, TaskNotFoundException {
|
||||
|
||||
String tkId1 = "TKI:000000000000000000000000000000000058";
|
||||
|
@ -112,7 +112,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedForTasksWithAttachmentsSucceeds()
|
||||
void should_SetPlanned_when_RequestContainsRasksWithAttachments()
|
||||
throws NotAuthorizedException, TaskNotFoundException, ClassificationNotFoundException,
|
||||
InvalidArgumentException, InvalidStateException, ConcurrencyException,
|
||||
AttachmentPersistenceException {
|
||||
|
@ -193,7 +193,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "user_3_2",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedPropertyOfTasksWithNoQualifyingTasks() {
|
||||
void should_ReturnBulkLog_when_UserIsNotAuthorizedForTasks() {
|
||||
String tkId1 = "TKI:000000000000000000000000000000000008";
|
||||
String tkId2 = "TKI:000000000000000000000000000000000009";
|
||||
String tkId3 = "TKI:000000000000000000000000000000000008";
|
||||
|
@ -215,7 +215,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "admin",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedPropertyOfTasksWithAdminUser()
|
||||
void should_SetPlannedPropertyOfTasks_when_RequestedByAdminUser()
|
||||
throws NotAuthorizedException, TaskNotFoundException {
|
||||
String tkId1 = "TKI:000000000000000000000000000000000008";
|
||||
String tkId2 = "TKI:000000000000000000000000000000000009";
|
||||
|
@ -242,7 +242,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "admin",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedPropertyOnEmptyTasksList() {
|
||||
void should_DoNothing_when_SetPlannedIsCalledWithEmptyTasksList() {
|
||||
Instant planned = getInstant("2020-05-03T07:00:00");
|
||||
BulkOperationResults<String, TaskanaException> results =
|
||||
taskService.setPlannedPropertyOfTasks(planned, new ArrayList<>());
|
||||
|
@ -261,7 +261,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "admin",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedPropertyOnSingleTaskWithBulkUpdate()
|
||||
void should_SetPlannedPropertyWithBulkUpdate_when_RequestContainsASingleTask()
|
||||
throws NotAuthorizedException, TaskNotFoundException, InvalidArgumentException {
|
||||
String taskId = "TKI:000000000000000000000000000000000002";
|
||||
Instant planned = getInstant("2020-05-03T07:00:00");
|
||||
|
@ -279,7 +279,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "admin",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedPropertyOnSingleTaskWithTaskUpdate()
|
||||
void should_SetPlannedPropertyOnSingle_when_UpdateTaskWasCalled()
|
||||
throws NotAuthorizedException, TaskNotFoundException, InvalidArgumentException,
|
||||
ConcurrencyException, InvalidStateException, ClassificationNotFoundException,
|
||||
AttachmentPersistenceException {
|
||||
|
@ -297,7 +297,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "admin",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetDuePropertyOnSingleTask()
|
||||
void should_SetDueOrPlannedProperty_when_TaskUpdateIsCalled()
|
||||
throws NotAuthorizedException, TaskNotFoundException, InvalidArgumentException,
|
||||
ConcurrencyException, InvalidStateException, ClassificationNotFoundException,
|
||||
AttachmentPersistenceException {
|
||||
|
@ -305,14 +305,17 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
Instant planned = getInstant("2020-05-03T07:00:00");
|
||||
Task task = taskService.getTask(taskId);
|
||||
|
||||
// test update of due that fails
|
||||
// test update of due with unchanged planned
|
||||
task.setDue(planned.plus(Duration.ofDays(8)));
|
||||
Task finalTask = task;
|
||||
ThrowingCallable taskanaCall =
|
||||
() -> {
|
||||
taskService.updateTask(finalTask);
|
||||
};
|
||||
assertThatThrownBy(taskanaCall).isInstanceOf(InvalidArgumentException.class);
|
||||
task = taskService.updateTask(task);
|
||||
assertThat(task.getPlanned()).isEqualTo(getInstant("2020-05-08T07:00:00"));
|
||||
|
||||
// test update of due with changed planned and due that fails
|
||||
task.setPlanned(planned.plus(Duration.ofDays(12)));
|
||||
task.setDue(planned.plus(Duration.ofDays(22)));
|
||||
final Task finalTask = task;
|
||||
assertThatThrownBy(() -> taskService.updateTask(finalTask))
|
||||
.isInstanceOf(InvalidArgumentException.class);
|
||||
|
||||
// update due and planned as expected.
|
||||
task = taskService.getTask(taskId);
|
||||
|
@ -337,7 +340,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "admin",
|
||||
groupNames = {"group_2"})
|
||||
@Test
|
||||
void testSetPlannedPropertyOnSingleTaskUpdateWithNulls()
|
||||
void should_setDue_when_taskUpdateIsCalled()
|
||||
throws NotAuthorizedException, TaskNotFoundException, InvalidArgumentException,
|
||||
ConcurrencyException, InvalidStateException, ClassificationNotFoundException,
|
||||
AttachmentPersistenceException {
|
||||
|
@ -374,7 +377,8 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdatePlannedAndDue() throws NotAuthorizedException, TaskNotFoundException {
|
||||
void should_throwException_when_DueAndPlannedAreChangedInconsistently()
|
||||
throws NotAuthorizedException, TaskNotFoundException {
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000030");
|
||||
task.setPlanned(getInstant("2020-04-21T07:00:00"));
|
||||
task.setDue(getInstant("2020-04-21T10:00:00"));
|
||||
|
@ -386,7 +390,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
|||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdateTaskSetPlannedOrDueToWeekend()
|
||||
void should_UpdateTaskPlannedOrDue_when_PlannedOrDueAreWeekendDays()
|
||||
throws NotAuthorizedException, TaskNotFoundException, ClassificationNotFoundException,
|
||||
InvalidArgumentException, InvalidStateException, ConcurrencyException,
|
||||
AttachmentPersistenceException {
|
||||
|
|
|
@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -42,7 +43,35 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdatePrimaryObjectReferenceOfTask()
|
||||
public void should_updatePlanned_when_onlyDueWasChanged() throws Exception {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
|
||||
task.setDue(Instant.parse("2020-07-02T01:00:00Z"));
|
||||
Task task1 = taskService.updateTask(task);
|
||||
assertThat(task1.getPlanned()).isEqualTo(Instant.parse("2020-07-01T01:00:00Z"));
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
public void should_throwException_when_DueAndPlannedWasChangedInconsistently() throws Exception {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
|
||||
task.setDue(Instant.parse("2020-07-02T00:00:00Z"));
|
||||
task.setPlanned(Instant.parse("2020-07-07T00:00:00Z"));
|
||||
assertThatThrownBy(() -> taskService.updateTask(task))
|
||||
.isInstanceOf(InvalidArgumentException.class)
|
||||
.withFailMessage(
|
||||
"Cannot update a task with given planned 2020-07-07T00:00:00Z and due "
|
||||
+ "date 2020-07-02T00:00:00Z not matching the service level PT24H.");
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void should_UpdatePrimaryObjectReferenceOfTask_when_requested()
|
||||
throws NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
TaskNotFoundException, ConcurrencyException, AttachmentPersistenceException,
|
||||
InvalidStateException {
|
||||
|
@ -73,7 +102,7 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testThrowsExceptionIfMandatoryPrimaryObjectReferenceIsNotSetOrIncomplete()
|
||||
void should_ThrowException_when_MandatoryPrimaryObjectReferenceIsNotSetOrIncomplete()
|
||||
throws NotAuthorizedException, TaskNotFoundException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
@ -115,7 +144,7 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testThrowsExceptionIfTaskHasAlreadyBeenUpdated()
|
||||
void should_ThrowException_when_TaskHasAlreadyBeenUpdated()
|
||||
throws NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||
TaskNotFoundException, ConcurrencyException, AttachmentPersistenceException,
|
||||
InvalidStateException, InterruptedException {
|
||||
|
@ -138,10 +167,10 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdateClassificationOfTask()
|
||||
void should_UpdateTaskProperties_when_ClassificationOfTaskIsChanged()
|
||||
throws TaskNotFoundException, ClassificationNotFoundException, InvalidArgumentException,
|
||||
ConcurrencyException, NotAuthorizedException, AttachmentPersistenceException,
|
||||
InvalidStateException {
|
||||
ConcurrencyException, NotAuthorizedException, AttachmentPersistenceException,
|
||||
InvalidStateException, SQLException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
|
||||
|
@ -157,13 +186,15 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
assertThat(task.getPlanned()).isEqualTo(updatedTask.getPlanned());
|
||||
assertThat(task.getName()).isEqualTo(updatedTask.getName());
|
||||
assertThat(task.getDescription()).isEqualTo(updatedTask.getDescription());
|
||||
resetDb(false); // classification of task TKI:0..00 was changed...
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
userName = "user_1_2",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdateReadFlagOfTask() throws TaskNotFoundException, NotAuthorizedException {
|
||||
void should_UpdateReadFlagOfTask_whenSetTaskReadIsCalled()
|
||||
throws TaskNotFoundException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
|
@ -187,7 +218,7 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testCustomPropertiesOfTask()
|
||||
void should_UpdateTask_when_CustomPropertiesOfTaskWereChanged()
|
||||
throws TaskNotFoundException, ClassificationNotFoundException, InvalidArgumentException,
|
||||
ConcurrencyException, NotAuthorizedException, AttachmentPersistenceException,
|
||||
InvalidStateException {
|
||||
|
@ -204,7 +235,7 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdateOfWorkbasketKeyWhatIsNotAllowed()
|
||||
void should_ThrowException_when_ModificationOfWorkbasketKeyIsAttempted()
|
||||
throws NotAuthorizedException, TaskNotFoundException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
@ -219,7 +250,7 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdateTasksByPorForUser1() throws InvalidArgumentException {
|
||||
void should_UpdateTask_when_ObjectReferenceWasChanged() throws InvalidArgumentException {
|
||||
ObjectReference por = new ObjectReference();
|
||||
por.setCompany("00");
|
||||
por.setSystem("PASystem");
|
||||
|
@ -241,7 +272,7 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "teamlead_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdateTasksByPor()
|
||||
void should_UpdateTask_when_PrimaryObjectReferenceWasChanged()
|
||||
throws InvalidArgumentException, TaskNotFoundException, NotAuthorizedException {
|
||||
ObjectReference por = new ObjectReference();
|
||||
por.setCompany("00");
|
||||
|
@ -271,7 +302,7 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "teamlead_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdateTasksById()
|
||||
void should_UpdateTaskCustomAttributes_when_UpdateTasksIsCalled()
|
||||
throws InvalidArgumentException, TaskNotFoundException, NotAuthorizedException {
|
||||
List<String> taskIds =
|
||||
Arrays.asList(
|
||||
|
@ -301,7 +332,7 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
@Test
|
||||
void testUpdateCallbackInfoOfSimpleTask()
|
||||
void should_UpdateCallbackInfo_when_requestedByApi()
|
||||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException,
|
||||
ConcurrencyException, AttachmentPersistenceException, InvalidStateException {
|
||||
|
@ -341,5 +372,4 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
|||
|
||||
assertThat(retrievedUpdatedTask.getCallbackInfo()).isEqualTo(callbackInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue