TSK-734: Added new method signature for TaskService.updateTask
This commit is contained in:
parent
92dfc99783
commit
9596875310
|
|
@ -373,7 +373,7 @@ public interface TaskService {
|
||||||
throws InvalidArgumentException;
|
throws InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completes tasks with a matching {@link ObjectReference}.
|
* Updates tasks with a matching {@link ObjectReference}.
|
||||||
*
|
*
|
||||||
* @param selectionCriteria
|
* @param selectionCriteria
|
||||||
* the {@link ObjectReference} that is used to select the tasks.
|
* the {@link ObjectReference} that is used to select the tasks.
|
||||||
|
|
@ -388,4 +388,21 @@ public interface TaskService {
|
||||||
*/
|
*/
|
||||||
List<String> updateTasks(ObjectReference selectionCriteria,
|
List<String> updateTasks(ObjectReference selectionCriteria,
|
||||||
Map<String, String> customFieldsToUpdate) throws InvalidArgumentException;
|
Map<String, String> customFieldsToUpdate) throws InvalidArgumentException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates tasks with matching taskIds.
|
||||||
|
*
|
||||||
|
* @param taskIds
|
||||||
|
* the taskIds that are used to select the tasks.
|
||||||
|
* @param customFieldsToUpdate
|
||||||
|
* a {@link Map} that contains as key the identification of the custom field and as value the
|
||||||
|
* corresponding new value of that custom field. The key for identification of the custom field must be a
|
||||||
|
* String with value "1", "2" ... "16" as in the setCustomAttribute or getCustomAttribute method of
|
||||||
|
* {@link Task}
|
||||||
|
* @return a list of the Ids of all modified tasks
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
* If the customFieldsToUpdate map contains an invalid key or if the selectionCriteria is invalid
|
||||||
|
*/
|
||||||
|
List<String> updateTasks(List<String> taskIds,
|
||||||
|
Map<String, String> customFieldsToUpdate) throws InvalidArgumentException;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1127,6 +1127,60 @@ public class TaskServiceImpl implements TaskService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> updateTasks(List<String> taskIds,
|
||||||
|
Map<String, String> customFieldsToUpdate) throws InvalidArgumentException {
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("entry to updateTasks(taskIds = {}, customFieldsToUpdate = {})", taskIds,
|
||||||
|
customFieldsToUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customFieldsToUpdate == null || customFieldsToUpdate.isEmpty()) {
|
||||||
|
throw new InvalidArgumentException("The customFieldsToUpdate argument to updateTasks must not be empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> allowedKeys = new HashSet<>(
|
||||||
|
Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
taskanaEngine.openConnection();
|
||||||
|
|
||||||
|
CustomPropertySelector fieldSelector = new CustomPropertySelector();
|
||||||
|
TaskImpl newTask = new TaskImpl();
|
||||||
|
newTask.setModified(Instant.now());
|
||||||
|
for (Map.Entry<String, String> entry : customFieldsToUpdate.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
if (!allowedKeys.contains(key)) {
|
||||||
|
throw new InvalidArgumentException(
|
||||||
|
"The customFieldsToUpdate argument to updateTasks contains invalid key " + key);
|
||||||
|
} else {
|
||||||
|
fieldSelector.setCustomProperty(key, true);
|
||||||
|
newTask.setCustomAttribute(key, entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// use query in order to find only those tasks that are visible to the current user
|
||||||
|
List<TaskSummary> taskSummaries = createTaskQuery()
|
||||||
|
.idIn(taskIds.toArray(new String[taskIds.size()]))
|
||||||
|
.list();
|
||||||
|
|
||||||
|
List<String> changedTasks = new ArrayList<>();
|
||||||
|
if (!taskSummaries.isEmpty()) {
|
||||||
|
changedTasks = taskSummaries.stream().map(TaskSummary::getTaskId).collect(Collectors.toList());
|
||||||
|
taskMapper.updateTasks(changedTasks, newTask, fieldSelector);
|
||||||
|
LOGGER.debug("updateTasks() updated the following tasks: {} ",
|
||||||
|
LoggerUtils.listToString(changedTasks));
|
||||||
|
} else {
|
||||||
|
LOGGER.debug("updateTasks() found no tasks for update ");
|
||||||
|
}
|
||||||
|
return changedTasks;
|
||||||
|
} finally {
|
||||||
|
LOGGER.debug("exit from deleteTasks().");
|
||||||
|
taskanaEngine.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
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -289,6 +290,37 @@ public class UpdateTaskAccTest extends AbstractAccTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WithAccessId(
|
||||||
|
userName = "teamlead_1",
|
||||||
|
groupNames = {"group_1"}
|
||||||
|
)
|
||||||
|
@Test
|
||||||
|
public void testUpdateTasksById()
|
||||||
|
throws InvalidArgumentException, TaskNotFoundException, NotAuthorizedException {
|
||||||
|
List<String> taskIds = Arrays.asList(
|
||||||
|
"TKI:000000000000000000000000000000000008",
|
||||||
|
"TKI:000000000000000000000000000000000009",
|
||||||
|
"TKI:000000000000000000000000000000000010");
|
||||||
|
Map<String, String> customProperties = new HashMap<>();
|
||||||
|
customProperties.put("1", "This is modifiedValue 1");
|
||||||
|
customProperties.put("5", "This is modifiedValue 5");
|
||||||
|
customProperties.put("10", "This is modifiedValue 10");
|
||||||
|
customProperties.put("12", "This is modifiedValue 12");
|
||||||
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
|
|
||||||
|
List<String> changedTasks = taskService.updateTasks(taskIds, customProperties);
|
||||||
|
assertEquals(3, changedTasks.size());
|
||||||
|
for (String taskId : changedTasks) {
|
||||||
|
Task task = taskService.getTask(taskId);
|
||||||
|
assertEquals("This is modifiedValue 1", task.getCustomAttribute("1"));
|
||||||
|
assertEquals("This is modifiedValue 5", task.getCustomAttribute("5"));
|
||||||
|
assertEquals("This is modifiedValue 10", task.getCustomAttribute("10"));
|
||||||
|
assertEquals("This is modifiedValue 12", task.getCustomAttribute("12"));
|
||||||
|
assertNull(task.getCustomAttribute("2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
userName = "user_1_1",
|
userName = "user_1_1",
|
||||||
groupNames = {"group_1"})
|
groupNames = {"group_1"})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue