TSK-1143 even more comments from Holger

This commit is contained in:
BerndBreier 2020-03-17 18:17:54 +01:00 committed by Holger Hagen
parent f78e7616f6
commit e470f8d200
4 changed files with 170 additions and 152 deletions

View File

@ -16,16 +16,11 @@ import org.slf4j.LoggerFactory;
import pro.taskana.classification.api.models.ClassificationSummary;
import pro.taskana.common.api.BulkOperationResults;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.exceptions.InvalidArgumentException;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.api.exceptions.SystemException;
import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.common.internal.security.CurrentUserContext;
import pro.taskana.common.internal.util.DaysToWorkingDaysConverter;
import pro.taskana.common.internal.util.Pair;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.exceptions.UpdateFailedException;
import pro.taskana.task.api.models.Attachment;
import pro.taskana.task.api.models.AttachmentSummary;
@ -68,45 +63,21 @@ class ServiceLevelHandler {
// - For each task iterate through all referenced classifications and find minimum ServiceLevel
// - collect the results into a map Duration -> List of tasks
// - for each duration in this map update due date of all associated tasks
BulkLog setPlannedPropertyOfTasksImpl(Instant planned, List<String> argTaskIds) {
BulkLog setPlannedPropertyOfTasksImpl(Instant planned, List<MinimalTaskSummary> tasks) {
BulkLog bulkLog = new BulkLog();
if (argTaskIds == null || argTaskIds.isEmpty()) {
return bulkLog;
}
Pair<List<MinimalTaskSummary>, BulkLog> resultsPair =
filterTasksForExistenceAndAuthorization(argTaskIds);
List<MinimalTaskSummary> existingTasksAuthorizedFor = resultsPair.getLeft();
bulkLog.addAllErrors(resultsPair.getRight());
List<AttachmentSummaryImpl> attachments = getAttachmentSummaries(existingTasksAuthorizedFor);
List<AttachmentSummaryImpl> attachments = getAttachmentSummaries(tasks);
List<ClassificationSummary> allInvolvedClassifications =
findAllInvolvedClassifications(existingTasksAuthorizedFor, attachments);
findAllInvolvedClassifications(tasks, attachments);
List<ClassificationWithServiceLevelResolved> allInvolvedClassificationsWithDuration =
resolveDurationsInClassifications(allInvolvedClassifications);
Map<Duration, List<String>> durationToTaskIdsMap =
getDurationToTaskIdsMap(
existingTasksAuthorizedFor, attachments, allInvolvedClassificationsWithDuration);
getDurationToTaskIdsMap(tasks, attachments, allInvolvedClassificationsWithDuration);
BulkLog updateResult = updatePlannedPropertyOfAffectedTasks(planned, durationToTaskIdsMap);
bulkLog.addAllErrors(updateResult);
return bulkLog;
}
BulkLog addExceptionsForNonExistingTasksToBulkLog(
List<String> requestTaskIds, List<MinimalTaskSummary> existingMinimalTaskSummaries) {
BulkLog bulkLog = new BulkLog();
List<String> nonExistingTaskIds = new ArrayList<>(requestTaskIds);
List<String> existingTaskIds =
existingMinimalTaskSummaries.stream()
.map(MinimalTaskSummary::getTaskId)
.collect(Collectors.toList());
nonExistingTaskIds.removeAll(existingTaskIds);
nonExistingTaskIds.forEach(
taskId ->
bulkLog.addError(taskId, new TaskNotFoundException(taskId, "Task was not found")));
return bulkLog;
}
TaskImpl updatePrioPlannedDueOfTask(
TaskImpl newTaskImpl, TaskImpl oldTaskImpl, boolean forRefreshOnClassificationUpdate)
throws InvalidArgumentException {
@ -131,8 +102,9 @@ class ServiceLevelHandler {
}
// classification update
if (forRefreshOnClassificationUpdate) {
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
durationPrioHolder.getDuration()));
newTaskImpl.setDue(
converter.addWorkingDaysToInstant(
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
return newTaskImpl;
}
// creation of new task
@ -160,48 +132,6 @@ class ServiceLevelHandler {
return getFinalPrioDurationOfTask(resolvedClassifications, onlyPriority);
}
Pair<List<MinimalTaskSummary>, BulkLog> filterTasksForExistenceAndAuthorization(
List<String> argTaskIds) {
BulkLog bulkLog = new BulkLog();
// remove duplicates
List<String> taskIds = argTaskIds.stream().distinct().collect(Collectors.toList());
// get existing tasks
List<MinimalTaskSummary> minimalTaskSummaries = taskMapper.findExistingTasks(taskIds, null);
bulkLog.addAllErrors(addExceptionsForNonExistingTasksToBulkLog(taskIds, minimalTaskSummaries));
Pair<List<MinimalTaskSummary>, BulkLog> filteredPair =
filterTasksAuthorizedForAndLogErrorsForNotAuthorized(minimalTaskSummaries);
bulkLog.addAllErrors(filteredPair.getRight());
return new Pair<>(filteredPair.getLeft(), bulkLog);
}
Pair<List<MinimalTaskSummary>, BulkLog> filterTasksAuthorizedForAndLogErrorsForNotAuthorized(
List<MinimalTaskSummary> existingTasks) {
BulkLog bulkLog = new BulkLog();
// check authorization only for non-admin users
if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN)) {
return new Pair<>(existingTasks, bulkLog);
} else {
List<String> taskIds =
existingTasks.stream().map(MinimalTaskSummary::getTaskId).collect(Collectors.toList());
List<String> accessIds = CurrentUserContext.getAccessIds();
List<String> taskIdsNotAuthorizedFor =
taskMapper.filterTaskIdsNotAuthorizedFor(taskIds, accessIds);
String userId = CurrentUserContext.getUserid();
for (String taskId : taskIdsNotAuthorizedFor) {
bulkLog.addError(
taskId,
new NotAuthorizedException(
String.format("User %s is not authorized for task %s ", userId, taskId), userId));
}
taskIds.removeAll(taskIdsNotAuthorizedFor);
List<MinimalTaskSummary> tasksAuthorizedFor =
existingTasks.stream()
.filter(t -> taskIds.contains(t.getTaskId()))
.collect(Collectors.toList());
return new Pair<>(tasksAuthorizedFor, bulkLog);
}
}
private TaskImpl updatePlannedDueOnTaskUpdate(
TaskImpl newTaskImpl, TaskImpl oldTaskImpl, DurationPrioHolder durationPrioHolder)
throws InvalidArgumentException {
@ -211,21 +141,24 @@ class ServiceLevelHandler {
// case 1: no change of planned / due, but potentially change of an attachment or classification
if (oldTaskImpl.getDue().equals(newTaskImpl.getDue())
&& oldTaskImpl.getPlanned().equals(newTaskImpl.getPlanned())) {
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
durationPrioHolder.getDuration()));
newTaskImpl.setDue(
converter.addWorkingDaysToInstant(
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
} else if (oldTaskImpl.getDue().equals(newTaskImpl.getDue())
&& newTaskImpl.getPlanned() != null) {
// case 2: planned was changed
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
durationPrioHolder.getDuration()));
newTaskImpl.setDue(
converter.addWorkingDaysToInstant(
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
} else { // case 3: due was changed
if (newTaskImpl.getDue() == null) {
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
durationPrioHolder.getDuration()));
newTaskImpl.setDue(
converter.addWorkingDaysToInstant(
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
} else {
Instant planned =
(converter.subtractWorkingDaysFromInstant(newTaskImpl.getDue(),
durationPrioHolder.getDuration()));
(converter.subtractWorkingDaysFromInstant(
newTaskImpl.getDue(), durationPrioHolder.getDuration()));
if (newTaskImpl.getPlanned() != null && !planned.equals(newTaskImpl.getPlanned())) {
throw new InvalidArgumentException(
"Cannot update a task with given planned "
@ -240,8 +173,9 @@ class ServiceLevelHandler {
private TaskImpl updatePlannedDueOnCreationOfNewTask(
TaskImpl newTaskImpl, DurationPrioHolder durationPrioHolder) throws InvalidArgumentException {
if (newTaskImpl.getDue() != null) { // due is specified: calculate back and check correctnes
Instant planned = (converter.subtractWorkingDaysFromInstant(newTaskImpl.getDue(),
durationPrioHolder.getDuration()));
Instant planned =
(converter.subtractWorkingDaysFromInstant(
newTaskImpl.getDue(), durationPrioHolder.getDuration()));
if (newTaskImpl.getPlanned() != null && !planned.equals(newTaskImpl.getPlanned())) {
throw new InvalidArgumentException(
"Cannot create a task with given planned "
@ -249,8 +183,9 @@ class ServiceLevelHandler {
}
newTaskImpl.setPlanned(planned);
} else { // task.due is null: calculate forward from planned
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
durationPrioHolder.getDuration()));
newTaskImpl.setDue(
converter.addWorkingDaysToInstant(
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
}
return newTaskImpl;
}

View File

@ -91,7 +91,6 @@ public class TaskServiceImpl implements TaskService {
private static final Set<String> ALLOWED_KEYS =
IntStream.rangeClosed(1, 16).mapToObj(String::valueOf).collect(Collectors.toSet());
private DaysToWorkingDaysConverter converter;
private InternalTaskanaEngine taskanaEngine;
private WorkbasketService workbasketService;
private ClassificationService classificationService;
@ -684,8 +683,7 @@ public class TaskServiceImpl implements TaskService {
try {
taskanaEngine.openConnection();
// use only elements we are authorized for
Pair<List<MinimalTaskSummary>, BulkLog> resultsPair =
serviceLevelHandler.filterTasksForExistenceAndAuthorization(taskIds);
Pair<List<MinimalTaskSummary>, BulkLog> resultsPair = getMinimalTaskSummaries(taskIds);
// set the Owner of these tasks we are authorized for
List<MinimalTaskSummary> existingMinimalTaskSummaries = resultsPair.getLeft();
taskIds =
@ -730,9 +728,20 @@ public class TaskServiceImpl implements TaskService {
planned,
LoggerUtils.listToString(argTaskIds));
}
BulkLog bulkLog = new BulkLog();
if (argTaskIds == null || argTaskIds.isEmpty()) {
return bulkLog;
}
try {
taskanaEngine.openConnection();
return serviceLevelHandler.setPlannedPropertyOfTasksImpl(planned, argTaskIds);
Pair<List<MinimalTaskSummary>, BulkLog> resultsPair = getMinimalTaskSummaries(argTaskIds);
List<MinimalTaskSummary> tasksToModify = resultsPair.getLeft();
bulkLog.addAllErrors(resultsPair.getRight());
BulkLog errorsFromProcessing =
serviceLevelHandler.setPlannedPropertyOfTasksImpl(planned, tasksToModify);
bulkLog.addAllErrors(errorsFromProcessing);
return bulkLog;
} finally {
LOGGER.debug("exit from setPlannedPropertyOfTasks");
taskanaEngine.returnConnection();
@ -811,6 +820,62 @@ public class TaskServiceImpl implements TaskService {
}
}
Pair<List<MinimalTaskSummary>, BulkLog> getMinimalTaskSummaries(List<String> argTaskIds) {
BulkLog bulkLog = new BulkLog();
// remove duplicates
List<String> taskIds = argTaskIds.stream().distinct().collect(Collectors.toList());
// get existing tasks
List<MinimalTaskSummary> minimalTaskSummaries = taskMapper.findExistingTasks(taskIds, null);
bulkLog.addAllErrors(addExceptionsForNonExistingTasksToBulkLog(taskIds, minimalTaskSummaries));
Pair<List<MinimalTaskSummary>, BulkLog> filteredPair =
filterTasksAuthorizedForAndLogErrorsForNotAuthorized(minimalTaskSummaries);
bulkLog.addAllErrors(filteredPair.getRight());
return new Pair<>(filteredPair.getLeft(), bulkLog);
}
Pair<List<MinimalTaskSummary>, BulkLog> filterTasksAuthorizedForAndLogErrorsForNotAuthorized(
List<MinimalTaskSummary> existingTasks) {
BulkLog bulkLog = new BulkLog();
// check authorization only for non-admin users
if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN)) {
return new Pair<>(existingTasks, bulkLog);
} else {
List<String> taskIds =
existingTasks.stream().map(MinimalTaskSummary::getTaskId).collect(Collectors.toList());
List<String> accessIds = CurrentUserContext.getAccessIds();
List<String> taskIdsNotAuthorizedFor =
taskMapper.filterTaskIdsNotAuthorizedFor(taskIds, accessIds);
String userId = CurrentUserContext.getUserid();
for (String taskId : taskIdsNotAuthorizedFor) {
bulkLog.addError(
taskId,
new NotAuthorizedException(
String.format("User %s is not authorized for task %s ", userId, taskId), userId));
}
taskIds.removeAll(taskIdsNotAuthorizedFor);
List<MinimalTaskSummary> tasksAuthorizedFor =
existingTasks.stream()
.filter(t -> taskIds.contains(t.getTaskId()))
.collect(Collectors.toList());
return new Pair<>(tasksAuthorizedFor, bulkLog);
}
}
BulkLog addExceptionsForNonExistingTasksToBulkLog(
List<String> requestTaskIds, List<MinimalTaskSummary> existingMinimalTaskSummaries) {
BulkLog bulkLog = new BulkLog();
List<String> nonExistingTaskIds = new ArrayList<>(requestTaskIds);
List<String> existingTaskIds =
existingMinimalTaskSummaries.stream()
.map(MinimalTaskSummary::getTaskId)
.collect(Collectors.toList());
nonExistingTaskIds.removeAll(existingTaskIds);
nonExistingTaskIds.forEach(
taskId ->
bulkLog.addError(taskId, new TaskNotFoundException(taskId, "Task was not found")));
return bulkLog;
}
void removeNonExistingTasksFromTaskIdList(
List<String> taskIds, BulkOperationResults<String, TaskanaException> bulkLog) {
if (LOGGER.isDebugEnabled()) {
@ -866,8 +931,6 @@ public class TaskServiceImpl implements TaskService {
return result;
}
private TaskImpl checkConcurrencyAndSetModified(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)
throws ConcurrencyException {
// TODO: not safe to rely only on different timestamps.
@ -1213,7 +1276,7 @@ public class TaskServiceImpl implements TaskService {
} catch (Exception e) {
LOGGER.warn(
"Attempted to determine callback state from {} and caught exception", value, e);
throw new InvalidArgumentException(
String.format("Attempted to set callback state for task %s.", task.getId()), e);
}

View File

@ -0,0 +1,63 @@
package acceptance.task;
import static org.assertj.core.api.Assertions.assertThat;
import acceptance.AbstractAccTest;
import java.sql.SQLException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.common.api.BulkOperationResults;
import pro.taskana.common.api.exceptions.TaskanaException;
import pro.taskana.security.JaasExtension;
import pro.taskana.security.WithAccessId;
import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.models.Task;
import pro.taskana.task.api.models.TaskSummary;
/** Acceptance test for planned and prio of all tasks. */
@ExtendWith(JaasExtension.class)
@SuppressWarnings({"checkstyle:LineLength"})
public class ServiceLevelOfAllTasksAccTest extends AbstractAccTest {
TaskService taskService;
@WithAccessId(
userName = "admin",
groupNames = {"group_2"})
@Test
void testSetPlannedPropertyOnAllTasks() throws SQLException {
taskService = taskanaEngine.getTaskService();
Instant planned = getInstant("2020-05-03T07:00:00");
List<TaskSummary> allTasks = taskService.createTaskQuery().list();
// Now update each task with updateTask() and new planned
final List<TaskSummary> individuallyUpdatedTasks = new ArrayList<>();
allTasks.forEach(t -> individuallyUpdatedTasks.add(getUpdatedTaskSummary(t, planned)));
// reset DB and do the same with bulk update
resetDb(false);
List<String> taskIds = allTasks.stream().map(TaskSummary::getId).collect(Collectors.toList());
BulkOperationResults<String, TaskanaException> bulkLog =
taskService.setPlannedPropertyOfTasks(planned, taskIds);
// check that there was no error and compare the result of the 2 operations
assertThat(bulkLog.containsErrors()).isFalse();
Map<String, Instant> bulkUpdatedTaskMap =
taskService.createTaskQuery().list().stream()
.collect(Collectors.toMap(TaskSummary::getId, TaskSummary::getDue));
individuallyUpdatedTasks.forEach(
t -> assertThat(t.getDue().equals(bulkUpdatedTaskMap.get(t.getId()))));
}
private TaskSummary getUpdatedTaskSummary(TaskSummary t, Instant planned) {
try {
Task task = taskService.getTask(t.getId());
task.setPlanned(planned);
return taskService.updateTask(task);
} catch (Exception e) {
return null;
}
}
}

View File

@ -4,16 +4,12 @@ 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.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -31,7 +27,6 @@ import pro.taskana.task.api.exceptions.AttachmentPersistenceException;
import pro.taskana.task.api.exceptions.InvalidStateException;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.Task;
import pro.taskana.task.api.models.TaskSummary;
/** Acceptance test for all "create task" scenarios. */
@ExtendWith(JaasExtension.class)
@ -39,11 +34,9 @@ import pro.taskana.task.api.models.TaskSummary;
public class ServiceLevelPriorityAccTest extends AbstractAccTest {
private TaskService taskService;
@BeforeEach
void setup() throws SQLException {
DaysToWorkingDaysConverter.setGermanPublicHolidaysEnabled(true);
ServiceLevelPriorityAccTest() {
super();
taskService = taskanaEngine.getTaskService();
resetDb(false);
}
@WithAccessId(
@ -67,7 +60,6 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
String tkId4 = "TKI:000000000000000000000000000000000060";
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4);
TaskService taskService = taskanaEngine.getTaskService();
Instant planned = getInstant("2020-02-11T07:00:00");
BulkOperationResults<String, TaskanaException> results =
@ -100,7 +92,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4, tkId5);
Instant planned = getInstant("2020-04-20T07:00:00");
BulkOperationResults<String, TaskanaException> results =
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, taskIds);
taskService.setPlannedPropertyOfTasks(planned, taskIds);
assertThat(results.containsErrors()).isTrue();
assertThat(results.getErrorMap().size()).isEqualTo(1);
assertThat(results.getErrorForId("TKI:000000000000000000000000000047110059"))
@ -144,7 +136,6 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
// |TAI:000000000000000000000000000000000007 | CLI:100000000000000000000000000000000008 | P1D |
// +-----------------------------------------+------------------------------------------+------+
TaskService taskService = taskanaEngine.getTaskService();
String tkId0 = "TKI:000000000000000000000000000000000000";
String tkId1 = "TKI:000000000000000000000000000000000001";
String tkId2 = "TKI:000000000000000000000000000000000002";
@ -209,7 +200,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4);
Instant planned = getInstant("2020-02-25T07:00:00");
BulkOperationResults<String, TaskanaException> results =
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, taskIds);
taskService.setPlannedPropertyOfTasks(planned, taskIds);
assertThat(results.containsErrors()).isTrue();
assertThat(results.getErrorMap().size()).isEqualTo(3);
assertThat(results.getErrorForId(tkId1)).isInstanceOf(NotAuthorizedException.class);
@ -232,7 +223,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4);
Instant planned = getInstant("2020-05-03T07:00:00");
BulkOperationResults<String, TaskanaException> results =
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, taskIds);
taskService.setPlannedPropertyOfTasks(planned, taskIds);
assertThat(results.containsErrors()).isFalse();
Instant dueBulk1 = taskService.getTask(tkId1).getDue();
@ -240,9 +231,9 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
Instant dueBulk3 = taskService.getTask(tkId3).getDue();
Instant dueBulk4 = taskService.getTask(tkId4).getDue();
assertThat(dueBulk1).isEqualTo(getInstant("2020-05-14T07:00:00"));
assertThat(dueBulk2).isEqualTo(getInstant("2020-05-22T07:00:00"));
assertThat(dueBulk2).isEqualTo(getInstant("2020-05-21T07:00:00"));
assertThat(dueBulk3).isEqualTo(getInstant("2020-05-14T07:00:00"));
assertThat(dueBulk4).isEqualTo(getInstant("2020-05-22T07:00:00"));
assertThat(dueBulk4).isEqualTo(getInstant("2020-05-21T07:00:00"));
}
@WithAccessId(
@ -252,7 +243,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
void testSetPlannedPropertyOnEmptyTasksList() {
Instant planned = getInstant("2020-05-03T07:00:00");
BulkOperationResults<String, TaskanaException> results =
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, new ArrayList<>());
taskService.setPlannedPropertyOfTasks(planned, new ArrayList<>());
assertThat(results.containsErrors()).isFalse();
}
@ -274,7 +265,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
Instant planned = getInstant("2020-05-03T07:00:00");
// test bulk operation setPlanned...
BulkOperationResults<String, TaskanaException> results =
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, Arrays.asList(taskId));
taskService.setPlannedPropertyOfTasks(planned, Arrays.asList(taskId));
Task task = taskService.getTask(taskId);
assertThat(results.containsErrors()).isFalse();
DaysToWorkingDaysConverter converter = DaysToWorkingDaysConverter.initialize();
@ -316,9 +307,10 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
task.setDue(planned.plus(Duration.ofDays(8)));
Task finalTask = task;
assertThatThrownBy(
() -> {
taskService.updateTask(finalTask);
}).isInstanceOf(InvalidArgumentException.class);
() -> {
taskService.updateTask(finalTask);
})
.isInstanceOf(InvalidArgumentException.class);
// update due and planned as expected.
task = taskService.getTask(taskId);
@ -376,50 +368,15 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
assertThat(task.getPlanned()).isEqualTo(task.getDue().plus(Duration.ofDays(days)));
}
@WithAccessId(
userName = "admin",
groupNames = {"group_2"})
@Test
void testSetPlannedPropertyOnAllTasks() throws SQLException {
Instant planned = getInstant("2020-05-03T07:00:00");
List<TaskSummary> allTasks = taskService.createTaskQuery().list();
// Now update each task with updateTask() and new planned
final List<TaskSummary> individuallyUpdatedTasks = new ArrayList<>();
allTasks.forEach(t -> individuallyUpdatedTasks.add(getUpdatedTaskSummary(t, planned)));
// reset DB and do the same with bulk update
resetDb(false);
List<String> taskIds = allTasks.stream().map(TaskSummary::getId).collect(Collectors.toList());
BulkOperationResults<String, TaskanaException> bulkLog =
taskService.setPlannedPropertyOfTasks(planned, taskIds);
// check that there was no error and compare the result of the 2 operations
assertThat(bulkLog.containsErrors()).isFalse();
Map<String, Instant> bulkUpdatedTaskMap =
taskService.createTaskQuery().list().stream()
.collect(Collectors.toMap(TaskSummary::getId, TaskSummary::getDue));
individuallyUpdatedTasks.forEach(
t -> assertThat(t.getDue().equals(bulkUpdatedTaskMap.get(t.getId()))));
}
@WithAccessId(
userName = "user_1_2",
groupNames = {"group_1"})
@Test
void testUpdatePlannedAndDue() throws NotAuthorizedException, TaskNotFoundException {
TaskService taskService = taskanaEngine.getTaskService();
Task task = taskService.getTask("TKI:000000000000000000000000000000000030");
task.setPlanned(getInstant("2020-04-21T07:00:00"));
task.setDue(getInstant("2020-04-21T10:00:00"));
assertThatThrownBy(() -> taskService.updateTask(task))
.isInstanceOf(InvalidArgumentException.class);
}
private TaskSummary getUpdatedTaskSummary(TaskSummary t, Instant planned) {
try {
Task task = taskService.getTask(t.getId());
task.setPlanned(planned);
return taskService.updateTask(task);
} catch (Exception e) {
return null;
}
}
}