TSK-259 delete Task single and bulk
This commit is contained in:
parent
4969f8b165
commit
62defd1c08
|
|
@ -289,4 +289,39 @@ public interface TaskService {
|
||||||
*/
|
*/
|
||||||
BulkOperationResults<String, TaskanaException> transferBulk(String destinationWorkbasketKey, List<String> taskIds)
|
BulkOperationResults<String, TaskanaException> transferBulk(String destinationWorkbasketKey, List<String> taskIds)
|
||||||
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException;
|
throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the task with the given Id.
|
||||||
|
*
|
||||||
|
* @param taskId
|
||||||
|
* The Id of the task to delete.
|
||||||
|
* @throws TaskNotFoundException
|
||||||
|
* If the given Id does not refer to an existing task.
|
||||||
|
* @throws InvalidStateException
|
||||||
|
* If the state of the referenced task is not Completed.
|
||||||
|
*/
|
||||||
|
void deleteTask(String taskId) throws TaskNotFoundException, InvalidStateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the task with the given Id.
|
||||||
|
*
|
||||||
|
* @param taskId
|
||||||
|
* The Id of the task to delete.
|
||||||
|
* @param forceDelete
|
||||||
|
* force the deletion. If true, a task is deleted even if it is not in state completed.
|
||||||
|
* @throws TaskNotFoundException
|
||||||
|
* If the given Id does not refer to an existing task.
|
||||||
|
* @throws InvalidStateException
|
||||||
|
* If the state of the referenced task is not Completed and forceDelet is false.
|
||||||
|
*/
|
||||||
|
void deleteTask(String taskId, boolean forceDelete) throws TaskNotFoundException, InvalidStateException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a list of tasks.
|
||||||
|
*
|
||||||
|
* @param tasks
|
||||||
|
* the ids of the tasks to delete.
|
||||||
|
* @return the result of the operations with Id and Exception for each failed task deletion.
|
||||||
|
*/
|
||||||
|
BulkOperationResults<String, TaskanaException> deleteTasks(List<String> tasks);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package pro.taskana.impl;
|
package pro.taskana.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
@ -17,7 +18,7 @@ import org.slf4j.LoggerFactory;
|
||||||
*/
|
*/
|
||||||
public class BulkOperationResults<K, V> {
|
public class BulkOperationResults<K, V> {
|
||||||
|
|
||||||
private Optional<Map<K, V>> errorMap = Optional.of(new HashMap<K, V>());
|
private Map<K, V> errorMap = new HashMap<K, V>();
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(BulkOperationResults.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(BulkOperationResults.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,7 +27,7 @@ public class BulkOperationResults<K, V> {
|
||||||
* @return map of errors which can´t be null.
|
* @return map of errors which can´t be null.
|
||||||
*/
|
*/
|
||||||
public Map<K, V> getErrorMap() {
|
public Map<K, V> getErrorMap() {
|
||||||
return this.errorMap.get();
|
return this.errorMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,7 +43,7 @@ public class BulkOperationResults<K, V> {
|
||||||
boolean status = false;
|
boolean status = false;
|
||||||
try {
|
try {
|
||||||
if (objectId != null) {
|
if (objectId != null) {
|
||||||
this.errorMap.get().put(objectId, error);
|
this.errorMap.put(objectId, error);
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -58,9 +59,9 @@ public class BulkOperationResults<K, V> {
|
||||||
*
|
*
|
||||||
* @return true if there are logged errors.
|
* @return true if there are logged errors.
|
||||||
*/
|
*/
|
||||||
public boolean containErrors() {
|
public boolean containsErrors() {
|
||||||
boolean isContainingErrors = false;
|
boolean isContainingErrors = false;
|
||||||
if (!this.errorMap.get().isEmpty()) {
|
if (!this.errorMap.isEmpty()) {
|
||||||
isContainingErrors = true;
|
isContainingErrors = true;
|
||||||
}
|
}
|
||||||
return isContainingErrors;
|
return isContainingErrors;
|
||||||
|
|
@ -76,15 +77,24 @@ public class BulkOperationResults<K, V> {
|
||||||
public V getErrorForId(K idKey) {
|
public V getErrorForId(K idKey) {
|
||||||
V result = null;
|
V result = null;
|
||||||
if (idKey != null) {
|
if (idKey != null) {
|
||||||
result = this.errorMap.get().get(idKey);
|
result = this.errorMap.get(idKey);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the IDs of the Object with failed requests.
|
||||||
|
*
|
||||||
|
* @return a List of IDs that could not be processed successfully.
|
||||||
|
*/
|
||||||
|
public List<K> getFailedIds() {
|
||||||
|
return new ArrayList<>(this.errorMap.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clearing the map - all entries will be removed.
|
* Clearing the map - all entries will be removed.
|
||||||
*/
|
*/
|
||||||
public void clearErrors() {
|
public void clearErrors() {
|
||||||
this.errorMap.get().clear();
|
this.errorMap.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package pro.taskana.impl;
|
||||||
|
|
||||||
|
import pro.taskana.model.TaskState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convenience class to represent pairs of task id and task state.
|
||||||
|
*/
|
||||||
|
public class MinimalTaskSummary {
|
||||||
|
|
||||||
|
private String taskId;
|
||||||
|
private String workbasketKey;
|
||||||
|
private TaskState taskState;
|
||||||
|
|
||||||
|
public String getTaskId() {
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskId(String taskId) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWorkbasketKey() {
|
||||||
|
return workbasketKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorkbasketKey(String workbasketKey) {
|
||||||
|
this.workbasketKey = workbasketKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskState getTaskState() {
|
||||||
|
return taskState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskState(TaskState taskState) {
|
||||||
|
this.taskState = taskState;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -338,8 +338,8 @@ public class TaskServiceImpl implements TaskService {
|
||||||
Workbasket destinationWorkbasket = workbasketService.getWorkbasketByKey(destinationWorkbasketKey);
|
Workbasket destinationWorkbasket = workbasketService.getWorkbasketByKey(destinationWorkbasketKey);
|
||||||
|
|
||||||
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||||
// check tasks exist and Ids valid - log and remove
|
|
||||||
List<TaskSummary> taskSummaries = this.createTaskQuery().idIn(taskIds.toArray(new String[0])).list();
|
// check tasks Ids exist and not empty - log and remove
|
||||||
Iterator<String> taskIdIterator = taskIds.iterator();
|
Iterator<String> taskIdIterator = taskIds.iterator();
|
||||||
while (taskIdIterator.hasNext()) {
|
while (taskIdIterator.hasNext()) {
|
||||||
String currentTaskId = taskIdIterator.next();
|
String currentTaskId = taskIdIterator.next();
|
||||||
|
|
@ -347,18 +347,16 @@ public class TaskServiceImpl implements TaskService {
|
||||||
bulkLog.addError("",
|
bulkLog.addError("",
|
||||||
new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed."));
|
new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed."));
|
||||||
taskIdIterator.remove();
|
taskIdIterator.remove();
|
||||||
} else if (!taskSummaries.stream()
|
|
||||||
.filter(taskSummary -> currentTaskId.equals(taskSummary.getTaskId()))
|
|
||||||
.findFirst()
|
|
||||||
.isPresent()) {
|
|
||||||
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId));
|
|
||||||
taskIdIterator.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// query for existing tasks. use taskMapper.findExistingTasks because this method
|
||||||
|
// returns only the required information.
|
||||||
|
List<MinimalTaskSummary> taskSummaries = taskMapper.findExistingTasks(taskIds);
|
||||||
|
|
||||||
// check source WB (read)+transfer
|
// check source WB (read)+transfer
|
||||||
Set<String> workbasketKeys = new HashSet<>();
|
Set<String> workbasketKeys = new HashSet<>();
|
||||||
taskSummaries.stream().forEach(t -> workbasketKeys.add(t.getWorkbasketSummary().getKey()));
|
taskSummaries.stream().forEach(t -> workbasketKeys.add(t.getWorkbasketKey()));
|
||||||
List<WorkbasketSummary> sourceWorkbaskets = workbasketService.createWorkbasketQuery()
|
List<WorkbasketSummary> sourceWorkbaskets = workbasketService.createWorkbasketQuery()
|
||||||
.callerHasPermission(WorkbasketAuthorization.TRANSFER)
|
.callerHasPermission(WorkbasketAuthorization.TRANSFER)
|
||||||
.keyIn(workbasketKeys.toArray(new String[0]))
|
.keyIn(workbasketKeys.toArray(new String[0]))
|
||||||
|
|
@ -366,41 +364,36 @@ public class TaskServiceImpl implements TaskService {
|
||||||
taskIdIterator = taskIds.iterator();
|
taskIdIterator = taskIds.iterator();
|
||||||
while (taskIdIterator.hasNext()) {
|
while (taskIdIterator.hasNext()) {
|
||||||
String currentTaskId = taskIdIterator.next();
|
String currentTaskId = taskIdIterator.next();
|
||||||
TaskSummary taskSummary = taskSummaries.stream()
|
MinimalTaskSummary taskSummary = taskSummaries.stream()
|
||||||
.filter(t -> currentTaskId.equals(t.getTaskId()))
|
.filter(t -> currentTaskId.equals(t.getTaskId()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
if (taskSummaries != null) {
|
if (taskSummary == null) {
|
||||||
if (!sourceWorkbaskets.stream()
|
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId));
|
||||||
.filter(wb -> taskSummary.getWorkbasketSummary().getKey().equals(wb.getKey()))
|
taskIdIterator.remove();
|
||||||
.findFirst()
|
} else if (!sourceWorkbaskets.stream()
|
||||||
.isPresent()) {
|
.anyMatch(wb -> taskSummary.getWorkbasketKey().equals(wb.getKey()))) {
|
||||||
bulkLog.addError(currentTaskId,
|
bulkLog.addError(currentTaskId,
|
||||||
new NotAuthorizedException(
|
new NotAuthorizedException(
|
||||||
"The workbasket of this task got not TRANSFER permissions. TaskId=" + currentTaskId));
|
"The workbasket of this task got not TRANSFER permissions. TaskId=" + currentTaskId));
|
||||||
taskIdIterator.remove();
|
taskIdIterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// filter taskSummaries and update values
|
// filter taskSummaries and update values
|
||||||
taskSummaries = taskSummaries.stream().filter(ts -> taskIds.contains(ts.getTaskId())).collect(
|
taskSummaries = taskSummaries.stream().filter(ts -> taskIds.contains(ts.getTaskId())).collect(
|
||||||
Collectors.toList());
|
Collectors.toList());
|
||||||
if (!taskSummaries.isEmpty()) {
|
if (!taskSummaries.isEmpty()) {
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
List<TaskSummaryImpl> updateObjects = new ArrayList<>();
|
TaskSummaryImpl updateObject = new TaskSummaryImpl();
|
||||||
for (TaskSummary ts : taskSummaries) {
|
updateObject.setRead(false);
|
||||||
TaskSummaryImpl taskSummary = (TaskSummaryImpl) ts;
|
updateObject.setTransferred(true);
|
||||||
taskSummary.setRead(false);
|
updateObject.setWorkbasketSummary(destinationWorkbasket.asSummary());
|
||||||
taskSummary.setTransferred(true);
|
updateObject.setDomain(destinationWorkbasket.getDomain());
|
||||||
taskSummary.setWorkbasketSummary(destinationWorkbasket.asSummary());
|
updateObject.setModified(now);
|
||||||
taskSummary.setDomain(destinationWorkbasket.getDomain());
|
updateObject.setState(TaskState.READY);
|
||||||
taskSummary.setModified(now);
|
updateObject.setOwner(null);
|
||||||
taskSummary.setState(TaskState.READY);
|
taskMapper.updateTransfered(taskIds, updateObject);
|
||||||
taskSummary.setOwner(null);
|
|
||||||
updateObjects.add(taskSummary);
|
|
||||||
}
|
|
||||||
taskMapper.updateTransfered(taskIds, updateObjects.get(0));
|
|
||||||
}
|
}
|
||||||
return bulkLog;
|
return bulkLog;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -815,6 +808,76 @@ public class TaskServiceImpl implements TaskService {
|
||||||
return new AttachmentImpl();
|
return new AttachmentImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteTask(String taskId) throws TaskNotFoundException, InvalidStateException {
|
||||||
|
deleteTask(taskId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteTask(String taskId, boolean forceDelete) throws TaskNotFoundException, InvalidStateException {
|
||||||
|
LOGGER.debug("entry to deleteTask(taskId = {} , forceDelete = {} )", taskId, forceDelete);
|
||||||
|
TaskImpl task = null;
|
||||||
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
task = (TaskImpl) getTask(taskId);
|
||||||
|
|
||||||
|
// reset read flag and set transferred flag
|
||||||
|
if (!TaskState.COMPLETED.equals(task.getState()) && !forceDelete) {
|
||||||
|
LOGGER.warn(
|
||||||
|
"Method deleteTask() found that task {} is not completed and forceDelete is false. Throwing InvalidStateException",
|
||||||
|
task);
|
||||||
|
throw new InvalidStateException("Cannot delete Task " + taskId + " because it is not completed");
|
||||||
|
}
|
||||||
|
taskMapper.delete(taskId);
|
||||||
|
LOGGER.debug("Method deleteTask() deleted Task {}", taskId);
|
||||||
|
} finally {
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
LOGGER.debug("exit from deleteTask(). ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BulkOperationResults<String, TaskanaException> deleteTasks(List<String> taskIds) {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("entry to deleteTasks(tasks = {})", LoggerUtils.listToString(taskIds));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
taskanaEngineImpl.openConnection();
|
||||||
|
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||||
|
|
||||||
|
List<MinimalTaskSummary> taskSummaries = taskMapper.findExistingTasks(taskIds);
|
||||||
|
|
||||||
|
Iterator<String> taskIdIterator = taskIds.iterator();
|
||||||
|
while (taskIdIterator.hasNext()) {
|
||||||
|
String currentTaskId = taskIdIterator.next();
|
||||||
|
if (currentTaskId == null || currentTaskId.equals("")) {
|
||||||
|
bulkLog.addError("",
|
||||||
|
new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed."));
|
||||||
|
taskIdIterator.remove();
|
||||||
|
} else {
|
||||||
|
MinimalTaskSummary foundSummary = taskSummaries.stream()
|
||||||
|
.filter(taskState -> currentTaskId.equals(taskState.getTaskId()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if (foundSummary == null) {
|
||||||
|
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId));
|
||||||
|
taskIdIterator.remove();
|
||||||
|
} else {
|
||||||
|
if (!TaskState.COMPLETED.equals(foundSummary.getTaskState())) {
|
||||||
|
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
|
||||||
|
taskIdIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taskMapper.deleteMultiple(taskIds);
|
||||||
|
return bulkLog;
|
||||||
|
} finally {
|
||||||
|
LOGGER.debug("exit from deleteTasks()");
|
||||||
|
taskanaEngineImpl.returnConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void validateObjectReference(ObjectReference objRef, String objRefType, String objName)
|
private void validateObjectReference(ObjectReference objRef, String objRefType, String objName)
|
||||||
throws InvalidArgumentException {
|
throws InvalidArgumentException {
|
||||||
// check that all values in the ObjectReference are set correctly
|
// check that all values in the ObjectReference are set correctly
|
||||||
|
|
@ -1007,4 +1070,5 @@ public class TaskServiceImpl implements TaskService {
|
||||||
attachment.setTaskId(newTask.getId());
|
attachment.setTaskId(newTask.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import org.apache.ibatis.annotations.Select;
|
||||||
import org.apache.ibatis.annotations.Update;
|
import org.apache.ibatis.annotations.Update;
|
||||||
import org.apache.ibatis.type.JdbcType;
|
import org.apache.ibatis.type.JdbcType;
|
||||||
|
|
||||||
|
import pro.taskana.impl.MinimalTaskSummary;
|
||||||
import pro.taskana.impl.TaskImpl;
|
import pro.taskana.impl.TaskImpl;
|
||||||
import pro.taskana.impl.TaskSummaryImpl;
|
import pro.taskana.impl.TaskSummaryImpl;
|
||||||
import pro.taskana.impl.WorkbasketSummaryImpl;
|
import pro.taskana.impl.WorkbasketSummaryImpl;
|
||||||
|
|
@ -89,6 +90,9 @@ public interface TaskMapper {
|
||||||
@Delete("DELETE FROM TASK WHERE ID = #{id}")
|
@Delete("DELETE FROM TASK WHERE ID = #{id}")
|
||||||
void delete(String id);
|
void delete(String id);
|
||||||
|
|
||||||
|
@Delete("<script>DELETE FROM TASK WHERE ID IN(<foreach item='item' collection='ids' separator=',' >#{item}</foreach>)</script>")
|
||||||
|
void deleteMultiple(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
@Select("SELECT ID, CREATED, CLAIMED, COMPLETED, MODIFIED, PLANNED, DUE, NAME, DESCRIPTION, PRIORITY, STATE, CLASSIFICATION_KEY, WORKBASKET_KEY, DOMAIN, BUSINESS_PROCESS_ID, PARENT_BUSINESS_PROCESS_ID, OWNER, POR_COMPANY, POR_SYSTEM, POR_INSTANCE, POR_TYPE, POR_VALUE, IS_READ, IS_TRANSFERRED, CUSTOM_ATTRIBUTES, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8, CUSTOM_9, CUSTOM_10 "
|
@Select("SELECT ID, CREATED, CLAIMED, COMPLETED, MODIFIED, PLANNED, DUE, NAME, DESCRIPTION, PRIORITY, STATE, CLASSIFICATION_KEY, WORKBASKET_KEY, DOMAIN, BUSINESS_PROCESS_ID, PARENT_BUSINESS_PROCESS_ID, OWNER, POR_COMPANY, POR_SYSTEM, POR_INSTANCE, POR_TYPE, POR_VALUE, IS_READ, IS_TRANSFERRED, CUSTOM_ATTRIBUTES, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, CUSTOM_5, CUSTOM_6, CUSTOM_7, CUSTOM_8, CUSTOM_9, CUSTOM_10 "
|
||||||
+ "FROM TASK "
|
+ "FROM TASK "
|
||||||
+ "WHERE WORKBASKET_KEY = #{workbasketKey} "
|
+ "WHERE WORKBASKET_KEY = #{workbasketKey} "
|
||||||
|
|
@ -178,4 +182,14 @@ public interface TaskMapper {
|
||||||
+ "</script>")
|
+ "</script>")
|
||||||
void updateTransfered(@Param("taskIds") List<String> taskIds,
|
void updateTransfered(@Param("taskIds") List<String> taskIds,
|
||||||
@Param("referencetask") TaskSummaryImpl referencetask);
|
@Param("referencetask") TaskSummaryImpl referencetask);
|
||||||
|
|
||||||
|
@Select("<script>SELECT ID, STATE, WORKBASKET_KEY FROM TASK "
|
||||||
|
+ "WHERE ID IN(<foreach item='item' collection='taskIds' separator=',' >#{item}</foreach>) "
|
||||||
|
+ "</script>")
|
||||||
|
@Results(value = {
|
||||||
|
@Result(property = "taskId", column = "ID"),
|
||||||
|
@Result(property = "workbasketKey", column = "WORKBASKET_KEY"),
|
||||||
|
@Result(property = "taskState", column = "STATE")})
|
||||||
|
List<MinimalTaskSummary> findExistingTasks(@Param("taskIds") List<String> taskIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,25 @@
|
||||||
package acceptance.task;
|
package acceptance.task;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.h2.store.fs.FileUtils;
|
import org.h2.store.fs.FileUtils;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import acceptance.AbstractAccTest;
|
import acceptance.AbstractAccTest;
|
||||||
import pro.taskana.Task;
|
import pro.taskana.Task;
|
||||||
import pro.taskana.TaskService;
|
import pro.taskana.TaskService;
|
||||||
import pro.taskana.exceptions.AttachmentPersistenceException;
|
|
||||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
|
||||||
import pro.taskana.exceptions.ConcurrencyException;
|
|
||||||
import pro.taskana.exceptions.InvalidArgumentException;
|
|
||||||
import pro.taskana.exceptions.InvalidStateException;
|
import pro.taskana.exceptions.InvalidStateException;
|
||||||
import pro.taskana.exceptions.InvalidWorkbasketException;
|
|
||||||
import pro.taskana.exceptions.NotAuthorizedException;
|
|
||||||
import pro.taskana.exceptions.TaskAlreadyExistException;
|
|
||||||
import pro.taskana.exceptions.TaskNotFoundException;
|
import pro.taskana.exceptions.TaskNotFoundException;
|
||||||
import pro.taskana.exceptions.WorkbasketNotFoundException;
|
import pro.taskana.exceptions.TaskanaException;
|
||||||
|
import pro.taskana.impl.BulkOperationResults;
|
||||||
import pro.taskana.security.JAASRunner;
|
import pro.taskana.security.JAASRunner;
|
||||||
import pro.taskana.security.WithAccessId;
|
import pro.taskana.security.WithAccessId;
|
||||||
|
|
||||||
|
|
@ -35,88 +33,71 @@ public class DeleteTaskAccTest extends AbstractAccTest {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
userName = "user_1_2",
|
userName = "user_1_2",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
@Test(expected = TaskNotFoundException.class)
|
@Test(expected = TaskNotFoundException.class)
|
||||||
public void testDeleteSingleTask()
|
public void testDeleteSingleTask() throws TaskNotFoundException, InvalidStateException {
|
||||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
|
||||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
|
||||||
ConcurrencyException, AttachmentPersistenceException {
|
|
||||||
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000036");
|
Task task = taskService.getTask("TKI:000000000000000000000000000000000036");
|
||||||
|
|
||||||
// taskService.deleteTask(task.getId());
|
taskService.deleteTask(task.getId());
|
||||||
|
|
||||||
Task deletedTask = taskService.getTask("TKI:000000000000000000000000000000000036");
|
taskService.getTask("TKI:000000000000000000000000000000000036");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
userName = "user_1_2",
|
userName = "user_1_2",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
@Test(expected = InvalidStateException.class)
|
@Test(expected = InvalidStateException.class)
|
||||||
public void testThrowsExceptionIfTaskIsNotCompleted()
|
public void testThrowsExceptionIfTaskIsNotCompleted()
|
||||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
throws TaskNotFoundException, InvalidStateException, SQLException {
|
||||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
|
||||||
ConcurrencyException, AttachmentPersistenceException {
|
|
||||||
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000027");
|
Task task = taskService.getTask("TKI:000000000000000000000000000000000029");
|
||||||
|
|
||||||
// taskService.deleteTask(task.getId());
|
taskService.deleteTask(task.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
userName = "user_1_2",
|
userName = "user_1_2",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
@Test(expected = TaskNotFoundException.class)
|
@Test(expected = TaskNotFoundException.class)
|
||||||
public void testForceDeleteTaskIfNotCompleted()
|
public void testForceDeleteTaskIfNotCompleted() throws SQLException, TaskNotFoundException, InvalidStateException {
|
||||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
|
||||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
|
||||||
ConcurrencyException, AttachmentPersistenceException {
|
|
||||||
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000027");
|
Task task = taskService.getTask("TKI:000000000000000000000000000000000027");
|
||||||
|
try {
|
||||||
// taskService.deleteTask(task.getId(), true);
|
taskService.deleteTask(task.getId());
|
||||||
|
fail("Should not be possible to delete claimed task without force flag");
|
||||||
Task deletedTask = taskService.getTask("TKI:000000000000000000000000000000000036");
|
} catch (InvalidStateException ex) {
|
||||||
|
taskService.deleteTask(task.getId(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
taskService.getTask("TKI:000000000000000000000000000000000027");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
userName = "user_1_2",
|
userName = "user_1_2",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
@Test(expected = TaskNotFoundException.class)
|
@Test(expected = TaskNotFoundException.class)
|
||||||
public void testBulkDeleteTask()
|
public void testBulkDeleteTask() throws TaskNotFoundException {
|
||||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
|
||||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
|
||||||
ConcurrencyException, AttachmentPersistenceException {
|
|
||||||
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
ArrayList<String> taskIdList = new ArrayList<>();
|
ArrayList<String> taskIdList = new ArrayList<>();
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000037");
|
taskIdList.add("TKI:000000000000000000000000000000000037");
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000038");
|
taskIdList.add("TKI:000000000000000000000000000000000038");
|
||||||
|
|
||||||
// BulkOperationResults results = taskService.deleteTasks(taskIdList);
|
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||||
|
|
||||||
// assertFalse(results.containsError());
|
assertFalse(results.containsErrors());
|
||||||
Task deletedTask = taskService.getTask("TKI:000000000000000000000000000000000038");
|
taskService.getTask("TKI:000000000000000000000000000000000038");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
userName = "user_1_2",
|
userName = "user_1_2",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
@Test(expected = TaskNotFoundException.class)
|
@Test(expected = TaskNotFoundException.class)
|
||||||
public void testBulkDeleteTasksWithException()
|
public void testBulkDeleteTasksWithException() throws TaskNotFoundException {
|
||||||
throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
|
||||||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException,
|
|
||||||
ConcurrencyException, AttachmentPersistenceException {
|
|
||||||
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
ArrayList<String> taskIdList = new ArrayList<>();
|
ArrayList<String> taskIdList = new ArrayList<>();
|
||||||
|
|
@ -124,12 +105,19 @@ public class DeleteTaskAccTest extends AbstractAccTest {
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000040");
|
taskIdList.add("TKI:000000000000000000000000000000000040");
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000028");
|
taskIdList.add("TKI:000000000000000000000000000000000028");
|
||||||
|
|
||||||
// BulkOperationResults results = taskService.deleteTasks(taskIdList);
|
BulkOperationResults<String, TaskanaException> results = taskService.deleteTasks(taskIdList);
|
||||||
|
|
||||||
|
String expectedFailedId = "TKI:000000000000000000000000000000000028";
|
||||||
|
assertTrue(results.containsErrors());
|
||||||
|
List<String> failedTaskIds = results.getFailedIds();
|
||||||
|
assertTrue(failedTaskIds.size() == 1);
|
||||||
|
assertTrue(expectedFailedId.equals(failedTaskIds.get(0)));
|
||||||
|
assertTrue(results.getErrorMap().get(expectedFailedId).getClass() == InvalidStateException.class);
|
||||||
|
|
||||||
// assertTrue(results.containsError());
|
|
||||||
// more assertions ...
|
|
||||||
Task notDeletedTask = taskService.getTask("TKI:000000000000000000000000000000000028");
|
Task notDeletedTask = taskService.getTask("TKI:000000000000000000000000000000000028");
|
||||||
Task deletedTask = taskService.getTask("TKI:000000000000000000000000000000000040");
|
assertTrue(notDeletedTask != null);
|
||||||
|
taskService.getTask("TKI:000000000000000000000000000000000040");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ public class TransferTaskAccTest extends AbstractAccTest {
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000005");
|
taskIdList.add("TKI:000000000000000000000000000000000005");
|
||||||
|
|
||||||
BulkOperationResults<String, TaskanaException> results = taskService.transferBulk("USER_1_1", taskIdList);
|
BulkOperationResults<String, TaskanaException> results = taskService.transferBulk("USER_1_1", taskIdList);
|
||||||
assertFalse(results.containErrors());
|
assertFalse(results.containsErrors());
|
||||||
|
|
||||||
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasketByKey("USER_1_1");
|
Workbasket wb = taskanaEngine.getWorkbasketService().getWorkbasketByKey("USER_1_1");
|
||||||
Task transferredTask = taskService.getTask("TKI:000000000000000000000000000000000004");
|
Task transferredTask = taskService.getTask("TKI:000000000000000000000000000000000004");
|
||||||
|
|
@ -137,7 +137,7 @@ public class TransferTaskAccTest extends AbstractAccTest {
|
||||||
assertEquals(TaskState.READY, transferredTask.getState());
|
assertEquals(TaskState.READY, transferredTask.getState());
|
||||||
assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
|
assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
|
||||||
assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
|
assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
|
||||||
assertTrue(transferredTask.getModified().isAfter(before));
|
assertFalse(transferredTask.getModified().isBefore(before));
|
||||||
assertThat(transferredTask.getOwner(), equalTo(null));
|
assertThat(transferredTask.getOwner(), equalTo(null));
|
||||||
transferredTask = taskService.getTask("TKI:000000000000000000000000000000000005");
|
transferredTask = taskService.getTask("TKI:000000000000000000000000000000000005");
|
||||||
assertNotNull(transferredTask);
|
assertNotNull(transferredTask);
|
||||||
|
|
@ -146,7 +146,7 @@ public class TransferTaskAccTest extends AbstractAccTest {
|
||||||
assertEquals(TaskState.READY, transferredTask.getState());
|
assertEquals(TaskState.READY, transferredTask.getState());
|
||||||
assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
|
assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
|
||||||
assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
|
assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
|
||||||
assertTrue(transferredTask.getModified().isAfter(before));
|
assertFalse(transferredTask.getModified().isBefore(before));
|
||||||
assertThat(transferredTask.getOwner(), equalTo(null));
|
assertThat(transferredTask.getOwner(), equalTo(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,7 +167,7 @@ public class TransferTaskAccTest extends AbstractAccTest {
|
||||||
taskIdList.add("TKI:000000000000000000000000000000000099"); // TaskNotFound
|
taskIdList.add("TKI:000000000000000000000000000000000099"); // TaskNotFound
|
||||||
|
|
||||||
BulkOperationResults<String, TaskanaException> results = taskService.transferBulk("USER_1_1", taskIdList);
|
BulkOperationResults<String, TaskanaException> results = taskService.transferBulk("USER_1_1", taskIdList);
|
||||||
assertTrue(results.containErrors());
|
assertTrue(results.containsErrors());
|
||||||
assertThat(results.getErrorMap().values().size(), equalTo(3));
|
assertThat(results.getErrorMap().values().size(), equalTo(3));
|
||||||
// react to result
|
// react to result
|
||||||
for (String taskId : results.getErrorMap().keySet()) {
|
for (String taskId : results.getErrorMap().keySet()) {
|
||||||
|
|
@ -189,7 +189,7 @@ public class TransferTaskAccTest extends AbstractAccTest {
|
||||||
assertEquals(TaskState.READY, transferredTask.getState());
|
assertEquals(TaskState.READY, transferredTask.getState());
|
||||||
assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
|
assertThat(transferredTask.getWorkbasketKey(), equalTo(wb.getKey()));
|
||||||
assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
|
assertThat(transferredTask.getDomain(), equalTo(wb.getDomain()));
|
||||||
assertTrue(transferredTask.getModified().isAfter(before));
|
assertFalse(transferredTask.getModified().isBefore(before));
|
||||||
assertThat(transferredTask.getOwner(), equalTo(null));
|
assertThat(transferredTask.getOwner(), equalTo(null));
|
||||||
|
|
||||||
transferredTask = taskService.getTask("TKI:000000000000000000000000000000000002");
|
transferredTask = taskService.getTask("TKI:000000000000000000000000000000000002");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue