Search in sources :

Example 26 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DataQueryServiceDimensionItemKeywordTest method testGetUserOrgUnits.

private void testGetUserOrgUnits(UserOrgUnitType userOrgUnitType) {
    int orgUnitSize = 10;
    User user = new User();
    Set<OrganisationUnit> orgUnits = rnd.objects(OrganisationUnit.class, orgUnitSize).collect(Collectors.toSet());
    switch(userOrgUnitType) {
        case DATA_CAPTURE:
            user.setOrganisationUnits(orgUnits);
            break;
        case DATA_OUTPUT:
            user.setDataViewOrganisationUnits(orgUnits);
            break;
        case TEI_SEARCH:
            user.setTeiSearchOrganisationUnits(orgUnits);
            break;
    }
    DataQueryRequest request = DataQueryRequest.newBuilder().userOrgUnitType(userOrgUnitType).build();
    DataQueryParams params = target.getFromRequest(request);
    when(securityManager.getCurrentUser(params)).thenReturn(user);
    List<OrganisationUnit> result = target.getUserOrgUnits(params, null);
    assertThat(result, hasSize(orgUnitSize));
    // Check collection is sorted
    assertTrue(Ordering.natural().isOrdered(result));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) User(org.hisp.dhis.user.User) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest)

Example 27 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithIndicatorGroup.

@Test
void convertAnalyticsRequestWithIndicatorGroup() {
    final String INDICATOR_GROUP_UID = "oehv9EO3vP7";
    when(dimensionService.getDataDimensionalItemObject(UID, "cYeuwXTCPkU")).thenReturn(new DataElement());
    IndicatorGroup indicatorGroup = new IndicatorGroup("dummy");
    indicatorGroup.setUid(INDICATOR_GROUP_UID);
    indicatorGroup.setCode("CODE_10");
    indicatorGroup.setMembers(Sets.newHashSet(new Indicator(), new Indicator()));
    when(idObjectManager.getObject(IndicatorGroup.class, UID, INDICATOR_GROUP_UID)).thenReturn(indicatorGroup);
    when(idObjectManager.getObject(OrganisationUnit.class, UID, "goRUwCHPg1M")).thenReturn(new OrganisationUnit("aaa"));
    when(idObjectManager.getObject(OrganisationUnit.class, UID, "fdc6uOvgoji")).thenReturn(new OrganisationUnit("bbb"));
    rb.addOuFilter("goRUwCHPg1M;fdc6uOvgoji");
    rb.addDimension("IN_GROUP-" + INDICATOR_GROUP_UID + ";cYeuwXTCPkU;Jtf34kNZhz");
    rb.addPeDimension(PERIOD_DIMENSION);
    DataQueryRequest request = DataQueryRequest.newBuilder().filter(rb.getFilterParams()).dimension(rb.getDimensionParams()).build();
    DataQueryParams params = target.getFromRequest(request);
    DimensionalObject dimension = params.getDimension("dx");
    assertThat(dimension.getDimensionItemKeywords().getKeywords(), hasSize(1));
    DimensionItemKeywords.Keyword aggregation = dimension.getDimensionItemKeywords().getKeywords().get(0);
    assertThat(aggregation.getMetadataItem().getUid(), is(indicatorGroup.getUid()));
    assertThat(aggregation.getMetadataItem().getCode(), is(indicatorGroup.getCode()));
    assertThat(aggregation.getMetadataItem().getName(), is(indicatorGroup.getName()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) IndicatorGroup(org.hisp.dhis.indicator.IndicatorGroup) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) Indicator(org.hisp.dhis.indicator.Indicator) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test)

Example 28 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithOrgUnitGroupAsFilter.

@Test
void convertAnalyticsRequestWithOrgUnitGroupAsFilter() {
    mockDimensionService();
    final String ouGroupUID = "gzcv65VyaGq";
    initOrgUnitGroup(ouGroupUID);
    rb.addPeDimension(PERIOD_DIMENSION);
    rb.addDimension(concatenateUuid(DATA_ELEMENT_1, DATA_ELEMENT_2, DATA_ELEMENT_3));
    rb.addOuFilter("OU_GROUP-" + ouGroupUID + ";" + rootOu.getUid());
    DataQueryRequest request = DataQueryRequest.newBuilder().dimension(rb.getDimensionParams()).filter(rb.getFilterParams()).build();
    DataQueryParams params = target.getFromRequest(request);
    assertOrgUnitGroup(ouGroupUID, params.getFilter("ou"));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) Test(org.junit.jupiter.api.Test)

Example 29 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithOrgUnitLevelAsFilter.

@Test
void convertAnalyticsRequestWithOrgUnitLevelAsFilter() {
    OrganisationUnit level2OuA = new OrganisationUnit("Bo");
    OrganisationUnit level2OuB = new OrganisationUnit("Bombali");
    mockDimensionService();
    when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("wjP19dkFeIk")).thenReturn(2);
    when(idObjectManager.getObject(OrganisationUnit.class, UID, "ImspTQPwCqd")).thenReturn(rootOu);
    when(organisationUnitService.getOrganisationUnitsAtLevels(Mockito.anyList(), Mockito.anyList())).thenReturn(Lists.newArrayList(level2OuA, level2OuB));
    when(organisationUnitService.getOrganisationUnitLevelByLevel(2)).thenReturn(buildOrgUnitLevel(2, "level2UID", "District", null));
    rb.addOuFilter("LEVEL-wjP19dkFeIk;ImspTQPwCqd");
    rb.addDimension(concatenateUuid(DATA_ELEMENT_1, DATA_ELEMENT_2, DATA_ELEMENT_3));
    rb.addPeDimension(PERIOD_DIMENSION);
    DataQueryRequest request = DataQueryRequest.newBuilder().filter(rb.getFilterParams()).dimension(rb.getDimensionParams()).build();
    DataQueryParams params = target.getFromRequest(request);
    DimensionalObject filter = params.getFilters().get(0);
    DimensionItemKeywords keywords = filter.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword("level2UID"));
    assertEquals("District", keywords.getKeyword("level2UID").getMetadataItem().getName());
    assertNull(keywords.getKeyword("level2UID").getMetadataItem().getCode());
    assertNotNull(keywords.getKeyword(rootOu.getUid()));
    assertEquals("Sierra Leone", keywords.getKeyword(rootOu.getUid()).getMetadataItem().getName());
    assertEquals(rootOu.getCode(), keywords.getKeyword(rootOu.getUid()).getMetadataItem().getCode());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test)

Example 30 with DataQueryRequest

use of org.hisp.dhis.common.DataQueryRequest in project dhis2-core by dhis2.

the class DataQueryServiceTest method testGetFromUrlOrgUnitGroup.

@Test
void testGetFromUrlOrgUnitGroup() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("ou:OU_GROUP-" + ouGroupA.getUid());
    dimensionParams.add("dx:" + deA.getDimensionItem() + ";" + deB.getDimensionItem());
    dimensionParams.add("pe:2011;2012");
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).build();
    DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
    assertEquals(3, params.getOrganisationUnits().size());
    assertEquals(2, params.getDataElements().size());
    assertEquals(2, params.getPeriods().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DataQueryRequest (org.hisp.dhis.common.DataQueryRequest)35 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)29 Test (org.junit.jupiter.api.Test)29 HashSet (java.util.HashSet)19 LinkedHashSet (java.util.LinkedHashSet)18 DhisSpringTest (org.hisp.dhis.DhisSpringTest)18 DimensionalObject (org.hisp.dhis.common.DimensionalObject)11 DimensionItemKeywords (org.hisp.dhis.common.DimensionItemKeywords)9 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 DataElement (org.hisp.dhis.dataelement.DataElement)3 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 Grid (org.hisp.dhis.common.Grid)2 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)2 Indicator (org.hisp.dhis.indicator.Indicator)2 IndicatorGroup (org.hisp.dhis.indicator.IndicatorGroup)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 LineString (org.geojson.LineString)1 MultiLineString (org.geojson.MultiLineString)1 Attribute (org.hisp.dhis.attribute.Attribute)1