use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class DataItemServiceFacade method retrieveDataItemEntities.
/**
* This method will iterate through the list of target entities, and query
* each one of them using the filters and params provided. The result list
* will bring together the results of all target entities queried.
*
* @param targetEntities the list of entities to be retrieved
* @param orderParams request ordering params
* @param filters request filters
* @param options request options
* @return the consolidated collection of entities found.
*/
List<DataItem> retrieveDataItemEntities(final Set<Class<? extends BaseIdentifiableObject>> targetEntities, final Set<String> filters, final WebOptions options, final OrderParams orderParams) {
final List<DataItem> dataItems = new ArrayList<>();
final User currentUser = currentUserService.getCurrentUser();
if (isNotEmpty(targetEntities)) {
// Defining the query params map, and setting the common params.
final MapSqlParameterSource paramsMap = new MapSqlParameterSource().addValue("userUid", currentUser.getUid());
setFilteringParams(filters, options, paramsMap, currentUser);
setOrderingParams(orderParams, paramsMap);
setMaxResultsWhenPaging(options, paramsMap);
dataItems.addAll(queryExecutor.find(targetEntities, paramsMap));
// In memory pagination.
return paginate(options, dataItems);
}
return dataItems;
}
use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class PaginationHelperTest method testPaginateWhenIntermediatePage.
@Test
void testPaginateWhenIntermediatePage() {
// Given
final int pageSize = 5;
final int secondPage = 2;
final int totalOfItems = 13;
final WebOptions theWebOptions = mockWebOptions(pageSize, secondPage);
final List<DataItem> anyDimensionalItems = mockDimensionalItems(totalOfItems);
// When
final List<DataItem> resultingList = paginate(theWebOptions, anyDimensionalItems);
// Then
assertThat(resultingList, hasSize(5));
}
use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class PaginationHelperTest method testPaginateWhenLastPage.
@Test
void testPaginateWhenLastPage() {
// Given
final int pageSize = 5;
final int lastPage = 3;
final int totalOfItems = 13;
final WebOptions theWebOptions = mockWebOptions(pageSize, lastPage);
final List<DataItem> anyDimensionalItems = mockDimensionalItems(totalOfItems);
// When
final List<DataItem> resultingList = paginate(theWebOptions, anyDimensionalItems);
// Then
assertThat(resultingList, hasSize(3));
}
use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class PaginationHelperTest method testPaginateWhenPageSizeIsZero.
@Test
void testPaginateWhenPageSizeIsZero() {
// Given
final int pageSize = 0;
final int lastPage = 3;
final int totalOfItems = 13;
final WebOptions theWebOptions = mockWebOptions(pageSize, lastPage);
final List<DataItem> anyDimensionalItems = mockDimensionalItems(totalOfItems);
// When
assertThrows(IllegalStateException.class, () -> paginate(theWebOptions, anyDimensionalItems), "Page size must be greater than zero.");
}
use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class PaginationHelperTest method mockDimensionalItems.
private List<DataItem> mockDimensionalItems(final int totalOfItems) {
final List<DataItem> dataItemEntities = new ArrayList<>(0);
for (int i = 0; i < totalOfItems; i++) {
final DataItem dataItem = DataItem.builder().name("d-" + i).id("d-" + i).build();
dataItemEntities.add(dataItem);
}
return dataItemEntities;
}
Aggregations