Search in sources :

Example 36 with WebOptions

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);
}
Also used : WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) GeoFeature(org.hisp.dhis.webapi.webdomain.GeoFeature) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 37 with WebOptions

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()));
}
Also used : BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DataItem(org.hisp.dhis.dataitem.DataItem) OrderParams(org.hisp.dhis.dxf2.common.OrderParams) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Test(org.junit.jupiter.api.Test)

Example 38 with WebOptions

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));
}
Also used : User(org.hisp.dhis.user.User) DataItem(org.hisp.dhis.dataitem.DataItem) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Indicator(org.hisp.dhis.indicator.Indicator) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) OrderParams(org.hisp.dhis.dxf2.common.OrderParams) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Test(org.junit.jupiter.api.Test)

Example 39 with WebOptions

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));
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) User(org.hisp.dhis.user.User) CollectionHelper.asSet(org.hibernate.validator.internal.util.CollectionHelper.asSet) DataSet(org.hisp.dhis.dataset.DataSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Pager(org.hisp.dhis.common.Pager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Example 40 with WebOptions

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));
}
Also used : DataItem(org.hisp.dhis.dataitem.DataItem) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) Test(org.junit.jupiter.api.Test)

Aggregations

WebOptions (org.hisp.dhis.webapi.webdomain.WebOptions)45 RootNode (org.hisp.dhis.node.types.RootNode)21 Test (org.junit.jupiter.api.Test)18 Pager (org.hisp.dhis.common.Pager)16 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)14 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)13 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)12 DataItem (org.hisp.dhis.dataitem.DataItem)10 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)10 User (org.hisp.dhis.user.User)9 WebMetadata (org.hisp.dhis.webapi.webdomain.WebMetadata)9 List (java.util.List)8 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)7 Order (org.hisp.dhis.query.Order)7 Query (org.hisp.dhis.query.Query)7 ArrayList (java.util.ArrayList)6 CollectionNode (org.hisp.dhis.node.types.CollectionNode)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 HashMap (java.util.HashMap)5