use of org.hisp.dhis.query.Pagination in project dhis2-core by dhis2.
the class MessageConversationController method getEntityList.
@Override
@SuppressWarnings("unchecked")
protected List<org.hisp.dhis.message.MessageConversation> getEntityList(WebMetadata metadata, WebOptions options, List<String> filters, List<Order> orders) throws QueryParserException {
List<org.hisp.dhis.message.MessageConversation> messageConversations;
if (options.getOptions().containsKey("query")) {
messageConversations = Lists.newArrayList(manager.filter(getEntityClass(), options.getOptions().get("query")));
} else {
messageConversations = new ArrayList<>(messageService.getMessageConversations());
}
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, orders, new Pagination(), options.getRootJunction());
query.setDefaultOrder();
query.setDefaults(Defaults.valueOf(options.get("defaults", DEFAULTS)));
query.setObjects(messageConversations);
messageConversations = (List<org.hisp.dhis.message.MessageConversation>) queryService.query(query);
if (options.get("queryString") != null) {
String queryOperator = "token";
if (options.get("queryOperator") != null) {
queryOperator = options.get("queryOperator");
}
List<String> queryFilter = Arrays.asList("subject:" + queryOperator + ":" + options.get("queryString"), "messages.text:" + queryOperator + ":" + options.get("queryString"), "messages.sender.displayName:" + queryOperator + ":" + options.get("queryString"));
Query subQuery = queryService.getQueryFromUrl(getEntityClass(), queryFilter, Collections.emptyList(), new Pagination(), Junction.Type.OR);
subQuery.setObjects(messageConversations);
messageConversations = (List<org.hisp.dhis.message.MessageConversation>) queryService.query(subQuery);
}
int count = messageConversations.size();
Query paginatedQuery = queryService.getQueryFromUrl(getEntityClass(), Collections.emptyList(), Collections.emptyList(), getPaginationData(options), options.getRootJunction());
paginatedQuery.setObjects(messageConversations);
messageConversations = (List<org.hisp.dhis.message.MessageConversation>) queryService.query(paginatedQuery);
if (options.hasPaging()) {
Pager pager = new Pager(options.getPage(), count, options.getPageSize());
metadata.setPager(pager);
}
return messageConversations;
}
use of org.hisp.dhis.query.Pagination in project dhis2-core by dhis2.
the class PaginationUtilsTest method verifyIgnoreNegativePage.
@Test
void verifyIgnoreNegativePage() {
Map<String, String> options = new HashMap<>();
options.put(WebOptions.PAGING, "true");
options.put(WebOptions.PAGE, "-2");
options.put(WebOptions.PAGE_SIZE, "200");
WebOptions webOptions = new WebOptions(options);
Pagination paginationData = PaginationUtils.getPaginationData(webOptions);
assertThat(paginationData.getFirstResult(), is(0));
assertThat(paginationData.getSize(), is(200));
}
use of org.hisp.dhis.query.Pagination in project dhis2-core by dhis2.
the class PaginationUtilsTest method verifyPaginationIsDisabled.
@Test
void verifyPaginationIsDisabled() {
Map<String, String> options = new HashMap<>();
options.put(WebOptions.PAGING, "false");
WebOptions webOptions = new WebOptions(options);
Pagination paginationData = PaginationUtils.getPaginationData(webOptions);
assertThat(paginationData.getFirstResult(), is(0));
assertThat(paginationData.getSize(), is(0));
assertThat(paginationData.hasPagination(), is(false));
}
use of org.hisp.dhis.query.Pagination in project dhis2-core by dhis2.
the class UserController method makeQuery.
private Query makeQuery(WebOptions options, List<String> filters, List<Order> orders, UserQueryParams params) {
Pagination pagination = CollectionUtils.isEmpty(filters) ? new Pagination() : getPaginationData(options);
List<String> ordersAsString = (orders == null) ? null : orders.stream().map(Order::toOrderString).collect(Collectors.toList());
/*
* Keep the memory query on the result
*/
Query query = queryService.getQueryFromUrl(getEntityClass(), filters, orders, pagination, options.getRootJunction());
// Fetches all users if there are no query, i.e only filters...
List<User> users = userService.getUsers(params, ordersAsString);
query.setObjects(users);
query.setDefaults(Defaults.valueOf(options.get("defaults", DEFAULTS)));
query.setDefaultOrder();
return query;
}
use of org.hisp.dhis.query.Pagination in project dhis2-core by dhis2.
the class PaginationUtilsTest method verifyPaginationStartsAtZero.
@Test
void verifyPaginationStartsAtZero() {
Map<String, String> options = new HashMap<>();
options.put(WebOptions.PAGING, "true");
options.put(WebOptions.PAGE, "1");
options.put(WebOptions.PAGE_SIZE, "20");
WebOptions webOptions = new WebOptions(options);
Pagination paginationData = PaginationUtils.getPaginationData(webOptions);
assertThat(paginationData.getFirstResult(), is(0));
assertThat(paginationData.getSize(), is(20));
}
Aggregations