use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class PaginationHelperTest method testPaginateWhenFirstPage.
@Test
void testPaginateWhenFirstPage() {
// Given
final int pageSize = 5;
final int firstPage = 1;
final int totalOfItems = 13;
final WebOptions theWebOptions = mockWebOptions(pageSize, firstPage);
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 DataItemQueryControllerTest method testGetWithSuccess.
@Test
void testGetWithSuccess() {
// Given
final Map<String, String> anyUrlParameters = new HashMap<>();
final OrderParams anyOrderParams = new OrderParams();
final User anyUser = new User();
final Set<Class<? extends BaseIdentifiableObject>> targetEntities = new HashSet<>(singletonList(Indicator.class));
final List<DataItem> itemsFound = singletonList(new DataItem());
// When
when(dataItemServiceFacade.extractTargetEntities(anySet())).thenReturn(targetEntities);
when(aclService.canRead(anyUser, Indicator.class)).thenReturn(true);
when(dataItemServiceFacade.retrieveDataItemEntities(anySet(), anySet(), any(WebOptions.class), any(OrderParams.class))).thenReturn(itemsFound);
final ResponseEntity<RootNode> actualResponse = dataItemQueryController.getJson(anyUrlParameters, anyOrderParams, anyUser);
// Then
assertThat(actualResponse, is(not(nullValue())));
assertThat(actualResponse.getStatusCode(), is(OK));
verify(responseHandler, times(1)).addResultsToNode(any(RootNode.class), anyList(), anySet());
verify(responseHandler, times(1)).addPaginationToNode(any(RootNode.class), anySet(), any(), any(), anySet());
}
use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class DataItemQueryControllerTest method testGetWhenItemsAreNotFound.
@Test
void testGetWhenItemsAreNotFound() {
// Given
final Map<String, String> anyUrlParameters = new HashMap<>();
final OrderParams anyOrderParams = new OrderParams();
final User anyUser = new User();
final Set<Class<? extends BaseIdentifiableObject>> targetEntities = new HashSet<>(singletonList(Indicator.class));
final List<DataItem> itemsFound = emptyList();
// When
when(dataItemServiceFacade.extractTargetEntities(anySet())).thenReturn(targetEntities);
when(aclService.canRead(anyUser, Indicator.class)).thenReturn(true);
when(dataItemServiceFacade.retrieveDataItemEntities(anySet(), anySet(), any(WebOptions.class), any(OrderParams.class))).thenReturn(itemsFound);
final ResponseEntity<RootNode> actualResponse = dataItemQueryController.getJson(anyUrlParameters, anyOrderParams, anyUser);
// Then
assertThat(actualResponse, is(not(nullValue())));
assertThat(actualResponse.getStatusCode(), is(OK));
verify(responseHandler, times(1)).addResultsToNode(any(), anyList(), anySet());
verify(responseHandler, times(1)).addPaginationToNode(any(), anySet(), any(), any(), anySet());
}
use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class DataItemQueryController method getDimensionalItems.
/**
* Based on the informed arguments, this method will read the URL and based
* on the give params will retrieve the respective data items.
*
* @param currentUser the logged user
* @param urlParameters the request url params
* @param orderParams the request order params
* @return the complete root node
*/
private ResponseEntity<RootNode> getDimensionalItems(final User currentUser, final Map<String, String> urlParameters, final OrderParams orderParams) {
// Defining the input params.
final Set<String> fields = newHashSet(contextService.getParameterValues(FIELDS));
final Set<String> filters = newHashSet(contextService.getParameterValues(FILTER));
final WebOptions options = new WebOptions(urlParameters);
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
checkNamesAndOperators(filters);
checkOrderParams(orderParams.getOrders());
// Extracting the target entities to be queried.
final Set<Class<? extends BaseIdentifiableObject>> targetEntities = dataItemServiceFacade.extractTargetEntities(filters);
// Checking if the user can read all the target entities.
checkAuthorization(currentUser, targetEntities);
// Retrieving the data items based on the input params.
final List<DataItem> dimensionalItems = dataItemServiceFacade.retrieveDataItemEntities(targetEntities, filters, options, orderParams);
// Creating the response node.
final RootNode rootNode = createMetadata();
responseHandler.addResultsToNode(rootNode, dimensionalItems, fields);
responseHandler.addPaginationToNode(rootNode, targetEntities, currentUser, options, filters);
return new ResponseEntity<>(rootNode, OK);
}
use of org.hisp.dhis.dataitem.DataItem in project dhis2-core by dhis2.
the class DataItemServiceFacadeTest method testRetrieveDataItemEntitiesWhenTargetEntitiesIsEmpty.
@Test
void testRetrieveDataItemEntitiesWhenTargetEntitiesIsEmpty() {
// Given
final Set<Class<? extends BaseIdentifiableObject>> anyTargetEntities = emptySet();
final Set<String> anyFilters = newHashSet("anyFilter");
final WebOptions anyWebOptions = mockWebOptions(10, 1);
final Set<String> anyOrdering = new HashSet<>(asList("name:desc"));
final OrderParams anyOrderParams = new OrderParams(anyOrdering);
// When
final List<DataItem> actualDimensionalItems = dataItemServiceFacade.retrieveDataItemEntities(anyTargetEntities, anyFilters, anyWebOptions, anyOrderParams);
// Then
assertThat(actualDimensionalItems, is(empty()));
}
Aggregations