TSK-1131 updateOwner Bulk - comments from Holger
This commit is contained in:
parent
20bd0922db
commit
7f93dd048e
|
|
@ -184,10 +184,12 @@ public class TaskCleanupJob extends AbstractTaskanaJob {
|
||||||
taskanaEngineImpl.getTaskService().deleteTasks(tasksIdsToBeDeleted);
|
taskanaEngineImpl.getTaskService().deleteTasks(tasksIdsToBeDeleted);
|
||||||
LOGGER.debug("{} tasks deleted.", tasksIdsToBeDeleted.size() - results.getFailedIds().size());
|
LOGGER.debug("{} tasks deleted.", tasksIdsToBeDeleted.size() - results.getFailedIds().size());
|
||||||
for (String failedId : results.getFailedIds()) {
|
for (String failedId : results.getFailedIds()) {
|
||||||
LOGGER.warn(
|
if (LOGGER.isWarnEnabled()) {
|
||||||
"Task with id {} could not be deleted. Reason: {}",
|
LOGGER.warn(
|
||||||
LogSanitizer.stripLineBreakingChars(failedId),
|
"Task with id {} could not be deleted. Reason: {}",
|
||||||
LogSanitizer.stripLineBreakingChars(results.getErrorForId(failedId)));
|
LogSanitizer.stripLineBreakingChars(failedId),
|
||||||
|
LogSanitizer.stripLineBreakingChars(results.getErrorForId(failedId)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"exit from deleteTasks(), returning {}",
|
"exit from deleteTasks(), returning {}",
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,17 @@ public final class TaskRoutingManager {
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
if (workbasketIds.isEmpty()) {
|
if (workbasketIds.isEmpty()) {
|
||||||
LOGGER.error(
|
if (LOGGER.isErrorEnabled()) {
|
||||||
"No TaskRouter determined a workbasket for task {}.",
|
LOGGER.error(
|
||||||
LogSanitizer.stripLineBreakingChars(task));
|
"No TaskRouter determined a workbasket for task {}.",
|
||||||
|
LogSanitizer.stripLineBreakingChars(task));
|
||||||
|
}
|
||||||
} else if (workbasketIds.size() > 1) {
|
} else if (workbasketIds.size() > 1) {
|
||||||
LOGGER.error(
|
if (LOGGER.isErrorEnabled()) {
|
||||||
"The TaskRouters determined more than one workbasket for task {}",
|
LOGGER.error(
|
||||||
LogSanitizer.stripLineBreakingChars(task));
|
"The TaskRouters determined more than one workbasket for task {}",
|
||||||
|
LogSanitizer.stripLineBreakingChars(task));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
workbasketId = workbasketIds.stream().findFirst().orElse(null);
|
workbasketId = workbasketIds.stream().findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import org.apache.ibatis.exceptions.PersistenceException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.TaskanaEngineConfiguration;
|
|
||||||
import pro.taskana.classification.api.ClassificationService;
|
import pro.taskana.classification.api.ClassificationService;
|
||||||
import pro.taskana.classification.api.exceptions.ClassificationNotFoundException;
|
import pro.taskana.classification.api.exceptions.ClassificationNotFoundException;
|
||||||
import pro.taskana.classification.api.models.Classification;
|
import pro.taskana.classification.api.models.Classification;
|
||||||
|
|
@ -73,12 +72,17 @@ public class TaskServiceImpl implements TaskService {
|
||||||
|
|
||||||
private static final String IS_ALREADY_CLAIMED_BY = " is already claimed by ";
|
private static final String IS_ALREADY_CLAIMED_BY = " is already claimed by ";
|
||||||
private static final String IS_ALREADY_COMPLETED = " is already completed.";
|
private static final String IS_ALREADY_COMPLETED = " is already completed.";
|
||||||
private static final String TASK_WITH_ID_IS_NOT_READY = "Task with id %s is not in state ready.";
|
private static final String TASK_WITH_ID_IS_NOT_READY =
|
||||||
|
"Task with id %s is in state %s and not in state ready.";
|
||||||
|
private static final String TASK_WITH_ID_WAS_NOT_FOUND = "Task with id %s was not found.";
|
||||||
|
private static final String TASK_WITH_ID_CALLBACK_NOT_PROCESSED =
|
||||||
|
"Task wit Id %s cannot be deleted because its callback is not yet processed";
|
||||||
private static final String WAS_NOT_FOUND2 = " was not found.";
|
private static final String WAS_NOT_FOUND2 = " was not found.";
|
||||||
private static final String WAS_NOT_FOUND = " was not found";
|
private static final String WAS_NOT_FOUND = " was not found";
|
||||||
private static final String TASK_WITH_ID = "Task with id ";
|
private static final String TASK_WITH_ID = "Task with id ";
|
||||||
private static final String WAS_MARKED_FOR_DELETION = " was marked for deletion";
|
private static final String WAS_MARKED_FOR_DELETION = " was marked for deletion";
|
||||||
private static final String THE_WORKBASKET = "The workbasket ";
|
private static final String THE_WORKBASKET = "The workbasket ";
|
||||||
|
private static final String TASK = "Task";
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskServiceImpl.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(TaskServiceImpl.class);
|
||||||
private static final String ID_PREFIX_ATTACHMENT = "TAI";
|
private static final String ID_PREFIX_ATTACHMENT = "TAI";
|
||||||
private static final String ID_PREFIX_TASK = "TKI";
|
private static final String ID_PREFIX_TASK = "TKI";
|
||||||
|
|
@ -211,7 +215,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
Classification classification =
|
Classification classification =
|
||||||
this.classificationService.getClassification(classificationKey, workbasket.getDomain());
|
this.classificationService.getClassification(classificationKey, workbasket.getDomain());
|
||||||
task.setClassificationSummary(classification.asSummary());
|
task.setClassificationSummary(classification.asSummary());
|
||||||
validateObjectReference(task.getPrimaryObjRef(), "primary ObjectReference", "Task");
|
validateObjectReference(task.getPrimaryObjRef(), "primary ObjectReference", TASK);
|
||||||
PrioDurationHolder prioDurationFromAttachments = handleAttachments(task);
|
PrioDurationHolder prioDurationFromAttachments = handleAttachments(task);
|
||||||
standardSettings(task, classification, prioDurationFromAttachments);
|
standardSettings(task, classification, prioDurationFromAttachments);
|
||||||
setCallbackStateOnTaskCreation(task);
|
setCallbackStateOnTaskCreation(task);
|
||||||
|
|
@ -628,39 +632,47 @@ public class TaskServiceImpl implements TaskService {
|
||||||
owner,
|
owner,
|
||||||
LoggerUtils.listToString(argTaskIds));
|
LoggerUtils.listToString(argTaskIds));
|
||||||
}
|
}
|
||||||
|
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||||
|
if (argTaskIds == null || argTaskIds.isEmpty()) {
|
||||||
|
return bulkLog;
|
||||||
|
}
|
||||||
|
// remove duplicates
|
||||||
|
List<String> taskIds = argTaskIds.stream().distinct().collect(Collectors.toList());
|
||||||
|
final int requestSize = taskIds.size();
|
||||||
try {
|
try {
|
||||||
taskanaEngine.openConnection();
|
taskanaEngine.openConnection();
|
||||||
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
|
||||||
if (argTaskIds == null || argTaskIds.isEmpty()) {
|
|
||||||
return bulkLog;
|
|
||||||
}
|
|
||||||
// remove duplicates
|
|
||||||
List<String> taskIds = argTaskIds.stream().sorted().distinct().collect(Collectors.toList());
|
|
||||||
final int requestSize = taskIds.size();
|
|
||||||
// use only elements we are authorized for
|
// use only elements we are authorized for
|
||||||
taskIds = filterForAuthorized(taskIds, bulkLog);
|
Pair<List<String>, BulkOperationResults<String, TaskanaException>> resultsPair =
|
||||||
|
filterForAuthorizedTasks(taskIds);
|
||||||
// set the Owner of these tasks we are authorized for
|
// set the Owner of these tasks we are authorized for
|
||||||
|
taskIds = resultsPair.getLeft();
|
||||||
|
bulkLog.addAllErrors(resultsPair.getRight());
|
||||||
if (taskIds.isEmpty()) {
|
if (taskIds.isEmpty()) {
|
||||||
return bulkLog;
|
return bulkLog;
|
||||||
} else {
|
} else {
|
||||||
final int numberOfAffectedTasks = taskMapper.setOwnerOfTasks(owner, taskIds, Instant.now());
|
final int numberOfAffectedTasks = taskMapper.setOwnerOfTasks(owner, taskIds, Instant.now());
|
||||||
// check the outcome
|
if (numberOfAffectedTasks == taskIds.size()) { // all tasks were updated
|
||||||
List<MinimalTaskSummary> existingMinimalTaskSummaries =
|
return bulkLog;
|
||||||
taskMapper.findExistingTasks(taskIds, null);
|
} else {
|
||||||
// check for tasks that don't exist
|
// check the outcome
|
||||||
handleNonExistingTasks(taskIds, existingMinimalTaskSummaries, bulkLog);
|
List<MinimalTaskSummary> existingMinimalTaskSummaries =
|
||||||
// add all errors that occured to bulkLog
|
taskMapper.findExistingTasks(taskIds, null);
|
||||||
addErrorsToResultObject(owner, bulkLog, existingMinimalTaskSummaries);
|
// add exceptions for non existing tasks
|
||||||
LOGGER.debug(
|
bulkLog.addAllErrors(
|
||||||
"Received the Request to set owner on "
|
addExceptionsForNonExistingTasks(taskIds, existingMinimalTaskSummaries));
|
||||||
+ requestSize
|
// add exceptions of all remaining tasks whose owners were not set
|
||||||
+ " tasks, "
|
bulkLog.addAllErrors(
|
||||||
+ "actually modified tasks = "
|
addExceptionsForTasksWhoseOwnerWasNotSet(owner, existingMinimalTaskSummaries));
|
||||||
+ numberOfAffectedTasks
|
if (LOGGER.isDebugEnabled()) {
|
||||||
+ ", could not set owner on "
|
LOGGER.debug(
|
||||||
+ bulkLog.getFailedIds().size()
|
"Received the Request to set owner on {} tasks, actually modified tasks = {}, "
|
||||||
+ " tasks.");
|
+ "could not set owner on {} tasks",
|
||||||
return bulkLog;
|
requestSize,
|
||||||
|
numberOfAffectedTasks,
|
||||||
|
bulkLog.getFailedIds().size());
|
||||||
|
}
|
||||||
|
return bulkLog;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
LOGGER.debug("exit from setOwnerOfTasks()");
|
LOGGER.debug("exit from setOwnerOfTasks()");
|
||||||
|
|
@ -808,20 +820,20 @@ public class TaskServiceImpl implements TaskService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addErrorsToResultObject(
|
private BulkOperationResults<String, TaskanaException> addExceptionsForTasksWhoseOwnerWasNotSet(
|
||||||
String owner,
|
String owner, List<MinimalTaskSummary> existingMinimalTaskSummaries) {
|
||||||
BulkOperationResults<String, TaskanaException> bulkLog,
|
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||||
List<MinimalTaskSummary> existingMinimalTaskSummaries) {
|
|
||||||
for (MinimalTaskSummary taskSummary : existingMinimalTaskSummaries) {
|
for (MinimalTaskSummary taskSummary : existingMinimalTaskSummaries) {
|
||||||
if (!owner.equals(taskSummary.getOwner())) { // owner was not set
|
if (!owner.equals(taskSummary.getOwner())) { // owner was not set
|
||||||
if (!taskSummary.getTaskState().equals(TaskState.READY)) { // due to invalid state
|
if (!taskSummary.getTaskState().equals(TaskState.READY)) { // due to invalid state
|
||||||
bulkLog.addError(
|
bulkLog.addError(
|
||||||
taskSummary.getTaskId(),
|
taskSummary.getTaskId(),
|
||||||
new InvalidStateException(
|
new InvalidStateException(
|
||||||
"Task "
|
String.format(
|
||||||
+ taskSummary.getTaskId()
|
TASK_WITH_ID_IS_NOT_READY,
|
||||||
+ " is in state "
|
taskSummary.getTaskId(),
|
||||||
+ taskSummary.getTaskState()));
|
taskSummary.getTaskState())));
|
||||||
} else { // due to unknown reason
|
} else { // due to unknown reason
|
||||||
bulkLog.addError(
|
bulkLog.addError(
|
||||||
taskSummary.getTaskId(),
|
taskSummary.getTaskId(),
|
||||||
|
|
@ -830,12 +842,12 @@ public class TaskServiceImpl implements TaskService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return bulkLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNonExistingTasks(
|
private BulkOperationResults<String, TaskanaException> addExceptionsForNonExistingTasks(
|
||||||
List<String> taskIds,
|
List<String> taskIds, List<MinimalTaskSummary> existingMinimalTaskSummaries) {
|
||||||
List<MinimalTaskSummary> existingMinimalTaskSummaries,
|
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||||
BulkOperationResults<String, TaskanaException> bulkLog) {
|
|
||||||
List<String> nonExistingTaskIds = new ArrayList<>(taskIds);
|
List<String> nonExistingTaskIds = new ArrayList<>(taskIds);
|
||||||
List<String> existingTaskIds =
|
List<String> existingTaskIds =
|
||||||
existingMinimalTaskSummaries.stream()
|
existingMinimalTaskSummaries.stream()
|
||||||
|
|
@ -843,15 +855,20 @@ public class TaskServiceImpl implements TaskService {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
nonExistingTaskIds.removeAll(existingTaskIds);
|
nonExistingTaskIds.removeAll(existingTaskIds);
|
||||||
for (String taskId : nonExistingTaskIds) {
|
for (String taskId : nonExistingTaskIds) {
|
||||||
bulkLog.addError(taskId, new TaskNotFoundException(taskId, "Task was not found"));
|
bulkLog.addError(
|
||||||
|
taskId,
|
||||||
|
new TaskNotFoundException(taskId, String.format(TASK_WITH_ID_WAS_NOT_FOUND, taskId)));
|
||||||
}
|
}
|
||||||
|
return bulkLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> filterForAuthorized(
|
private Pair<List<String>, BulkOperationResults<String, TaskanaException>>
|
||||||
List<String> taskIds, BulkOperationResults<String, TaskanaException> bulkLog) {
|
filterForAuthorizedTasks(List<String> taskIds) {
|
||||||
List<String> accessIds = getAccessIds();
|
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
|
||||||
|
List<String> accessIds = CurrentUserContext.getAccessIds();
|
||||||
List<String> tasksAuthorizedFor = new ArrayList<>(taskIds);
|
List<String> tasksAuthorizedFor = new ArrayList<>(taskIds);
|
||||||
if (accessIds != null) {
|
// check authorization only for non-admin users
|
||||||
|
if (!taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN)) {
|
||||||
List<String> tasksNotAuthorizedFor =
|
List<String> tasksNotAuthorizedFor =
|
||||||
taskMapper.filterTaskIdsNotAuthorizedFor(taskIds, accessIds);
|
taskMapper.filterTaskIdsNotAuthorizedFor(taskIds, accessIds);
|
||||||
tasksAuthorizedFor.removeAll(tasksNotAuthorizedFor);
|
tasksAuthorizedFor.removeAll(tasksNotAuthorizedFor);
|
||||||
|
|
@ -863,20 +880,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
"Current user not authorized for task " + taskId, currentUserId));
|
"Current user not authorized for task " + taskId, currentUserId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tasksAuthorizedFor;
|
return new Pair<>(tasksAuthorizedFor, bulkLog);
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getAccessIds() {
|
|
||||||
List<String> accessIds;
|
|
||||||
if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN)) {
|
|
||||||
accessIds = null;
|
|
||||||
} else {
|
|
||||||
accessIds = CurrentUserContext.getAccessIds();
|
|
||||||
if (TaskanaEngineConfiguration.shouldUseLowerCaseForAccessIds()) {
|
|
||||||
accessIds = accessIds.stream().map(String::toLowerCase).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return accessIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task claim(String taskId, boolean forceClaim)
|
private Task claim(String taskId, boolean forceClaim)
|
||||||
|
|
@ -1020,8 +1024,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
"Cannot delete Task " + taskId + " because it is not completed.");
|
"Cannot delete Task " + taskId + " because it is not completed.");
|
||||||
}
|
}
|
||||||
if (CallbackState.CALLBACK_PROCESSING_REQUIRED.equals(task.getCallbackState())) {
|
if (CallbackState.CALLBACK_PROCESSING_REQUIRED.equals(task.getCallbackState())) {
|
||||||
throw new InvalidStateException(
|
throw new InvalidStateException(String.format(TASK_WITH_ID_CALLBACK_NOT_PROCESSED, taskId));
|
||||||
"Task " + taskId + " cannot be deleted because its callback is not yet processed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taskMapper.delete(taskId);
|
taskMapper.delete(taskId);
|
||||||
|
|
@ -1062,7 +1065,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
bulkLog.addError(
|
bulkLog.addError(
|
||||||
currentTaskId,
|
currentTaskId,
|
||||||
new InvalidStateException(
|
new InvalidStateException(
|
||||||
"Task " + currentTaskId + " cannot be deleted before callback is processed"));
|
String.format(TASK_WITH_ID_CALLBACK_NOT_PROCESSED, currentTaskId)));
|
||||||
taskIdIterator.remove();
|
taskIdIterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1257,7 +1260,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
bulkLog.addError(
|
bulkLog.addError(
|
||||||
currentTaskId,
|
currentTaskId,
|
||||||
new TaskNotFoundException(
|
new TaskNotFoundException(
|
||||||
currentTaskId, "task with id " + currentTaskId + WAS_NOT_FOUND2));
|
currentTaskId, String.format(TASK_WITH_ID_WAS_NOT_FOUND, currentTaskId)));
|
||||||
taskIdIterator.remove();
|
taskIdIterator.remove();
|
||||||
} else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) {
|
} else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) {
|
||||||
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
|
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
|
||||||
|
|
@ -1266,10 +1269,9 @@ public class TaskServiceImpl implements TaskService {
|
||||||
bulkLog.addError(
|
bulkLog.addError(
|
||||||
currentTaskId,
|
currentTaskId,
|
||||||
new InvalidOwnerException(
|
new InvalidOwnerException(
|
||||||
"TaskOwner is"
|
String.format(
|
||||||
+ taskSummary.getOwner()
|
"TaskOwner is %s, but currentUser is %s.",
|
||||||
+ ", but current User is "
|
taskSummary.getOwner(), CurrentUserContext.getUserid())));
|
||||||
+ CurrentUserContext.getUserid()));
|
|
||||||
taskIdIterator.remove();
|
taskIdIterator.remove();
|
||||||
} else {
|
} else {
|
||||||
taskSummary.setCompleted(now);
|
taskSummary.setCompleted(now);
|
||||||
|
|
@ -1659,7 +1661,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
TaskImpl oldTaskImpl, TaskImpl newTaskImpl, PrioDurationHolder prioDurationFromAttachments)
|
TaskImpl oldTaskImpl, TaskImpl newTaskImpl, PrioDurationHolder prioDurationFromAttachments)
|
||||||
throws InvalidArgumentException, ConcurrencyException, ClassificationNotFoundException,
|
throws InvalidArgumentException, ConcurrencyException, ClassificationNotFoundException,
|
||||||
InvalidStateException {
|
InvalidStateException {
|
||||||
validateObjectReference(newTaskImpl.getPrimaryObjRef(), "primary ObjectReference", "Task");
|
validateObjectReference(newTaskImpl.getPrimaryObjRef(), "primary ObjectReference", TASK);
|
||||||
// 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
|
||||||
if (oldTaskImpl.getModified() != null
|
if (oldTaskImpl.getModified() != null
|
||||||
|
|
@ -1696,7 +1698,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
boolean isOwnerChanged = !Objects.equals(newTaskImpl.getOwner(), oldTaskImpl.getOwner());
|
boolean isOwnerChanged = !Objects.equals(newTaskImpl.getOwner(), oldTaskImpl.getOwner());
|
||||||
if (isOwnerChanged && oldTaskImpl.getState() != TaskState.READY) {
|
if (isOwnerChanged && oldTaskImpl.getState() != TaskState.READY) {
|
||||||
throw new InvalidStateException(
|
throw new InvalidStateException(
|
||||||
String.format(TASK_WITH_ID_IS_NOT_READY, oldTaskImpl.getId()));
|
String.format(TASK_WITH_ID_IS_NOT_READY, oldTaskImpl.getId(), oldTaskImpl.getState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateClassificationRelatedProperties(oldTaskImpl, newTaskImpl, prioDurationFromAttachments);
|
updateClassificationRelatedProperties(oldTaskImpl, newTaskImpl, prioDurationFromAttachments);
|
||||||
|
|
@ -2076,8 +2078,8 @@ public class TaskServiceImpl implements TaskService {
|
||||||
id,
|
id,
|
||||||
String.format(
|
String.format(
|
||||||
"When processing task updates due to change "
|
"When processing task updates due to change "
|
||||||
+ "of classification, the classification with id %s%s",
|
+ "of classification, the classification with id %s was not found",
|
||||||
id, WAS_NOT_FOUND2)));
|
id)));
|
||||||
} else {
|
} else {
|
||||||
att.setClassificationSummary(classificationSummary);
|
att.setClassificationSummary(classificationSummary);
|
||||||
result.add(att);
|
result.add(att);
|
||||||
|
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
package pro.taskana.task.internal.models;
|
|
||||||
|
|
||||||
import pro.taskana.task.api.TaskState;
|
|
||||||
|
|
||||||
public class TaskIdOwnerState {
|
|
||||||
private String taskId;
|
|
||||||
private String owner;
|
|
||||||
private TaskState taskState;
|
|
||||||
|
|
||||||
TaskIdOwnerState() {}
|
|
||||||
|
|
||||||
public String getTaskId() {
|
|
||||||
return taskId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskId(String taskId) {
|
|
||||||
this.taskId = taskId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOwner() {
|
|
||||||
return owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOwner(String owner) {
|
|
||||||
this.owner = owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TaskState getTaskState() {
|
|
||||||
return taskState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskState(TaskState taskState) {
|
|
||||||
this.taskState = taskState;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "TaskIdOwnerState [taskId="
|
|
||||||
+ taskId
|
|
||||||
+ ", owner="
|
|
||||||
+ owner
|
|
||||||
+ ", taskState="
|
|
||||||
+ taskState
|
|
||||||
+ "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -113,15 +113,15 @@ class UpdateTaskAccTest extends AbstractAccTest {
|
||||||
void testThrowsExceptionIfTaskHasAlreadyBeenUpdated()
|
void testThrowsExceptionIfTaskHasAlreadyBeenUpdated()
|
||||||
throws NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
throws NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException,
|
||||||
TaskNotFoundException, ConcurrencyException, AttachmentPersistenceException,
|
TaskNotFoundException, ConcurrencyException, AttachmentPersistenceException,
|
||||||
InvalidStateException {
|
InvalidStateException, InterruptedException {
|
||||||
|
|
||||||
TaskService taskService = taskanaEngine.getTaskService();
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
|
Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
|
||||||
Task task2 = taskService.getTask("TKI:000000000000000000000000000000000000");
|
final Task task2 = taskService.getTask("TKI:000000000000000000000000000000000000");
|
||||||
|
|
||||||
task.setCustomAttribute("1", "willi");
|
task.setCustomAttribute("1", "willi");
|
||||||
|
Thread.sleep(10);
|
||||||
taskService.updateTask(task);
|
taskService.updateTask(task);
|
||||||
|
|
||||||
task2.setCustomAttribute("2", "Walter");
|
task2.setCustomAttribute("2", "Walter");
|
||||||
// TODO flaky test ... if speed is too high,
|
// TODO flaky test ... if speed is too high,
|
||||||
assertThatThrownBy(() -> taskService.updateTask(task2))
|
assertThatThrownBy(() -> taskService.updateTask(task2))
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package acceptance.taskrouting;
|
package acceptance.taskrouting;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||||
|
|
||||||
import acceptance.AbstractAccTest;
|
import acceptance.AbstractAccTest;
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
|
|
@ -37,15 +37,15 @@ class TaskRoutingAccTest extends AbstractAccTest {
|
||||||
newTask.setPrimaryObjRef(
|
newTask.setPrimaryObjRef(
|
||||||
createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||||
final Task taskToCreate = newTask;
|
final Task taskToCreate = newTask;
|
||||||
Assertions.assertThrows(
|
assertThatThrownBy(() -> taskService.createTask(taskToCreate))
|
||||||
InvalidArgumentException.class, () -> taskService.createTask(taskToCreate));
|
.isInstanceOf(InvalidArgumentException.class);
|
||||||
((TaskImpl) taskToCreate).setDomain("DOMAIN_C");
|
((TaskImpl) taskToCreate).setDomain("DOMAIN_C");
|
||||||
Assertions.assertThrows(
|
assertThatThrownBy(() -> taskService.createTask(taskToCreate))
|
||||||
InvalidArgumentException.class, () -> taskService.createTask(taskToCreate));
|
.isInstanceOf(InvalidArgumentException.class);
|
||||||
((TaskImpl) taskToCreate).setDomain("DOMAIN_B");
|
((TaskImpl) taskToCreate).setDomain("DOMAIN_B");
|
||||||
Task createdTask = taskService.createTask(taskToCreate);
|
Task createdTask = taskService.createTask(taskToCreate);
|
||||||
assertEquals(
|
assertThat("WBI:100000000000000000000000000000000011")
|
||||||
"WBI:100000000000000000000000000000000011", createdTask.getWorkbasketSummary().getId());
|
.isEqualTo(createdTask.getWorkbasketSummary().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
|
|
@ -56,12 +56,49 @@ class TaskRoutingAccTest extends AbstractAccTest {
|
||||||
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||||
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException {
|
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException {
|
||||||
TaskImpl createdTaskA = createTask("DOMAIN_A", "L12010");
|
TaskImpl createdTaskA = createTask("DOMAIN_A", "L12010");
|
||||||
assertEquals(
|
assertThat("WBI:100000000000000000000000000000000001")
|
||||||
"WBI:100000000000000000000000000000000001", createdTaskA.getWorkbasketSummary().getId());
|
.isEqualTo(createdTaskA.getWorkbasketSummary().getId());
|
||||||
TaskImpl createdTaskB = createTask("DOMAIN_B", "T21001");
|
TaskImpl createdTaskB = createTask("DOMAIN_B", "T21001");
|
||||||
assertEquals(
|
assertThat("WBI:100000000000000000000000000000000011")
|
||||||
"WBI:100000000000000000000000000000000011", createdTaskB.getWorkbasketSummary().getId());
|
.isEqualTo(createdTaskB.getWorkbasketSummary().getId());
|
||||||
Assertions.assertThrows(InvalidArgumentException.class, () -> createTask(null, "L12010"));
|
assertThatThrownBy(() -> createTask(null, "L12010"))
|
||||||
|
.isInstanceOf(InvalidArgumentException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(
|
||||||
|
userName = "admin",
|
||||||
|
groupNames = {"group_1"})
|
||||||
|
@Test
|
||||||
|
void testCreateTaskWithNullRouting()
|
||||||
|
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||||
|
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException {
|
||||||
|
|
||||||
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
|
Task newTask = taskService.newTask(null, "DOMAIN_A");
|
||||||
|
newTask.setClassificationKey("L12010");
|
||||||
|
newTask.setPrimaryObjRef(
|
||||||
|
createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||||
|
newTask.setCustomAttribute("7", "noRouting");
|
||||||
|
assertThatThrownBy(() -> taskService.createTask(newTask))
|
||||||
|
.isInstanceOf(InvalidArgumentException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(
|
||||||
|
userName = "admin",
|
||||||
|
groupNames = {"group_1"})
|
||||||
|
@Test
|
||||||
|
void testCreateTaskWithRoutingToMultipleWorkbaskets()
|
||||||
|
throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException,
|
||||||
|
TaskAlreadyExistException, InvalidArgumentException, TaskNotFoundException {
|
||||||
|
|
||||||
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
|
Task newTask = taskService.newTask(null, "DOMAIN_B");
|
||||||
|
newTask.setClassificationKey("L12010");
|
||||||
|
newTask.setPrimaryObjRef(
|
||||||
|
createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||||
|
newTask.setCustomAttribute("7", "multipleWorkbaskets");
|
||||||
|
assertThatThrownBy(() -> taskService.createTask(newTask))
|
||||||
|
.isInstanceOf(InvalidArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TaskImpl createTask(String domain, String classificationKey)
|
private TaskImpl createTask(String domain, String classificationKey)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
package acceptance.taskrouting;
|
package acceptance.taskrouting;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import pro.taskana.common.api.TaskanaEngine;
|
import pro.taskana.common.api.TaskanaEngine;
|
||||||
|
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||||
import pro.taskana.spi.routing.api.TaskRoutingProvider;
|
import pro.taskana.spi.routing.api.TaskRoutingProvider;
|
||||||
import pro.taskana.task.api.models.Task;
|
import pro.taskana.task.api.models.Task;
|
||||||
|
|
||||||
/** This is a sample implementation of TaskRouter. */
|
/** This is a sample implementation of TaskRouter. */
|
||||||
public class TestTaskRoutingProviderForDomainA implements TaskRoutingProvider {
|
public class TestTaskRoutingProviderForDomainA implements TaskRoutingProvider {
|
||||||
|
private static final Logger LOGGER =
|
||||||
|
LoggerFactory.getLogger(TestTaskRoutingProviderForDomainA.class);
|
||||||
TaskanaEngine theEngine;
|
TaskanaEngine theEngine;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -16,8 +21,21 @@ public class TestTaskRoutingProviderForDomainA implements TaskRoutingProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String determineWorkbasketId(Task task) {
|
public String determineWorkbasketId(Task task) {
|
||||||
if ("DOMAIN_A".equals(task.getDomain())) {
|
String att7 = "";
|
||||||
return "WBI:100000000000000000000000000000000001";
|
try {
|
||||||
|
att7 = task.getCustomAttribute("7");
|
||||||
|
} catch (InvalidArgumentException ex) {
|
||||||
|
LOGGER.warn("caught exception ", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (att7 != null && att7.equals("multipleWorkbaskets")) {
|
||||||
|
return "WBI:100000000000000000000000000000000005";
|
||||||
|
} else if ("DOMAIN_A".equals(task.getDomain())) {
|
||||||
|
if (att7 != null && att7.equals("noRouting")) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return "WBI:100000000000000000000000000000000001";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue