use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class GeoFeatureController method getGeoFeaturesJson.
// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@GetMapping
@ResponseBody
public ResponseEntity<List<GeoFeature>> getGeoFeaturesJson(@RequestParam(required = false) String ou, @RequestParam(required = false) String oug, @RequestParam(required = false) DisplayProperty displayProperty, @RequestParam(required = false) Date relativePeriodDate, @RequestParam(required = false) String userOrgUnit, @RequestParam(required = false) String coordinateField, @RequestParam(defaultValue = "false", value = "includeGroupSets") boolean rpIncludeGroupSets, @RequestParam Map<String, String> parameters, DhisApiVersion apiVersion, HttpServletRequest request, HttpServletResponse response) {
WebOptions options = new WebOptions(parameters);
boolean includeGroupSets = "detailed".equals(options.getViewClass()) || rpIncludeGroupSets;
List<GeoFeature> features = geoFeatureService.getGeoFeatures(GeoFeatureService.Parameters.builder().apiVersion(apiVersion).displayProperty(displayProperty).includeGroupSets(includeGroupSets).request(request).response(response).organisationUnit(ou).userOrgUnit(userOrgUnit).organisationUnitGroupId(oug).relativePeriodDate(relativePeriodDate).coordinateField(coordinateField).build());
return ResponseEntity.ok().header(HttpHeaders.CACHE_CONTROL, GEOFEATURE_CACHE.getHeaderValue()).contentType(MediaType.APPLICATION_JSON).body(features);
}
use of org.hisp.dhis.webapi.webdomain.WebOptions 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()));
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class DataItemServiceFacadeTest method testRetrieveDataItemEntities.
@Test
void testRetrieveDataItemEntities() {
// Given
final Class<? extends BaseIdentifiableObject> targetEntity = Indicator.class;
final Set<Class<? extends BaseIdentifiableObject>> anyTargetEntities = new HashSet<>(asList(targetEntity));
final List<DataItem> expectedItemsFound = asList(mockDataItem(INDICATOR), mockDataItem(INDICATOR));
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);
final User currentUser = new User();
// When
when(currentUserService.getCurrentUser()).thenReturn(currentUser);
when(queryExecutor.find(anySet(), any(MapSqlParameterSource.class))).thenReturn(expectedItemsFound);
final List<DataItem> actualDimensionalItems = dataItemServiceFacade.retrieveDataItemEntities(anyTargetEntities, anyFilters, anyWebOptions, anyOrderParams);
// Then
assertThat(actualDimensionalItems, hasSize(2));
assertThat(actualDimensionalItems.get(0).getDimensionItemType(), is(INDICATOR));
assertThat(actualDimensionalItems.get(1).getDimensionItemType(), is(INDICATOR));
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class ResponseHandlerTest method testAddPaginationToNodeWhenTargetEntitiesIsEmpty.
@Test
void testAddPaginationToNodeWhenTargetEntitiesIsEmpty() {
// Given
final RootNode anyRootNode = new RootNode("any");
final Set<Class<? extends BaseIdentifiableObject>> emptyTargetEntities = emptySet();
final Set<String> anyFilters = newHashSet("any");
final User anyUser = new User();
final WebOptions anyWebOptions = mockWebOptions(10, 1);
// When
responseHandler.addPaginationToNode(anyRootNode, emptyTargetEntities, anyUser, anyWebOptions, anyFilters);
// Then
assertThat(anyRootNode, is(notNullValue()));
assertThat(anyRootNode.getName(), is(equalTo("any")));
assertThat(anyRootNode.getChildren(), is(empty()));
verify(linkService, never()).generatePagerLinks(any(Pager.class), anyString());
verify(queryExecutor, never()).count(any(Set.class), any(MapSqlParameterSource.class));
}
use of org.hisp.dhis.webapi.webdomain.WebOptions in project dhis2-core by dhis2.
the class PaginationHelperTest method testPaginateWhenDimensionalItemListIsEmpty.
@Test
void testPaginateWhenDimensionalItemListIsEmpty() {
// Given
final int pageSize = 5;
final int lastPage = 3;
final WebOptions theWebOptions = mockWebOptions(pageSize, lastPage);
final List<DataItem> emptyDimensionalItems = emptyList();
// When
final List<DataItem> resultingList = paginate(theWebOptions, emptyDimensionalItems);
// Then
assertThat(resultingList, is(emptyDimensionalItems));
assertThat(resultingList, hasSize(0));
}
Aggregations