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