@Override protected QuerySortOrder createSortOrder(String by, SortDirection direction) { return new QuerySortOrder(by, direction); } }
/** * Appends sorting with given sort direction. * * @param by * the object to sort by * @param direction * the sort direction * * @return this sort builder */ protected SortBuilder append(String by, SortDirection direction) { sortOrder.add(new QuerySortOrder(by, direction)); return this; }
/** * Sets strings describing back end properties to be used when sorting * this column. * <p> * By default, the {@link #setId(String) column id} will be used as the * sort property. * * @param properties * the array of strings describing backend properties * @return this column */ public Column<T, V> setSortProperty(String... properties) { Objects.requireNonNull(properties, "Sort properties can't be null"); return setSortOrderProvider(dir -> Arrays.stream(properties) .map(s -> new QuerySortOrder(s, dir))); }
@Test public void getItemsWithGrouping() throws Exception { // GIVEN dataProvider.filterByCategory(PulseItemCategory.INFO); dataProvider.setGrouping(true); Query query = new Query<Message, Void>(0, 3, ImmutableList.of(new QuerySortOrder(MessageConstants.ID, SortDirection.ASCENDING)), null, null); // WHEN List<Message> items = (List<Message>) dataProvider.fetchFromBackEnd(query).collect(Collectors.toList()); // THEN no additional data for grouping assertThat(items.size(), is(3)); assertThat(items, containsIdsInOrder(7, 8, 9)); } }
@Test public void getItems() throws Exception { // GIVEN WHEN dataProvider.filterByCategory(PulseItemCategory.ALL_TASKS); Query query = new Query<Task, Void>(0, 9, Collections.emptyList(), null, null); List<Task> items = (List<Task>) dataProvider.fetchFromBackEnd(query).collect(Collectors.toList()); dataProvider.filterByCategory(PulseItemCategory.UNCLAIMED); query = new Query<Task, Void>(0, 3, ImmutableList.of(new QuerySortOrder(TaskConstants.ID, SortDirection.DESCENDING)), null, null); List<Task> itemsSorted = (List<Task>) dataProvider.fetchFromBackEnd(query).collect(Collectors.toList()); // THEN assertThat(items.size(), is(9)); assertThat(items, containsIdsInOrder(1, 2, 3, 4, 5, 6, 7, 8, 9)); assertThat(itemsSorted.size(), is(3)); assertThat(itemsSorted, containsIdsInOrder(3, 2, 1)); } }
@Test public void getItems() throws Exception { // GIVEN WHEN dataProvider.filterByCategory(PulseItemCategory.ALL_MESSAGES); Query query = new Query<Message, Void>(0, 9, Collections.emptyList(), null, null); List<Message> items = (List<Message>) dataProvider.fetchFromBackEnd(query).collect(Collectors.toList()); dataProvider.filterByCategory(PulseItemCategory.PROBLEM); query = new Query<Message, Void>(0, 6, ImmutableList.of(new QuerySortOrder(MessageConstants.ID, SortDirection.DESCENDING)), null, null); List<Message> itemsSorted = (List<Message>) dataProvider.fetchFromBackEnd(query).collect(Collectors.toList()); // THEN assertThat(items.size(), is(9)); assertThat(items, containsIdsInOrder(1, 2, 3, 4, 5, 6, 7, 8, 9)); assertThat(itemsSorted.size(), is(6)); assertThat(itemsSorted, containsIdsInOrder(6, 5, 4, 3, 2, 1)); }