TSK-1143 even more comments from Holger
This commit is contained in:
parent
f78e7616f6
commit
e470f8d200
|
|
@ -16,16 +16,11 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.classification.api.models.ClassificationSummary;
|
import pro.taskana.classification.api.models.ClassificationSummary;
|
||||||
import pro.taskana.common.api.BulkOperationResults;
|
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.InvalidArgumentException;
|
||||||
import pro.taskana.common.api.exceptions.NotAuthorizedException;
|
|
||||||
import pro.taskana.common.api.exceptions.SystemException;
|
import pro.taskana.common.api.exceptions.SystemException;
|
||||||
import pro.taskana.common.api.exceptions.TaskanaException;
|
import pro.taskana.common.api.exceptions.TaskanaException;
|
||||||
import pro.taskana.common.internal.InternalTaskanaEngine;
|
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.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.exceptions.UpdateFailedException;
|
||||||
import pro.taskana.task.api.models.Attachment;
|
import pro.taskana.task.api.models.Attachment;
|
||||||
import pro.taskana.task.api.models.AttachmentSummary;
|
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
|
// - For each task iterate through all referenced classifications and find minimum ServiceLevel
|
||||||
// - collect the results into a map Duration -> List of tasks
|
// - collect the results into a map Duration -> List of tasks
|
||||||
// - for each duration in this map update due date of all associated 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();
|
BulkLog bulkLog = new BulkLog();
|
||||||
if (argTaskIds == null || argTaskIds.isEmpty()) {
|
List<AttachmentSummaryImpl> attachments = getAttachmentSummaries(tasks);
|
||||||
return bulkLog;
|
|
||||||
}
|
|
||||||
Pair<List<MinimalTaskSummary>, BulkLog> resultsPair =
|
|
||||||
filterTasksForExistenceAndAuthorization(argTaskIds);
|
|
||||||
List<MinimalTaskSummary> existingTasksAuthorizedFor = resultsPair.getLeft();
|
|
||||||
bulkLog.addAllErrors(resultsPair.getRight());
|
|
||||||
|
|
||||||
List<AttachmentSummaryImpl> attachments = getAttachmentSummaries(existingTasksAuthorizedFor);
|
|
||||||
List<ClassificationSummary> allInvolvedClassifications =
|
List<ClassificationSummary> allInvolvedClassifications =
|
||||||
findAllInvolvedClassifications(existingTasksAuthorizedFor, attachments);
|
findAllInvolvedClassifications(tasks, attachments);
|
||||||
List<ClassificationWithServiceLevelResolved> allInvolvedClassificationsWithDuration =
|
List<ClassificationWithServiceLevelResolved> allInvolvedClassificationsWithDuration =
|
||||||
resolveDurationsInClassifications(allInvolvedClassifications);
|
resolveDurationsInClassifications(allInvolvedClassifications);
|
||||||
Map<Duration, List<String>> durationToTaskIdsMap =
|
Map<Duration, List<String>> durationToTaskIdsMap =
|
||||||
getDurationToTaskIdsMap(
|
getDurationToTaskIdsMap(tasks, attachments, allInvolvedClassificationsWithDuration);
|
||||||
existingTasksAuthorizedFor, attachments, allInvolvedClassificationsWithDuration);
|
|
||||||
BulkLog updateResult = updatePlannedPropertyOfAffectedTasks(planned, durationToTaskIdsMap);
|
BulkLog updateResult = updatePlannedPropertyOfAffectedTasks(planned, durationToTaskIdsMap);
|
||||||
bulkLog.addAllErrors(updateResult);
|
bulkLog.addAllErrors(updateResult);
|
||||||
|
|
||||||
return bulkLog;
|
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 updatePrioPlannedDueOfTask(
|
||||||
TaskImpl newTaskImpl, TaskImpl oldTaskImpl, boolean forRefreshOnClassificationUpdate)
|
TaskImpl newTaskImpl, TaskImpl oldTaskImpl, boolean forRefreshOnClassificationUpdate)
|
||||||
throws InvalidArgumentException {
|
throws InvalidArgumentException {
|
||||||
|
|
@ -131,8 +102,9 @@ class ServiceLevelHandler {
|
||||||
}
|
}
|
||||||
// classification update
|
// classification update
|
||||||
if (forRefreshOnClassificationUpdate) {
|
if (forRefreshOnClassificationUpdate) {
|
||||||
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
|
newTaskImpl.setDue(
|
||||||
durationPrioHolder.getDuration()));
|
converter.addWorkingDaysToInstant(
|
||||||
|
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
|
||||||
return newTaskImpl;
|
return newTaskImpl;
|
||||||
}
|
}
|
||||||
// creation of new task
|
// creation of new task
|
||||||
|
|
@ -160,48 +132,6 @@ class ServiceLevelHandler {
|
||||||
return getFinalPrioDurationOfTask(resolvedClassifications, onlyPriority);
|
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(
|
private TaskImpl updatePlannedDueOnTaskUpdate(
|
||||||
TaskImpl newTaskImpl, TaskImpl oldTaskImpl, DurationPrioHolder durationPrioHolder)
|
TaskImpl newTaskImpl, TaskImpl oldTaskImpl, DurationPrioHolder durationPrioHolder)
|
||||||
throws InvalidArgumentException {
|
throws InvalidArgumentException {
|
||||||
|
|
@ -211,21 +141,24 @@ class ServiceLevelHandler {
|
||||||
// case 1: no change of planned / due, but potentially change of an attachment or classification
|
// case 1: no change of planned / due, but potentially change of an attachment or classification
|
||||||
if (oldTaskImpl.getDue().equals(newTaskImpl.getDue())
|
if (oldTaskImpl.getDue().equals(newTaskImpl.getDue())
|
||||||
&& oldTaskImpl.getPlanned().equals(newTaskImpl.getPlanned())) {
|
&& oldTaskImpl.getPlanned().equals(newTaskImpl.getPlanned())) {
|
||||||
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
|
newTaskImpl.setDue(
|
||||||
durationPrioHolder.getDuration()));
|
converter.addWorkingDaysToInstant(
|
||||||
|
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
|
||||||
} else if (oldTaskImpl.getDue().equals(newTaskImpl.getDue())
|
} else if (oldTaskImpl.getDue().equals(newTaskImpl.getDue())
|
||||||
&& newTaskImpl.getPlanned() != null) {
|
&& newTaskImpl.getPlanned() != null) {
|
||||||
// case 2: planned was changed
|
// case 2: planned was changed
|
||||||
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
|
newTaskImpl.setDue(
|
||||||
durationPrioHolder.getDuration()));
|
converter.addWorkingDaysToInstant(
|
||||||
|
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
|
||||||
} else { // case 3: due was changed
|
} else { // case 3: due was changed
|
||||||
if (newTaskImpl.getDue() == null) {
|
if (newTaskImpl.getDue() == null) {
|
||||||
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
|
newTaskImpl.setDue(
|
||||||
durationPrioHolder.getDuration()));
|
converter.addWorkingDaysToInstant(
|
||||||
|
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
|
||||||
} else {
|
} else {
|
||||||
Instant planned =
|
Instant planned =
|
||||||
(converter.subtractWorkingDaysFromInstant(newTaskImpl.getDue(),
|
(converter.subtractWorkingDaysFromInstant(
|
||||||
durationPrioHolder.getDuration()));
|
newTaskImpl.getDue(), durationPrioHolder.getDuration()));
|
||||||
if (newTaskImpl.getPlanned() != null && !planned.equals(newTaskImpl.getPlanned())) {
|
if (newTaskImpl.getPlanned() != null && !planned.equals(newTaskImpl.getPlanned())) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
"Cannot update a task with given planned "
|
"Cannot update a task with given planned "
|
||||||
|
|
@ -240,8 +173,9 @@ class ServiceLevelHandler {
|
||||||
private TaskImpl updatePlannedDueOnCreationOfNewTask(
|
private TaskImpl updatePlannedDueOnCreationOfNewTask(
|
||||||
TaskImpl newTaskImpl, DurationPrioHolder durationPrioHolder) throws InvalidArgumentException {
|
TaskImpl newTaskImpl, DurationPrioHolder durationPrioHolder) throws InvalidArgumentException {
|
||||||
if (newTaskImpl.getDue() != null) { // due is specified: calculate back and check correctnes
|
if (newTaskImpl.getDue() != null) { // due is specified: calculate back and check correctnes
|
||||||
Instant planned = (converter.subtractWorkingDaysFromInstant(newTaskImpl.getDue(),
|
Instant planned =
|
||||||
durationPrioHolder.getDuration()));
|
(converter.subtractWorkingDaysFromInstant(
|
||||||
|
newTaskImpl.getDue(), durationPrioHolder.getDuration()));
|
||||||
if (newTaskImpl.getPlanned() != null && !planned.equals(newTaskImpl.getPlanned())) {
|
if (newTaskImpl.getPlanned() != null && !planned.equals(newTaskImpl.getPlanned())) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
"Cannot create a task with given planned "
|
"Cannot create a task with given planned "
|
||||||
|
|
@ -249,8 +183,9 @@ class ServiceLevelHandler {
|
||||||
}
|
}
|
||||||
newTaskImpl.setPlanned(planned);
|
newTaskImpl.setPlanned(planned);
|
||||||
} else { // task.due is null: calculate forward from planned
|
} else { // task.due is null: calculate forward from planned
|
||||||
newTaskImpl.setDue(converter.addWorkingDaysToInstant(newTaskImpl.getPlanned(),
|
newTaskImpl.setDue(
|
||||||
durationPrioHolder.getDuration()));
|
converter.addWorkingDaysToInstant(
|
||||||
|
newTaskImpl.getPlanned(), durationPrioHolder.getDuration()));
|
||||||
}
|
}
|
||||||
return newTaskImpl;
|
return newTaskImpl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,6 @@ public class TaskServiceImpl implements TaskService {
|
||||||
|
|
||||||
private static final Set<String> ALLOWED_KEYS =
|
private static final Set<String> ALLOWED_KEYS =
|
||||||
IntStream.rangeClosed(1, 16).mapToObj(String::valueOf).collect(Collectors.toSet());
|
IntStream.rangeClosed(1, 16).mapToObj(String::valueOf).collect(Collectors.toSet());
|
||||||
private DaysToWorkingDaysConverter converter;
|
|
||||||
private InternalTaskanaEngine taskanaEngine;
|
private InternalTaskanaEngine taskanaEngine;
|
||||||
private WorkbasketService workbasketService;
|
private WorkbasketService workbasketService;
|
||||||
private ClassificationService classificationService;
|
private ClassificationService classificationService;
|
||||||
|
|
@ -684,8 +683,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
try {
|
try {
|
||||||
taskanaEngine.openConnection();
|
taskanaEngine.openConnection();
|
||||||
// use only elements we are authorized for
|
// use only elements we are authorized for
|
||||||
Pair<List<MinimalTaskSummary>, BulkLog> resultsPair =
|
Pair<List<MinimalTaskSummary>, BulkLog> resultsPair = getMinimalTaskSummaries(taskIds);
|
||||||
serviceLevelHandler.filterTasksForExistenceAndAuthorization(taskIds);
|
|
||||||
// set the Owner of these tasks we are authorized for
|
// set the Owner of these tasks we are authorized for
|
||||||
List<MinimalTaskSummary> existingMinimalTaskSummaries = resultsPair.getLeft();
|
List<MinimalTaskSummary> existingMinimalTaskSummaries = resultsPair.getLeft();
|
||||||
taskIds =
|
taskIds =
|
||||||
|
|
@ -730,9 +728,20 @@ public class TaskServiceImpl implements TaskService {
|
||||||
planned,
|
planned,
|
||||||
LoggerUtils.listToString(argTaskIds));
|
LoggerUtils.listToString(argTaskIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BulkLog bulkLog = new BulkLog();
|
||||||
|
if (argTaskIds == null || argTaskIds.isEmpty()) {
|
||||||
|
return bulkLog;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
taskanaEngine.openConnection();
|
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 {
|
} finally {
|
||||||
LOGGER.debug("exit from setPlannedPropertyOfTasks");
|
LOGGER.debug("exit from setPlannedPropertyOfTasks");
|
||||||
taskanaEngine.returnConnection();
|
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(
|
void removeNonExistingTasksFromTaskIdList(
|
||||||
List<String> taskIds, BulkOperationResults<String, TaskanaException> bulkLog) {
|
List<String> taskIds, BulkOperationResults<String, TaskanaException> bulkLog) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
|
@ -866,8 +931,6 @@ public class TaskServiceImpl implements TaskService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private TaskImpl checkConcurrencyAndSetModified(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)
|
private TaskImpl checkConcurrencyAndSetModified(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)
|
||||||
throws ConcurrencyException {
|
throws ConcurrencyException {
|
||||||
// TODO: not safe to rely only on different timestamps.
|
// TODO: not safe to rely only on different timestamps.
|
||||||
|
|
@ -1213,7 +1276,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn(
|
LOGGER.warn(
|
||||||
"Attempted to determine callback state from {} and caught exception", value, e);
|
"Attempted to determine callback state from {} and caught exception", value, e);
|
||||||
|
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
String.format("Attempted to set callback state for task %s.", task.getId()), e);
|
String.format("Attempted to set callback state for task %s.", task.getId()), e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,16 +4,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
import acceptance.AbstractAccTest;
|
import acceptance.AbstractAccTest;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
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.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
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.InvalidStateException;
|
||||||
import pro.taskana.task.api.exceptions.TaskNotFoundException;
|
import pro.taskana.task.api.exceptions.TaskNotFoundException;
|
||||||
import pro.taskana.task.api.models.Task;
|
import pro.taskana.task.api.models.Task;
|
||||||
import pro.taskana.task.api.models.TaskSummary;
|
|
||||||
|
|
||||||
/** Acceptance test for all "create task" scenarios. */
|
/** Acceptance test for all "create task" scenarios. */
|
||||||
@ExtendWith(JaasExtension.class)
|
@ExtendWith(JaasExtension.class)
|
||||||
|
|
@ -39,11 +34,9 @@ import pro.taskana.task.api.models.TaskSummary;
|
||||||
public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
private TaskService taskService;
|
private TaskService taskService;
|
||||||
|
|
||||||
@BeforeEach
|
ServiceLevelPriorityAccTest() {
|
||||||
void setup() throws SQLException {
|
super();
|
||||||
DaysToWorkingDaysConverter.setGermanPublicHolidaysEnabled(true);
|
|
||||||
taskService = taskanaEngine.getTaskService();
|
taskService = taskanaEngine.getTaskService();
|
||||||
resetDb(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
|
|
@ -67,7 +60,6 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
String tkId4 = "TKI:000000000000000000000000000000000060";
|
String tkId4 = "TKI:000000000000000000000000000000000060";
|
||||||
|
|
||||||
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4);
|
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4);
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
|
||||||
|
|
||||||
Instant planned = getInstant("2020-02-11T07:00:00");
|
Instant planned = getInstant("2020-02-11T07:00:00");
|
||||||
BulkOperationResults<String, TaskanaException> results =
|
BulkOperationResults<String, TaskanaException> results =
|
||||||
|
|
@ -100,7 +92,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4, tkId5);
|
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4, tkId5);
|
||||||
Instant planned = getInstant("2020-04-20T07:00:00");
|
Instant planned = getInstant("2020-04-20T07:00:00");
|
||||||
BulkOperationResults<String, TaskanaException> results =
|
BulkOperationResults<String, TaskanaException> results =
|
||||||
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, taskIds);
|
taskService.setPlannedPropertyOfTasks(planned, taskIds);
|
||||||
assertThat(results.containsErrors()).isTrue();
|
assertThat(results.containsErrors()).isTrue();
|
||||||
assertThat(results.getErrorMap().size()).isEqualTo(1);
|
assertThat(results.getErrorMap().size()).isEqualTo(1);
|
||||||
assertThat(results.getErrorForId("TKI:000000000000000000000000000047110059"))
|
assertThat(results.getErrorForId("TKI:000000000000000000000000000047110059"))
|
||||||
|
|
@ -144,7 +136,6 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
// |TAI:000000000000000000000000000000000007 | CLI:100000000000000000000000000000000008 | P1D |
|
// |TAI:000000000000000000000000000000000007 | CLI:100000000000000000000000000000000008 | P1D |
|
||||||
// +-----------------------------------------+------------------------------------------+------+
|
// +-----------------------------------------+------------------------------------------+------+
|
||||||
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
|
||||||
String tkId0 = "TKI:000000000000000000000000000000000000";
|
String tkId0 = "TKI:000000000000000000000000000000000000";
|
||||||
String tkId1 = "TKI:000000000000000000000000000000000001";
|
String tkId1 = "TKI:000000000000000000000000000000000001";
|
||||||
String tkId2 = "TKI:000000000000000000000000000000000002";
|
String tkId2 = "TKI:000000000000000000000000000000000002";
|
||||||
|
|
@ -209,7 +200,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4);
|
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4);
|
||||||
Instant planned = getInstant("2020-02-25T07:00:00");
|
Instant planned = getInstant("2020-02-25T07:00:00");
|
||||||
BulkOperationResults<String, TaskanaException> results =
|
BulkOperationResults<String, TaskanaException> results =
|
||||||
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, taskIds);
|
taskService.setPlannedPropertyOfTasks(planned, taskIds);
|
||||||
assertThat(results.containsErrors()).isTrue();
|
assertThat(results.containsErrors()).isTrue();
|
||||||
assertThat(results.getErrorMap().size()).isEqualTo(3);
|
assertThat(results.getErrorMap().size()).isEqualTo(3);
|
||||||
assertThat(results.getErrorForId(tkId1)).isInstanceOf(NotAuthorizedException.class);
|
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);
|
List<String> taskIds = Arrays.asList(tkId1, tkId2, tkId3, tkId4);
|
||||||
Instant planned = getInstant("2020-05-03T07:00:00");
|
Instant planned = getInstant("2020-05-03T07:00:00");
|
||||||
BulkOperationResults<String, TaskanaException> results =
|
BulkOperationResults<String, TaskanaException> results =
|
||||||
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, taskIds);
|
taskService.setPlannedPropertyOfTasks(planned, taskIds);
|
||||||
assertThat(results.containsErrors()).isFalse();
|
assertThat(results.containsErrors()).isFalse();
|
||||||
|
|
||||||
Instant dueBulk1 = taskService.getTask(tkId1).getDue();
|
Instant dueBulk1 = taskService.getTask(tkId1).getDue();
|
||||||
|
|
@ -240,9 +231,9 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
Instant dueBulk3 = taskService.getTask(tkId3).getDue();
|
Instant dueBulk3 = taskService.getTask(tkId3).getDue();
|
||||||
Instant dueBulk4 = taskService.getTask(tkId4).getDue();
|
Instant dueBulk4 = taskService.getTask(tkId4).getDue();
|
||||||
assertThat(dueBulk1).isEqualTo(getInstant("2020-05-14T07:00:00"));
|
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(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(
|
@WithAccessId(
|
||||||
|
|
@ -252,7 +243,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
void testSetPlannedPropertyOnEmptyTasksList() {
|
void testSetPlannedPropertyOnEmptyTasksList() {
|
||||||
Instant planned = getInstant("2020-05-03T07:00:00");
|
Instant planned = getInstant("2020-05-03T07:00:00");
|
||||||
BulkOperationResults<String, TaskanaException> results =
|
BulkOperationResults<String, TaskanaException> results =
|
||||||
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, new ArrayList<>());
|
taskService.setPlannedPropertyOfTasks(planned, new ArrayList<>());
|
||||||
assertThat(results.containsErrors()).isFalse();
|
assertThat(results.containsErrors()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,7 +265,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
Instant planned = getInstant("2020-05-03T07:00:00");
|
Instant planned = getInstant("2020-05-03T07:00:00");
|
||||||
// test bulk operation setPlanned...
|
// test bulk operation setPlanned...
|
||||||
BulkOperationResults<String, TaskanaException> results =
|
BulkOperationResults<String, TaskanaException> results =
|
||||||
taskanaEngine.getTaskService().setPlannedPropertyOfTasks(planned, Arrays.asList(taskId));
|
taskService.setPlannedPropertyOfTasks(planned, Arrays.asList(taskId));
|
||||||
Task task = taskService.getTask(taskId);
|
Task task = taskService.getTask(taskId);
|
||||||
assertThat(results.containsErrors()).isFalse();
|
assertThat(results.containsErrors()).isFalse();
|
||||||
DaysToWorkingDaysConverter converter = DaysToWorkingDaysConverter.initialize();
|
DaysToWorkingDaysConverter converter = DaysToWorkingDaysConverter.initialize();
|
||||||
|
|
@ -316,9 +307,10 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
task.setDue(planned.plus(Duration.ofDays(8)));
|
task.setDue(planned.plus(Duration.ofDays(8)));
|
||||||
Task finalTask = task;
|
Task finalTask = task;
|
||||||
assertThatThrownBy(
|
assertThatThrownBy(
|
||||||
() -> {
|
() -> {
|
||||||
taskService.updateTask(finalTask);
|
taskService.updateTask(finalTask);
|
||||||
}).isInstanceOf(InvalidArgumentException.class);
|
})
|
||||||
|
.isInstanceOf(InvalidArgumentException.class);
|
||||||
|
|
||||||
// update due and planned as expected.
|
// update due and planned as expected.
|
||||||
task = taskService.getTask(taskId);
|
task = taskService.getTask(taskId);
|
||||||
|
|
@ -376,50 +368,15 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest {
|
||||||
assertThat(task.getPlanned()).isEqualTo(task.getDue().plus(Duration.ofDays(days)));
|
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(
|
@WithAccessId(
|
||||||
userName = "user_1_2",
|
userName = "user_1_2",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
@Test
|
@Test
|
||||||
void testUpdatePlannedAndDue() throws NotAuthorizedException, TaskNotFoundException {
|
void testUpdatePlannedAndDue() throws NotAuthorizedException, TaskNotFoundException {
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
|
||||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000030");
|
Task task = taskService.getTask("TKI:000000000000000000000000000000000030");
|
||||||
task.setPlanned(getInstant("2020-04-21T07:00:00"));
|
task.setPlanned(getInstant("2020-04-21T07:00:00"));
|
||||||
task.setDue(getInstant("2020-04-21T10:00:00"));
|
task.setDue(getInstant("2020-04-21T10:00:00"));
|
||||||
assertThatThrownBy(() -> taskService.updateTask(task))
|
assertThatThrownBy(() -> taskService.updateTask(task))
|
||||||
.isInstanceOf(InvalidArgumentException.class);
|
.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue