TSK-1060: Add sort by taskId to TaskQuery
This commit is contained in:
parent
ca6dd310ce
commit
10e888acd4
|
|
@ -643,6 +643,15 @@ public interface TaskQuery extends BaseQuery<TaskSummary, TaskQueryColumnName> {
|
||||||
*/
|
*/
|
||||||
TaskQuery orderByDue(SortDirection sortDirection);
|
TaskQuery orderByDue(SortDirection sortDirection);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sorts the query result according to the primary task id.
|
||||||
|
*
|
||||||
|
* @param sortDirection Determines whether the result is sorted in ascending or descending order.
|
||||||
|
* If sortDirection is null, the result is sorted in ascending order
|
||||||
|
* @return the query
|
||||||
|
*/
|
||||||
|
TaskQuery orderByTaskId(SortDirection sortDirection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sorts the query result according to the modified timestamp.
|
* This method sorts the query result according to the modified timestamp.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -753,6 +753,11 @@ public class TaskQueryImpl implements TaskQuery {
|
||||||
return addOrderCriteria("DUE", sortDirection);
|
return addOrderCriteria("DUE", sortDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TaskQuery orderByTaskId(SortDirection sortDirection) {
|
||||||
|
return addOrderCriteria("ID", sortDirection);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TaskQuery orderByModified(SortDirection sortDirection) {
|
public TaskQuery orderByModified(SortDirection sortDirection) {
|
||||||
return addOrderCriteria("MODIFIED", sortDirection);
|
return addOrderCriteria("MODIFIED", sortDirection);
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,15 @@ package acceptance.task;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.core.IsEqual.equalTo;
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import acceptance.AbstractAccTest;
|
import acceptance.AbstractAccTest;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
@ -53,6 +57,57 @@ class QueryTasksWithSortingAccTest extends AbstractAccTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WithAccessId(
|
||||||
|
userName = "teamlead_1",
|
||||||
|
groupNames = {"group_1", "group_2"})
|
||||||
|
@Test
|
||||||
|
void testSortByTaskIdDesc() {
|
||||||
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
|
List<TaskSummary> results =
|
||||||
|
taskService
|
||||||
|
.createTaskQuery()
|
||||||
|
.workbasketKeyDomainIn(new KeyDomain("USER_3_2", "DOMAIN_B"))
|
||||||
|
.orderByTaskId(desc)
|
||||||
|
.list();
|
||||||
|
|
||||||
|
// test is only valid with at least 2 results
|
||||||
|
Assertions.assertTrue(results.size() > 2);
|
||||||
|
|
||||||
|
List<String> idsDesc =
|
||||||
|
results.stream()
|
||||||
|
.map(TaskSummary::getTaskId)
|
||||||
|
.sorted(Comparator.reverseOrder())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (int i = 0; i < results.size(); i++) {
|
||||||
|
assertEquals(idsDesc.get(i), results.get(i).getTaskId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@WithAccessId(
|
||||||
|
userName = "teamlead_1",
|
||||||
|
groupNames = {"group_1", "group_2"})
|
||||||
|
@Test
|
||||||
|
void testSortByTaskIdAsc() {
|
||||||
|
TaskService taskService = taskanaEngine.getTaskService();
|
||||||
|
List<TaskSummary> results =
|
||||||
|
taskService
|
||||||
|
.createTaskQuery()
|
||||||
|
.workbasketKeyDomainIn(new KeyDomain("USER_3_2", "DOMAIN_B"))
|
||||||
|
.orderByTaskId(null)
|
||||||
|
.list();
|
||||||
|
|
||||||
|
// test is only valid with at least 2 results
|
||||||
|
Assertions.assertTrue(results.size() > 2);
|
||||||
|
|
||||||
|
List<String> idsAsc =
|
||||||
|
results.stream().map(TaskSummary::getTaskId).sorted().collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (int i = 0; i < results.size(); i++) {
|
||||||
|
assertEquals(idsAsc.get(i), results.get(i).getTaskId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@WithAccessId(
|
@WithAccessId(
|
||||||
userName = "teamlead_1",
|
userName = "teamlead_1",
|
||||||
groupNames = {"group_1", "group_2"})
|
groupNames = {"group_1", "group_2"})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue