TSK-1257: refactored claimtasks in taskService and increased test coverage
This commit is contained in:
parent
6952ce8959
commit
496da17b3e
|
@ -4,8 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Returning type for a bulk db interaction with errors. This wrapper is storing them with a
|
||||
|
@ -14,10 +12,9 @@ import org.slf4j.LoggerFactory;
|
|||
* @param <K> unique keys for the logs.
|
||||
* @param <V> type of the stored informations
|
||||
*/
|
||||
public class BulkOperationResults<K, V> {
|
||||
public class BulkOperationResults<K, V extends Exception> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BulkOperationResults.class);
|
||||
private Map<K, V> errorMap = new HashMap<>();
|
||||
private final Map<K, V> errorMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Returning a list of current errors as map. If there are no errors the result will be empty.
|
||||
|
@ -29,29 +26,13 @@ public class BulkOperationResults<K, V> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adding an appearing error to the map and list them by a unique ID as key. NULL keys will be
|
||||
* ignored.
|
||||
* Adding an appearing error to the map and list them by a unique ID as key.
|
||||
*
|
||||
* @param objectId unique key of a entity.
|
||||
* @param error occurred error of a interaction with the entity
|
||||
* @return status of adding the values.
|
||||
*/
|
||||
public boolean addError(K objectId, V error) {
|
||||
boolean status = false;
|
||||
try {
|
||||
if (objectId != null) {
|
||||
this.errorMap.put(objectId, error);
|
||||
status = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(
|
||||
"Can´t add bulkoperation-error, because of a map failure. "
|
||||
+ "ID={}, error={} and current failure={}",
|
||||
objectId,
|
||||
error,
|
||||
e);
|
||||
}
|
||||
return status;
|
||||
public void addError(K objectId, V error) {
|
||||
this.errorMap.put(objectId, error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,11 +41,7 @@ public class BulkOperationResults<K, V> {
|
|||
* @return true if there are logged errors.
|
||||
*/
|
||||
public boolean containsErrors() {
|
||||
boolean isContainingErrors = false;
|
||||
if (!this.errorMap.isEmpty()) {
|
||||
isContainingErrors = true;
|
||||
}
|
||||
return isContainingErrors;
|
||||
return !errorMap.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,11 +51,7 @@ public class BulkOperationResults<K, V> {
|
|||
* @return stored error for ID
|
||||
*/
|
||||
public V getErrorForId(K idKey) {
|
||||
V result = null;
|
||||
if (idKey != null) {
|
||||
result = this.errorMap.get(idKey);
|
||||
}
|
||||
return result;
|
||||
return errorMap.get(idKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,12 +73,9 @@ public class BulkOperationResults<K, V> {
|
|||
*
|
||||
* @param log the other log
|
||||
*/
|
||||
public void addAllErrors(BulkOperationResults<K, V> log) {
|
||||
if (log != null && log.containsErrors()) {
|
||||
List<K> failedIds = log.getFailedIds();
|
||||
for (K id : failedIds) {
|
||||
addError(id, log.getErrorForId(id));
|
||||
}
|
||||
public void addAllErrors(BulkOperationResults<? extends K, ? extends V> log) {
|
||||
if (log != null) {
|
||||
errorMap.putAll(log.errorMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,19 +86,12 @@ public class BulkOperationResults<K, V> {
|
|||
*/
|
||||
public BulkOperationResults<K, Exception> mapBulkOperationResults() {
|
||||
BulkOperationResults<K, Exception> bulkLogMapped = new BulkOperationResults<>();
|
||||
|
||||
List<K> failedIds = this.getFailedIds();
|
||||
for (K id : failedIds) {
|
||||
bulkLogMapped.addError(id, (Exception) this.getErrorForId(id));
|
||||
}
|
||||
|
||||
bulkLogMapped.addAllErrors(this);
|
||||
return bulkLogMapped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BulkOperationResults [BulkOperationResults= "
|
||||
+ this.errorMap
|
||||
+ "]";
|
||||
return "BulkOperationResults [errorMap=" + errorMap + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -346,6 +346,16 @@ public interface TaskService {
|
|||
BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds)
|
||||
throws InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Completes a list of tasks.
|
||||
*
|
||||
* @param taskIds of the tasks which should be completed.
|
||||
* @return the result of the operations with Id and Exception for each failed task completion.
|
||||
* @throws InvalidArgumentException If the taskId parameter is NULL.
|
||||
*/
|
||||
BulkOperationResults<String, TaskanaException> forceCompleteTasks(List<String> taskIds)
|
||||
throws InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Updates tasks with a matching {@link ObjectReference}.
|
||||
*
|
||||
|
|
|
@ -17,6 +17,7 @@ import pro.taskana.common.internal.persistence.InstantTypeHandler;
|
|||
import pro.taskana.common.internal.persistence.MapTypeHandler;
|
||||
import pro.taskana.common.internal.util.Pair;
|
||||
import pro.taskana.task.api.CallbackState;
|
||||
import pro.taskana.task.api.models.TaskSummary;
|
||||
import pro.taskana.task.internal.models.MinimalTaskSummary;
|
||||
import pro.taskana.task.internal.models.TaskImpl;
|
||||
import pro.taskana.task.internal.models.TaskSummaryImpl;
|
||||
|
@ -157,12 +158,12 @@ public interface TaskMapper {
|
|||
|
||||
@Update(
|
||||
"<script>"
|
||||
+ " UPDATE TASK SET COMPLETED = #{referencetask.completed}, MODIFIED = #{referencetask.modified}, STATE = #{referencetask.state}"
|
||||
+ " UPDATE TASK SET COMPLETED = #{referenceTask.completed}, MODIFIED = #{referenceTask.modified}, STATE = #{referenceTask.state}"
|
||||
+ " WHERE ID IN <foreach item='taskId' index='index' separator=',' open='(' close=')' collection='taskIds'>#{taskId}</foreach>"
|
||||
+ "</script>")
|
||||
void updateCompleted(
|
||||
@Param("taskIds") List<String> taskIds,
|
||||
@Param("referencetask") TaskSummaryImpl referencetask);
|
||||
@Param("referenceTask") TaskSummary referenceTask);
|
||||
|
||||
@Select(
|
||||
"<script>SELECT ID, EXTERNAL_ID, STATE, WORKBASKET_ID, OWNER, MODIFIED, CLASSIFICATION_ID, "
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.Set;
|
|||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
import org.apache.ibatis.exceptions.PersistenceException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -101,23 +102,22 @@ public class TaskServiceImpl implements TaskService {
|
|||
IntStream.rangeClosed(1, 16).mapToObj(String::valueOf).collect(Collectors.toSet());
|
||||
private static final String TASK_WITH_ID_IS_ALREADY_IN_END_STATE =
|
||||
"Task with Id %s is already in an end state.";
|
||||
private InternalTaskanaEngine taskanaEngine;
|
||||
private WorkbasketService workbasketService;
|
||||
private ClassificationService classificationService;
|
||||
private TaskMapper taskMapper;
|
||||
private AttachmentMapper attachmentMapper;
|
||||
private HistoryEventProducer historyEventProducer;
|
||||
private TaskTransferrer taskTransferrer;
|
||||
private TaskCommentServiceImpl taskCommentService;
|
||||
private ServiceLevelHandler serviceLevelHandler;
|
||||
private AttachmentHandler attachmentHandler;
|
||||
private final InternalTaskanaEngine taskanaEngine;
|
||||
private final WorkbasketService workbasketService;
|
||||
private final ClassificationService classificationService;
|
||||
private final TaskMapper taskMapper;
|
||||
private final AttachmentMapper attachmentMapper;
|
||||
private final HistoryEventProducer historyEventProducer;
|
||||
private final TaskTransferrer taskTransferrer;
|
||||
private final TaskCommentServiceImpl taskCommentService;
|
||||
private final ServiceLevelHandler serviceLevelHandler;
|
||||
private final AttachmentHandler attachmentHandler;
|
||||
|
||||
public TaskServiceImpl(
|
||||
InternalTaskanaEngine taskanaEngine,
|
||||
TaskMapper taskMapper,
|
||||
TaskCommentMapper taskCommentMapper,
|
||||
AttachmentMapper attachmentMapper) {
|
||||
super();
|
||||
this.taskanaEngine = taskanaEngine;
|
||||
this.taskMapper = taskMapper;
|
||||
this.workbasketService = taskanaEngine.getEngine().getWorkbasketService();
|
||||
|
@ -422,7 +422,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
taskanaEngine.openConnection();
|
||||
oldTaskImpl = (TaskImpl) getTask(newTaskImpl.getId());
|
||||
|
||||
newTaskImpl = checkConcurrencyAndSetModified(newTaskImpl, oldTaskImpl);
|
||||
checkConcurrencyAndSetModified(newTaskImpl, oldTaskImpl);
|
||||
|
||||
attachmentHandler.insertAndDeleteAttachmentsOnTaskUpdate(newTaskImpl, oldTaskImpl);
|
||||
ObjectReference.validate(newTaskImpl.getPrimaryObjRef(), "primary ObjectReference", TASK);
|
||||
|
@ -490,6 +490,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
if (taskIds == null) {
|
||||
throw new InvalidArgumentException("List of TaskIds must not be null.");
|
||||
}
|
||||
taskIds = new ArrayList<>(taskIds);
|
||||
|
||||
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||
|
||||
|
@ -514,34 +515,82 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BulkOperationResults<String, TaskanaException> completeTasks(
|
||||
List<String> taskIdsToBeCompleted) throws InvalidArgumentException {
|
||||
public BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds)
|
||||
throws InvalidArgumentException {
|
||||
try {
|
||||
LOGGER.debug("entry to completeTasks(taskIds = {})", taskIdsToBeCompleted);
|
||||
LOGGER.debug("entry to completeTasks(taskIds = {})", taskIds);
|
||||
taskanaEngine.openConnection();
|
||||
|
||||
if (taskIdsToBeCompleted == null || taskIdsToBeCompleted.isEmpty()) {
|
||||
throw new InvalidArgumentException("TaskIds can´t be used as NULL-Parameter.");
|
||||
if (taskIds == null) {
|
||||
throw new InvalidArgumentException("TaskIds can't be used as NULL-Parameter.");
|
||||
}
|
||||
|
||||
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||
List<String> taskIds = new ArrayList<>(taskIdsToBeCompleted);
|
||||
removeNonExistingTasksFromTaskIdList(taskIds, bulkLog);
|
||||
Map<String, TaskSummaryImpl> taskSummaryMap =
|
||||
createTaskQuery().idIn(taskIds.toArray(new String[0])).list().stream()
|
||||
.collect(Collectors.toMap(TaskSummary::getId, e -> (TaskSummaryImpl) e));
|
||||
|
||||
List<TaskSummary> taskSummaries =
|
||||
this.createTaskQuery().idIn(taskIds.toArray(new String[0])).list();
|
||||
Predicate<Pair<String, ? extends TaskSummary>> taskIdNotFound =
|
||||
pair -> {
|
||||
if (pair.getRight() == null) {
|
||||
String taskId = pair.getLeft();
|
||||
bulkLog.addError(
|
||||
taskId,
|
||||
new TaskNotFoundException(
|
||||
taskId, String.format(TASK_WITH_ID_WAS_NOT_FOUND, taskId)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
checkIfTasksMatchCompleteCriteria(taskIds, taskSummaries, bulkLog);
|
||||
Predicate<TaskSummary> stateIsCorrect =
|
||||
summary -> {
|
||||
if (summary.getClaimed() == null || summary.getState() != TaskState.CLAIMED) {
|
||||
bulkLog.addError(summary.getId(), new InvalidStateException(summary.getId()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
updateTasksToBeCompleted(taskIds, taskSummaries);
|
||||
Predicate<TaskSummary> userIsCorrect =
|
||||
summary -> {
|
||||
if (!CurrentUserContext.getAccessIds().contains(summary.getOwner())) {
|
||||
bulkLog.addError(
|
||||
summary.getId(),
|
||||
new InvalidOwnerException(
|
||||
String.format(
|
||||
"TaskOwner is %s, but currentUser is %s.",
|
||||
summary.getOwner(), CurrentUserContext.getUserid())));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Stream<TaskSummaryImpl> filteredSummaries =
|
||||
taskIds.stream()
|
||||
.map(id -> Pair.of(id, taskSummaryMap.get(id)))
|
||||
.filter(taskIdNotFound)
|
||||
.map(Pair::getRight)
|
||||
.filter(stateIsCorrect)
|
||||
.filter(userIsCorrect);
|
||||
|
||||
updateTasksToBeCompleted(filteredSummaries);
|
||||
|
||||
return bulkLog;
|
||||
} finally {
|
||||
taskanaEngine.returnConnection();
|
||||
LOGGER.debug("exit from to completeTasks(taskIds = {})", taskIdsToBeCompleted);
|
||||
LOGGER.debug("exit from to completeTasks(taskIds = {})", taskIds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BulkOperationResults<String, TaskanaException> forceCompleteTasks(List<String> taskIds)
|
||||
throws InvalidArgumentException {
|
||||
|
||||
if (taskIds == null) {
|
||||
throw new InvalidArgumentException("TaskIds can't be used as NULL-Parameter.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> updateTasks(
|
||||
ObjectReference selectionCriteria, Map<String, String> customFieldsToUpdate)
|
||||
|
@ -568,9 +617,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
changedTasks = taskSummaries.stream().map(TaskSummary::getId).collect(Collectors.toList());
|
||||
taskMapper.updateTasks(changedTasks, updated, fieldSelector);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"updateTasks() updated the following tasks: {} ",
|
||||
changedTasks);
|
||||
LOGGER.debug("updateTasks() updated the following tasks: {} ", changedTasks);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -608,9 +655,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
changedTasks = taskSummaries.stream().map(TaskSummary::getId).collect(Collectors.toList());
|
||||
taskMapper.updateTasks(changedTasks, updatedTask, fieldSelector);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"updateTasks() updated the following tasks: {} ",
|
||||
changedTasks);
|
||||
LOGGER.debug("updateTasks() updated the following tasks: {} ", changedTasks);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -661,9 +706,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
public BulkOperationResults<String, TaskanaException> setCallbackStateForTasks(
|
||||
List<String> externalIds, CallbackState state) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to setCallbackStateForTasks(externalIds = {})",
|
||||
externalIds);
|
||||
LOGGER.debug("entry to setCallbackStateForTasks(externalIds = {})", externalIds);
|
||||
}
|
||||
try {
|
||||
taskanaEngine.openConnection();
|
||||
|
@ -694,10 +737,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
public BulkOperationResults<String, TaskanaException> setOwnerOfTasks(
|
||||
String owner, List<String> argTaskIds) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to setOwnerOfTasks(owner = {}, tasks = {})",
|
||||
owner,
|
||||
argTaskIds);
|
||||
LOGGER.debug("entry to setOwnerOfTasks(owner = {}, tasks = {})", owner, argTaskIds);
|
||||
}
|
||||
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||
if (argTaskIds == null || argTaskIds.isEmpty()) {
|
||||
|
@ -748,9 +788,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
Instant planned, List<String> argTaskIds) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to setPlannedPropertyOfTasks(planned = {}, tasks = {})",
|
||||
planned,
|
||||
argTaskIds);
|
||||
"entry to setPlannedPropertyOfTasks(planned = {}, tasks = {})", planned, argTaskIds);
|
||||
}
|
||||
|
||||
BulkLog bulkLog = new BulkLog();
|
||||
|
@ -815,7 +853,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
// tasks indirectly affected via attachments
|
||||
List<Pair<String, Instant>> affectedPairs =
|
||||
tasksAffectedDirectly.stream()
|
||||
.map(t -> new Pair<String, Instant>(t.getId(), t.getPlanned()))
|
||||
.map(t -> Pair.of(t.getId(), t.getPlanned()))
|
||||
.collect(Collectors.toList());
|
||||
// tasks indirectly affected via attachments
|
||||
List<Pair<String, Instant>> taskIdsAndPlannedFromAttachments =
|
||||
|
@ -849,9 +887,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
public void refreshPriorityAndDueDatesOfTasksOnClassificationUpdate(
|
||||
List<String> taskIds, boolean serviceLevelChanged, boolean priorityChanged) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to refreshPriorityAndDueDateOfTasks(tasks = {})",
|
||||
taskIds);
|
||||
LOGGER.debug("entry to refreshPriorityAndDueDateOfTasks(tasks = {})", taskIds);
|
||||
}
|
||||
Pair<List<MinimalTaskSummary>, BulkLog> resultsPair = getMinimalTaskSummaries(taskIds);
|
||||
List<MinimalTaskSummary> tasks = resultsPair.getLeft();
|
||||
|
@ -1008,8 +1044,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
List<TaskSummary> augmentTaskSummariesByContainedSummaries(List<TaskSummaryImpl> taskSummaries) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to augmentTaskSummariesByContainedSummaries(taskSummaries= {})",
|
||||
taskSummaries);
|
||||
"entry to augmentTaskSummariesByContainedSummaries(taskSummaries= {})", taskSummaries);
|
||||
}
|
||||
|
||||
List<TaskSummary> result = new ArrayList<>();
|
||||
|
@ -1039,7 +1074,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
return result;
|
||||
}
|
||||
|
||||
private TaskImpl checkConcurrencyAndSetModified(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)
|
||||
private void checkConcurrencyAndSetModified(TaskImpl newTaskImpl, TaskImpl oldTaskImpl)
|
||||
throws ConcurrencyException {
|
||||
// TODO: not safe to rely only on different timestamps.
|
||||
// With fast execution below 1ms there will be no concurrencyException
|
||||
|
@ -1052,7 +1087,6 @@ public class TaskServiceImpl implements TaskService {
|
|||
throw new ConcurrencyException("The task has already been updated by another user");
|
||||
}
|
||||
newTaskImpl.setModified(Instant.now());
|
||||
return newTaskImpl;
|
||||
}
|
||||
|
||||
private TaskImpl terminateCancelCommonActions(String taskId, TaskState targetState)
|
||||
|
@ -1423,67 +1457,25 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkIfTasksMatchCompleteCriteria(
|
||||
List<String> taskIds,
|
||||
List<TaskSummary> taskSummaries,
|
||||
BulkOperationResults<String, TaskanaException> bulkLog) {
|
||||
private void updateTasksToBeCompleted(Stream<TaskSummaryImpl> taskSummaries) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to checkIfTasksMatchCompleteCriteria(taskIds = {}, "
|
||||
+ "taskSummaries = {}, bulkLog = {})",
|
||||
taskIds,
|
||||
taskSummaries,
|
||||
bulkLog);
|
||||
LOGGER.debug("entry to updateTasksToBeCompleted()");
|
||||
}
|
||||
|
||||
Instant now = Instant.now();
|
||||
Iterator<String> taskIdIterator = taskIds.iterator();
|
||||
while (taskIdIterator.hasNext()) {
|
||||
String currentTaskId = taskIdIterator.next();
|
||||
TaskSummaryImpl taskSummary =
|
||||
(TaskSummaryImpl)
|
||||
taskSummaries.stream()
|
||||
.filter(ts -> currentTaskId.equals(ts.getId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (taskSummary == null) {
|
||||
bulkLog.addError(
|
||||
currentTaskId,
|
||||
new TaskNotFoundException(
|
||||
currentTaskId, String.format(TASK_WITH_ID_WAS_NOT_FOUND, currentTaskId)));
|
||||
taskIdIterator.remove();
|
||||
} else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) {
|
||||
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
|
||||
taskIdIterator.remove();
|
||||
} else if (!CurrentUserContext.getAccessIds().contains(taskSummary.getOwner())) {
|
||||
bulkLog.addError(
|
||||
currentTaskId,
|
||||
new InvalidOwnerException(
|
||||
String.format(
|
||||
"TaskOwner is %s, but currentUser is %s.",
|
||||
taskSummary.getOwner(), CurrentUserContext.getUserid())));
|
||||
taskIdIterator.remove();
|
||||
} else {
|
||||
taskSummary.setCompleted(now);
|
||||
taskSummary.setModified(now);
|
||||
taskSummary.setState(TaskState.COMPLETED);
|
||||
}
|
||||
}
|
||||
LOGGER.debug("exit from checkIfTasksMatchCompleteCriteria()");
|
||||
}
|
||||
List<String> taskIds = new ArrayList<>();
|
||||
List<TaskSummary> taskSummaryList =
|
||||
taskSummaries
|
||||
.peek(summary -> summary.setModified(now))
|
||||
.peek(summary -> summary.setCompleted(now))
|
||||
.peek(summary -> summary.setState(TaskState.COMPLETED))
|
||||
.peek(summary -> taskIds.add(summary.getId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
private void updateTasksToBeCompleted(List<String> taskIds, List<TaskSummary> taskSummaries) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to updateTasksToBeCompleted(taskIds = {}, taskSummaries = {})",
|
||||
taskIds,
|
||||
taskSummaries);
|
||||
}
|
||||
|
||||
if (!taskIds.isEmpty() && !taskSummaries.isEmpty()) {
|
||||
taskMapper.updateCompleted(taskIds, (TaskSummaryImpl) taskSummaries.get(0));
|
||||
if (!taskSummaryList.isEmpty()) {
|
||||
taskMapper.updateCompleted(taskIds, taskSummaryList.get(0));
|
||||
if (HistoryEventProducer.isHistoryEnabled()) {
|
||||
createTasksCompletedEvents(taskSummaries);
|
||||
createTasksCompletedEvents(taskSummaryList);
|
||||
}
|
||||
}
|
||||
LOGGER.debug("exit from updateTasksToBeCompleted()");
|
||||
|
@ -1494,7 +1486,8 @@ public class TaskServiceImpl implements TaskService {
|
|||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to addClassificationSummariesToTaskSummaries(tasks = {}, classifications = {})",
|
||||
tasks, classifications);
|
||||
tasks,
|
||||
classifications);
|
||||
}
|
||||
|
||||
if (tasks == null || tasks.isEmpty()) {
|
||||
|
@ -1738,8 +1731,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
throws InvalidArgumentException {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(
|
||||
"entry to validateCustomFields(customFieldsToUpdate = {})",
|
||||
customFieldsToUpdate);
|
||||
"entry to validateCustomFields(customFieldsToUpdate = {})", customFieldsToUpdate);
|
||||
}
|
||||
|
||||
if (customFieldsToUpdate == null || customFieldsToUpdate.isEmpty()) {
|
||||
|
@ -1825,7 +1817,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
}
|
||||
|
||||
private void createTasksCompletedEvents(List<TaskSummary> taskSummaries) {
|
||||
private void createTasksCompletedEvents(List<? extends TaskSummary> taskSummaries) {
|
||||
taskSummaries.forEach(
|
||||
task ->
|
||||
historyEventProducer.createEvent(
|
||||
|
|
|
@ -6,14 +6,19 @@ 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.Collections;
|
||||
import java.util.List;
|
||||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import pro.taskana.classification.api.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.common.api.BulkOperationResults;
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.common.api.exceptions.NotAuthorizedException;
|
||||
import pro.taskana.common.api.exceptions.TaskanaException;
|
||||
import pro.taskana.common.internal.security.CurrentUserContext;
|
||||
import pro.taskana.common.internal.security.JaasExtension;
|
||||
import pro.taskana.common.internal.security.WithAccessId;
|
||||
|
@ -31,20 +36,16 @@ import pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException;
|
|||
@ExtendWith(JaasExtension.class)
|
||||
class CompleteTaskAccTest extends AbstractAccTest {
|
||||
|
||||
CompleteTaskAccTest() {
|
||||
super();
|
||||
}
|
||||
private static final TaskService TASK_SERVICE = taskanaEngine.getTaskService();
|
||||
|
||||
@WithAccessId(user = "user-1-1", groups = "group-1")
|
||||
@Test
|
||||
void testCompleteTask()
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException,
|
||||
NotAuthorizedException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
assertThat(taskService.getTask("TKI:000000000000000000000000000000000001").getState())
|
||||
assertThat(TASK_SERVICE.getTask("TKI:000000000000000000000000000000000001").getState())
|
||||
.isEqualTo(TaskState.CLAIMED);
|
||||
Task completedTask = taskService.completeTask("TKI:000000000000000000000000000000000001");
|
||||
Task completedTask = TASK_SERVICE.completeTask("TKI:000000000000000000000000000000000001");
|
||||
assertThat(completedTask).isNotNull();
|
||||
assertThat(completedTask.getCompleted()).isNotNull();
|
||||
assertThat(completedTask.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
|
@ -57,13 +58,11 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
void should_ForceCompleteTask_When_NoExplicitPermissionsButUserIsInAdministrativeRole()
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException,
|
||||
NotAuthorizedException, SQLException {
|
||||
|
||||
resetDb(false);
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
assertThat(taskService.getTask("TKI:000000000000000000000000000000000000").getState())
|
||||
assertThat(TASK_SERVICE.getTask("TKI:000000000000000000000000000000000000").getState())
|
||||
.isEqualTo(TaskState.CLAIMED);
|
||||
Task completedTask = taskService.forceCompleteTask("TKI:000000000000000000000000000000000000");
|
||||
Task completedTask = TASK_SERVICE.forceCompleteTask("TKI:000000000000000000000000000000000000");
|
||||
assertThat(completedTask).isNotNull();
|
||||
assertThat(completedTask.getCompleted()).isNotNull();
|
||||
assertThat(completedTask.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
|
@ -75,9 +74,8 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
void testCompleteTaskTwice()
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException,
|
||||
NotAuthorizedException {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task completedTask = taskService.completeTask("TKI:000000000000000000000000000000000002");
|
||||
Task completedTask2 = taskService.completeTask("TKI:000000000000000000000000000000000002");
|
||||
Task completedTask = TASK_SERVICE.completeTask("TKI:000000000000000000000000000000000002");
|
||||
Task completedTask2 = TASK_SERVICE.completeTask("TKI:000000000000000000000000000000000002");
|
||||
assertThat(completedTask2).isEqualTo(completedTask);
|
||||
}
|
||||
|
||||
|
@ -87,9 +85,7 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException,
|
||||
InvalidOwnerException, InvalidStateException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task newTask = taskService.newTask("USER-1-1", "DOMAIN_A");
|
||||
Task newTask = TASK_SERVICE.newTask("USER-1-1", "DOMAIN_A");
|
||||
newTask.setClassificationKey("T2100");
|
||||
newTask.setOwner("other");
|
||||
newTask.setPrimaryObjRef(
|
||||
|
@ -98,12 +94,12 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
newTaskImpl.setState(TaskState.CLAIMED);
|
||||
newTaskImpl.setClaimed(Instant.now());
|
||||
|
||||
Task createdTask = taskService.createTask(newTaskImpl);
|
||||
Task completedTask = taskService.forceCompleteTask(createdTask.getId());
|
||||
Task createdTask = TASK_SERVICE.createTask(newTaskImpl);
|
||||
Task completedTask = TASK_SERVICE.forceCompleteTask(createdTask.getId());
|
||||
|
||||
assertThat(completedTask.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
assertThat(completedTask.getCompleted()).isNotNull();
|
||||
assertThat(isBeforeOrEqual(completedTask.getCreated(), completedTask.getModified())).isTrue();
|
||||
assertThat(completedTask.getCreated()).isBeforeOrEqualTo(completedTask.getModified());
|
||||
assertThat(completedTask.getCompleted()).isEqualTo(completedTask.getModified());
|
||||
}
|
||||
|
||||
|
@ -113,9 +109,7 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException,
|
||||
InvalidOwnerException, InvalidStateException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task newTask = taskService.newTask("USER-1-1", "DOMAIN_A");
|
||||
Task newTask = TASK_SERVICE.newTask("USER-1-1", "DOMAIN_A");
|
||||
newTask.setClassificationKey("T2100");
|
||||
newTask.setOwner("other");
|
||||
newTask.setPrimaryObjRef(
|
||||
|
@ -123,41 +117,39 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
TaskImpl newTaskImpl = (TaskImpl) newTask;
|
||||
newTaskImpl.setClaimed(Instant.now());
|
||||
|
||||
Task createdTask = taskService.createTask(newTaskImpl);
|
||||
Task completedTask = taskService.forceCompleteTask(createdTask.getId());
|
||||
Task createdTask = TASK_SERVICE.createTask(newTaskImpl);
|
||||
Task completedTask = TASK_SERVICE.forceCompleteTask(createdTask.getId());
|
||||
|
||||
assertThat(completedTask.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
assertThat(completedTask.getCompleted()).isNotNull();
|
||||
assertThat(isBeforeOrEqual(completedTask.getCreated(), completedTask.getModified())).isTrue();
|
||||
assertThat(completedTask.getCreated()).isBeforeOrEqualTo(completedTask.getModified());
|
||||
assertThat(completedTask.getCompleted()).isEqualTo(completedTask.getModified());
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1", groups = "group-1")
|
||||
@Test
|
||||
void testCompleteTaskThrowsErrors() {
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.completeTask("TKI:0000000000000000000000000000000000xx");
|
||||
TASK_SERVICE.completeTask("TKI:0000000000000000000000000000000000xx");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(TaskNotFoundException.class);
|
||||
|
||||
call =
|
||||
() -> {
|
||||
taskService.completeTask("TKI:000000000000000000000000000000000004");
|
||||
TASK_SERVICE.completeTask("TKI:000000000000000000000000000000000004");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(NotAuthorizedException.class);
|
||||
|
||||
call =
|
||||
() -> {
|
||||
taskService.completeTask("TKI:000000000000000000000000000000000025");
|
||||
TASK_SERVICE.completeTask("TKI:000000000000000000000000000000000025");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(InvalidStateException.class);
|
||||
|
||||
call =
|
||||
() -> {
|
||||
taskService.completeTask("TKI:000000000000000000000000000000000027");
|
||||
TASK_SERVICE.completeTask("TKI:000000000000000000000000000000000027");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(InvalidOwnerException.class);
|
||||
}
|
||||
|
@ -168,27 +160,25 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task newTask = taskService.newTask("USER-1-1", "DOMAIN_A");
|
||||
Task newTask = TASK_SERVICE.newTask("USER-1-1", "DOMAIN_A");
|
||||
newTask.setClassificationKey("T2100");
|
||||
newTask.setPrimaryObjRef(
|
||||
createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||
newTask.setOwner(null);
|
||||
Task createdTask = taskService.createTask(newTask);
|
||||
Task createdTask = TASK_SERVICE.createTask(newTask);
|
||||
|
||||
assertThat(createdTask).isNotNull();
|
||||
assertThat(createdTask.getClaimed()).isNull();
|
||||
|
||||
final Instant before = createdTask.getCreated();
|
||||
Task claimedTask = taskService.claim(createdTask.getId());
|
||||
Task claimedTask = TASK_SERVICE.claim(createdTask.getId());
|
||||
|
||||
assertThat(claimedTask.getOwner()).isNotNull();
|
||||
assertThat(CurrentUserContext.getUserid()).isEqualTo(claimedTask.getOwner());
|
||||
assertThat(claimedTask.getClaimed()).isNotNull();
|
||||
assertThat(isBeforeOrEqual(before, claimedTask.getClaimed())).isTrue();
|
||||
assertThat(isBeforeOrEqual(claimedTask.getCreated(), claimedTask.getClaimed())).isTrue();
|
||||
assertThat(isBeforeOrEqual(claimedTask.getClaimed(), Instant.now())).isTrue();
|
||||
assertThat(before).isBeforeOrEqualTo(claimedTask.getClaimed());
|
||||
assertThat(claimedTask.getCreated()).isBeforeOrEqualTo(claimedTask.getClaimed());
|
||||
assertThat(claimedTask.getClaimed()).isBeforeOrEqualTo(Instant.now());
|
||||
assertThat(claimedTask.getModified()).isEqualTo(claimedTask.getClaimed());
|
||||
}
|
||||
|
||||
|
@ -198,25 +188,23 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task newTask = taskService.newTask("USER-1-1", "DOMAIN_A");
|
||||
Task newTask = TASK_SERVICE.newTask("USER-1-1", "DOMAIN_A");
|
||||
newTask.setClassificationKey("T2100");
|
||||
newTask.setPrimaryObjRef(
|
||||
createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||
newTask.setOwner("other_user");
|
||||
Task createdTask = taskService.createTask(newTask);
|
||||
Task createdTask = TASK_SERVICE.createTask(newTask);
|
||||
|
||||
assertThat(createdTask).isNotNull();
|
||||
assertThat("other_user").isEqualTo(createdTask.getOwner());
|
||||
|
||||
Instant beforeForceClaim = Instant.now();
|
||||
Task taskAfterClaim = taskService.forceClaim(createdTask.getId());
|
||||
Task taskAfterClaim = TASK_SERVICE.forceClaim(createdTask.getId());
|
||||
|
||||
assertThat(taskAfterClaim.getOwner()).isEqualTo(CurrentUserContext.getUserid());
|
||||
assertThat(isBeforeOrEqual(beforeForceClaim, taskAfterClaim.getModified())).isTrue();
|
||||
assertThat(isBeforeOrEqual(beforeForceClaim, taskAfterClaim.getClaimed())).isTrue();
|
||||
assertThat(isBeforeOrEqual(taskAfterClaim.getCreated(), taskAfterClaim.getModified())).isTrue();
|
||||
assertThat(beforeForceClaim).isBeforeOrEqualTo(taskAfterClaim.getModified());
|
||||
assertThat(beforeForceClaim).isBeforeOrEqualTo(taskAfterClaim.getClaimed());
|
||||
assertThat(taskAfterClaim.getCreated()).isBeforeOrEqualTo(taskAfterClaim.getModified());
|
||||
|
||||
assertThat(taskAfterClaim.getState()).isEqualTo(TaskState.CLAIMED);
|
||||
assertThat(taskAfterClaim.isRead()).isTrue();
|
||||
|
@ -225,11 +213,9 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
@WithAccessId(user = "user-1-1", groups = "group-1")
|
||||
@Test
|
||||
void testClaimTaskNotExisting() {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.claim("NOT_EXISTING");
|
||||
TASK_SERVICE.claim("NOT_EXISTING");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(TaskNotFoundException.class);
|
||||
}
|
||||
|
@ -237,11 +223,9 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
@WithAccessId(user = "user-1-1", groups = "group-1")
|
||||
@Test
|
||||
void testClaimTaskWithInvalidState() {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.forceClaim("TKI:000000000000000000000000000000000036");
|
||||
TASK_SERVICE.forceClaim("TKI:000000000000000000000000000000000036");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(InvalidStateException.class);
|
||||
}
|
||||
|
@ -249,11 +233,9 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
@WithAccessId(user = "user-1-1", groups = "group-1")
|
||||
@Test
|
||||
void testClaimTaskWithInvalidOwner() {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.claim("TKI:000000000000000000000000000000000100");
|
||||
TASK_SERVICE.claim("TKI:000000000000000000000000000000000100");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(InvalidOwnerException.class);
|
||||
}
|
||||
|
@ -261,11 +243,9 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
@WithAccessId(user = "user-1-1", groups = "group-1")
|
||||
@Test
|
||||
void testCancelClaimForcedWithInvalidState() {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.forceCancelClaim("TKI:000000000000000000000000000000000036");
|
||||
TASK_SERVICE.forceCancelClaim("TKI:000000000000000000000000000000000036");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(InvalidStateException.class);
|
||||
}
|
||||
|
@ -276,18 +256,16 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException,
|
||||
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException,
|
||||
InvalidStateException, InvalidOwnerException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task newTask = taskService.newTask("USER-1-1", "DOMAIN_A");
|
||||
Task newTask = TASK_SERVICE.newTask("USER-1-1", "DOMAIN_A");
|
||||
newTask.setClassificationKey("T2100");
|
||||
newTask.setPrimaryObjRef(
|
||||
createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||
Task createdTask = taskService.createTask(newTask);
|
||||
Task createdTask = TASK_SERVICE.createTask(newTask);
|
||||
|
||||
assertThat(createdTask).isNotNull();
|
||||
assertThat(TaskState.READY).isEqualTo(createdTask.getState());
|
||||
|
||||
createdTask = taskService.cancelClaim(createdTask.getId());
|
||||
createdTask = TASK_SERVICE.cancelClaim(createdTask.getId());
|
||||
|
||||
assertThat(createdTask).isNotNull();
|
||||
assertThat(TaskState.READY).isEqualTo(createdTask.getState());
|
||||
|
@ -298,16 +276,14 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
void testForceCancelClaimSuccessfull()
|
||||
throws TaskNotFoundException, InvalidStateException, InvalidOwnerException,
|
||||
NotAuthorizedException, InterruptedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task taskBefore = taskService.getTask("TKI:000000000000000000000000000000000043");
|
||||
Task taskBefore = TASK_SERVICE.getTask("TKI:000000000000000000000000000000000043");
|
||||
|
||||
assertThat(taskBefore).isNotNull();
|
||||
assertThat(taskBefore.getState()).isEqualTo(TaskState.CLAIMED);
|
||||
|
||||
final Instant before = Instant.now();
|
||||
Thread.sleep(1);
|
||||
Task taskAfter = taskService.forceCancelClaim("TKI:000000000000000000000000000000000043");
|
||||
Task taskAfter = TASK_SERVICE.forceCancelClaim("TKI:000000000000000000000000000000000043");
|
||||
|
||||
assertThat(taskAfter).isNotNull();
|
||||
assertThat(taskAfter.getState()).isEqualTo(TaskState.READY);
|
||||
|
@ -320,16 +296,103 @@ class CompleteTaskAccTest extends AbstractAccTest {
|
|||
@WithAccessId(user = "user-1-1", groups = "group-1")
|
||||
@Test
|
||||
void testCancelClaimWithInvalidOwner() {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.cancelClaim("TKI:000000000000000000000000000000000100");
|
||||
TASK_SERVICE.cancelClaim("TKI:000000000000000000000000000000000100");
|
||||
};
|
||||
assertThatThrownBy(call).isInstanceOf(InvalidOwnerException.class);
|
||||
}
|
||||
|
||||
private boolean isBeforeOrEqual(Instant before, Instant after) {
|
||||
return before.isBefore(after) || before.equals(after);
|
||||
@Test
|
||||
void should_ThrowException_When_BulkUpdateWithNullList() {
|
||||
assertThatThrownBy(() -> TASK_SERVICE.completeTasks(null))
|
||||
.isInstanceOf(InvalidArgumentException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2")
|
||||
@Test
|
||||
void should_CompleteAllTasks_When_BulkCompletingTasks() throws Exception {
|
||||
String id1 = "TKI:000000000000000000000000000000000102";
|
||||
String id2 = "TKI:000000000000000000000000000000000101";
|
||||
List<String> taskIdList = Arrays.asList(id1, id2);
|
||||
|
||||
Instant beforeBulkComplete = Instant.now();
|
||||
BulkOperationResults<String, TaskanaException> results = TASK_SERVICE.completeTasks(taskIdList);
|
||||
|
||||
assertThat(results.containsErrors()).isFalse();
|
||||
Task completedTask1 = TASK_SERVICE.getTask(id1);
|
||||
assertThat(completedTask1.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
assertThat(completedTask1.getCompleted())
|
||||
.isEqualTo(completedTask1.getModified())
|
||||
.isAfter(beforeBulkComplete);
|
||||
Task completedTask2 = TASK_SERVICE.getTask(id2);
|
||||
assertThat(completedTask2.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
assertThat(completedTask2.getCompleted())
|
||||
.isEqualTo(completedTask2.getModified())
|
||||
.isAfter(beforeBulkComplete);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2")
|
||||
@Test
|
||||
void should_CompleteValidTasksEvenIfErrorsExist_When_BulkCompletingTasks() throws Exception {
|
||||
String invalid = "invalid-id";
|
||||
String validId = "TKI:000000000000000000000000000000000103";
|
||||
List<String> taskIdList = Arrays.asList(invalid, validId);
|
||||
|
||||
Instant beforeBulkComplete = Instant.now();
|
||||
BulkOperationResults<String, TaskanaException> results = TASK_SERVICE.completeTasks(taskIdList);
|
||||
|
||||
assertThat(results.containsErrors()).isTrue();
|
||||
Task completedTask2 = TASK_SERVICE.getTask(validId);
|
||||
assertThat(completedTask2.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
assertThat(completedTask2.getCompleted())
|
||||
.isEqualTo(completedTask2.getModified())
|
||||
.isAfter(beforeBulkComplete);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2")
|
||||
@Test
|
||||
void should_AddErrorsForInvalidTaskIds_When_BulkCompletingTasks() throws Exception {
|
||||
String invalid1 = "";
|
||||
String invalid2 = null;
|
||||
String invalid3 = "invalid-id";
|
||||
String notAuthorized = "TKI:000000000000000000000000000000000002";
|
||||
List<String> taskIdList = Arrays.asList(invalid1, invalid2, invalid3, notAuthorized);
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = TASK_SERVICE.completeTasks(taskIdList);
|
||||
|
||||
assertThat(results.containsErrors()).isTrue();
|
||||
assertThat(results.getFailedIds())
|
||||
.containsExactlyInAnyOrder(invalid1, invalid2, invalid3, notAuthorized);
|
||||
assertThat(results.getErrorMap().values()).hasOnlyElementsOfType(TaskNotFoundException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2")
|
||||
@Test
|
||||
void should_AddErrorForTaskWhichIsNotClaimed_When_BulkCompletingTasks() throws Exception {
|
||||
String id1 = "TKI:000000000000000000000000000000000033"; // task is not claimed
|
||||
String id2 = "TKI:000000000000000000000000000000000036"; // task is completed
|
||||
String id3 = "TKI:300000000000000000000000000000000000"; // task is canceled
|
||||
String id4 = "TKI:300000000000000000000000000000000010"; // task is terminated
|
||||
List<String> taskIdList = Arrays.asList(id1, id2, id3, id4);
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = TASK_SERVICE.completeTasks(taskIdList);
|
||||
|
||||
assertThat(results.containsErrors()).isTrue();
|
||||
assertThat(results.getFailedIds()).containsExactlyInAnyOrder(id1, id2, id3, id4);
|
||||
assertThat(results.getErrorForId(id1)).isInstanceOf(InvalidStateException.class);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2", groups = "group-1")
|
||||
@Test
|
||||
void should_AddErrorForTaskIfOwnerDoesNotMach_When_BulkCompletingTasks() throws Exception {
|
||||
String id1 = "TKI:000000000000000000000000000000000002";
|
||||
List<String> taskIdList = Collections.singletonList(id1);
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = TASK_SERVICE.completeTasks(taskIdList);
|
||||
|
||||
assertThat(results.containsErrors()).isTrue();
|
||||
assertThat(results.getFailedIds()).containsExactlyInAnyOrder(id1);
|
||||
assertThat(results.getErrorForId(id1)).isInstanceOf(InvalidOwnerException.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package acceptance.task;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.util.IterableUtil.toArray;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.util.Comparator;
|
||||
|
@ -86,10 +85,9 @@ class QueryTaskWithAttachmentAccTest extends AbstractAccTest {
|
|||
|
||||
assertThat(queryAttachmentSummaries)
|
||||
.hasSize(originalAttachments.size())
|
||||
.containsOnly(toArray(originalAttachments)) // same values
|
||||
.containsExactlyElementsOf(originalAttachments) // same values
|
||||
.usingElementComparator(REFERENCE_COMPARATOR)
|
||||
.doesNotContain(
|
||||
toArray(originalAttachments)); // but not same reference
|
||||
.doesNotContainAnyElementsOf(originalAttachments); // but not same reference
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-1", groups = "group-1")
|
||||
|
@ -115,9 +113,8 @@ class QueryTaskWithAttachmentAccTest extends AbstractAccTest {
|
|||
|
||||
assertThat(queryAttachmentSummaries)
|
||||
.hasSize(originalAttachments.size())
|
||||
.containsOnly(toArray(originalAttachments)) // same values
|
||||
.containsExactlyElementsOf(originalAttachments) // same values
|
||||
.usingElementComparator(REFERENCE_COMPARATOR)
|
||||
.doesNotContain(
|
||||
toArray(originalAttachments)); // but not same reference
|
||||
.doesNotContainAnyElementsOf(originalAttachments); // but not same reference
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|||
import acceptance.AbstractAccTest;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
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;
|
||||
|
@ -29,10 +29,6 @@ import pro.taskana.task.api.models.Task;
|
|||
@ExtendWith(JaasExtension.class)
|
||||
class WorkOnTaskAccTest extends AbstractAccTest {
|
||||
|
||||
WorkOnTaskAccTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2", groups = "group-1")
|
||||
@Test
|
||||
void testClaimTask()
|
||||
|
@ -60,8 +56,6 @@ class WorkOnTaskAccTest extends AbstractAccTest {
|
|||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000026");
|
||||
|
||||
// Assertions.assertThrows(InvalidOwnerException.class, () ->
|
||||
// taskService.claim(task.getId()));
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.claim(task.getId());
|
||||
|
@ -87,8 +81,6 @@ class WorkOnTaskAccTest extends AbstractAccTest {
|
|||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000028");
|
||||
|
||||
// Assertions.assertThrows(InvalidOwnerException.class, () ->
|
||||
// taskService.claim(task.getId()));
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.claim(task.getId());
|
||||
|
@ -121,8 +113,6 @@ class WorkOnTaskAccTest extends AbstractAccTest {
|
|||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000030");
|
||||
|
||||
// Assertions.assertThrows(
|
||||
// InvalidOwnerException.class, () -> taskService.cancelClaim(claimedTask.getId()));
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.cancelClaim(claimedTask.getId());
|
||||
|
@ -196,8 +186,6 @@ class WorkOnTaskAccTest extends AbstractAccTest {
|
|||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task claimedTask = taskService.getTask("TKI:000000000000000000000000000000000034");
|
||||
|
||||
// Assertions.assertThrows(
|
||||
// InvalidOwnerException.class, () -> taskService.completeTask(claimedTask.getId()));
|
||||
ThrowingCallable call =
|
||||
() -> {
|
||||
taskService.completeTask(claimedTask.getId());
|
||||
|
@ -224,47 +212,20 @@ class WorkOnTaskAccTest extends AbstractAccTest {
|
|||
assertThat(completedTask.getOwner()).isEqualTo("user-1-2");
|
||||
}
|
||||
|
||||
@WithAccessId(user = "user-1-2", groups = "group-1")
|
||||
@Test
|
||||
void testBulkCompleteTasks()
|
||||
throws NotAuthorizedException, InvalidArgumentException, TaskNotFoundException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
List<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000100");
|
||||
taskIdList.add("TKI:000000000000000000000000000000000101");
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.completeTasks(taskIdList);
|
||||
|
||||
assertThat(results.containsErrors()).isFalse();
|
||||
Task completedTask1 = taskService.getTask("TKI:000000000000000000000000000000000100");
|
||||
assertThat(completedTask1.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
assertThat(completedTask1.getCompleted()).isNotNull();
|
||||
Task completedTask2 = taskService.getTask("TKI:000000000000000000000000000000000101");
|
||||
assertThat(completedTask2.getState()).isEqualTo(TaskState.COMPLETED);
|
||||
assertThat(completedTask2.getCompleted()).isNotNull();
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin")
|
||||
@Test
|
||||
void testBulkDeleteTasksWithException() throws InvalidArgumentException, NotAuthorizedException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
List<String> taskIdList = new ArrayList<>();
|
||||
taskIdList.add("TKI:000000000000000000000000000000000102");
|
||||
taskIdList.add("TKI:000000000000000000000000000000003333");
|
||||
String id1 = "TKI:000000000000000000000000000000000102";
|
||||
String id2 = "TKI:000000000000000000000000000000003333";
|
||||
List<String> taskIdList = Arrays.asList(id1, id2);
|
||||
|
||||
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||
|
||||
assertThat(results.containsErrors()).isTrue();
|
||||
assertThat(results.getErrorMap()).hasSize(2);
|
||||
assertThat(
|
||||
results.getErrorForId("TKI:000000000000000000000000000000003333")
|
||||
instanceof TaskNotFoundException)
|
||||
.isTrue();
|
||||
assertThat(
|
||||
results.getErrorForId("TKI:000000000000000000000000000000000102")
|
||||
instanceof InvalidStateException)
|
||||
.isTrue();
|
||||
assertThat(results.getFailedIds()).containsExactlyInAnyOrder(id1, id2);
|
||||
assertThat(results.getErrorForId(id1)).isInstanceOf(InvalidStateException.class);
|
||||
assertThat(results.getErrorForId(id2)).isInstanceOf(TaskNotFoundException.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,11 @@ package acceptance.workbasket;
|
|||
|
||||
import static java.lang.String.CASE_INSENSITIVE_ORDER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.util.IterableUtil.toArray;
|
||||
import static pro.taskana.common.api.BaseQuery.SortDirection.ASCENDING;
|
||||
import static pro.taskana.common.api.BaseQuery.SortDirection.DESCENDING;
|
||||
import static pro.taskana.workbasket.api.WorkbasketQueryColumnName.NAME;
|
||||
|
||||
import acceptance.AbstractAccTest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
@ -327,23 +325,21 @@ class QueryWorkbasketAccTest extends AbstractAccTest {
|
|||
.orderByDomain(ASCENDING)
|
||||
.list();
|
||||
|
||||
ArrayList<String> expectedIds =
|
||||
new ArrayList<>(
|
||||
Arrays.asList(
|
||||
"WBI:100000000000000000000000000000000001",
|
||||
"WBI:100000000000000000000000000000000002",
|
||||
"WBI:100000000000000000000000000000000004",
|
||||
"WBI:100000000000000000000000000000000005",
|
||||
"WBI:100000000000000000000000000000000006",
|
||||
"WBI:100000000000000000000000000000000007",
|
||||
"WBI:100000000000000000000000000000000008",
|
||||
"WBI:100000000000000000000000000000000009",
|
||||
"WBI:100000000000000000000000000000000010",
|
||||
"WBI:100000000000000000000000000000000012"));
|
||||
List<String> expectedIds =
|
||||
Arrays.asList(
|
||||
"WBI:100000000000000000000000000000000001",
|
||||
"WBI:100000000000000000000000000000000002",
|
||||
"WBI:100000000000000000000000000000000004",
|
||||
"WBI:100000000000000000000000000000000005",
|
||||
"WBI:100000000000000000000000000000000006",
|
||||
"WBI:100000000000000000000000000000000007",
|
||||
"WBI:100000000000000000000000000000000008",
|
||||
"WBI:100000000000000000000000000000000009",
|
||||
"WBI:100000000000000000000000000000000010",
|
||||
"WBI:100000000000000000000000000000000012");
|
||||
assertThat(results)
|
||||
.hasSize(10)
|
||||
.extracting(WorkbasketSummary::getId)
|
||||
.containsOnly(toArray(expectedIds));
|
||||
.containsExactlyInAnyOrderElementsOf(expectedIds);
|
||||
}
|
||||
|
||||
@WithAccessId(user = "admin", groups = "group-1")
|
||||
|
|
|
@ -81,7 +81,7 @@ class ClassificationDefinitionControllerIntTest {
|
|||
assertThat(response.getBody()).isNotNull();
|
||||
assertThat(response.getBody().getContent())
|
||||
.extracting(ClassificationRepresentationModel::getClassificationId)
|
||||
.containsOnlyOnce(
|
||||
.containsExactlyInAnyOrder(
|
||||
"CLI:200000000000000000000000000000000015",
|
||||
"CLI:200000000000000000000000000000000017",
|
||||
"CLI:200000000000000000000000000000000018",
|
||||
|
|
|
@ -265,7 +265,7 @@ class TaskRepresentationModelAssemberTest {
|
|||
assertThat(repModels)
|
||||
.hasSize(attachments.size())
|
||||
.extracting(AttachmentRepresentationModel::getAttachmentId)
|
||||
.containsOnlyOnce(objects);
|
||||
.containsExactlyInAnyOrder(objects);
|
||||
}
|
||||
|
||||
private void testLinks(TaskRepresentationModel repModel) {
|
||||
|
|
|
@ -69,7 +69,7 @@ class WorkbasketDefinitionRepresentationModelAssemblerTest {
|
|||
assertThat(repModel.getWorkbasket()).isNotNull();
|
||||
// accessItemAssembler does the conversion. Thus no further testing needed.
|
||||
assertThat(repModel.getAuthorizations()).hasSize(2);
|
||||
assertThat(repModel.getDistributionTargets()).containsOnlyOnce("target1", "target2");
|
||||
assertThat(repModel.getDistributionTargets()).containsExactlyInAnyOrder("target1", "target2");
|
||||
InOrder inOrder = Mockito.inOrder(mocks);
|
||||
inOrder.verify(workbasketAssembler).toModel(workbasket);
|
||||
inOrder.verify(workbasketService).getWorkbasketAccessItems(id);
|
||||
|
|
Loading…
Reference in New Issue