Search in sources :

Example 1 with DataQueryRequest

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithRelativePeriod.

@Test
void convertAnalyticsRequestWithRelativePeriod() {
    mockDimensionService();
    when(i18n.getString("LAST_12_MONTHS")).thenReturn("Last 12 months");
    when(i18n.getString("LAST_YEAR")).thenReturn("Last year");
    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 dimension = params.getDimension(PERIOD_DIM_ID);
    DimensionItemKeywords keywords = dimension.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword("LAST_12_MONTHS"));
    assertEquals("Last 12 months", keywords.getKeyword("LAST_12_MONTHS").getMetadataItem().getName());
    assertNotNull(keywords.getKeyword("LAST_YEAR"));
    assertEquals("Last year", keywords.getKeyword("LAST_YEAR").getMetadataItem().getName());
}
Also used : 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 2 with DataQueryRequest

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithMultipleOuLevelToDataQueryParam.

@Test
void convertAnalyticsRequestWithMultipleOuLevelToDataQueryParam() {
    mockDimensionService();
    when(organisationUnitService.getOrganisationUnitLevelByLevel(2)).thenReturn(buildOrgUnitLevel(2, "level2UID", "District", null));
    when(organisationUnitService.getOrganisationUnitLevelByLevel(3)).thenReturn(buildOrgUnitLevel(3, "level3UID", "Chiefdom", null));
    when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("3")).thenReturn(3);
    when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("2")).thenReturn(2);
    when(organisationUnitService.getOrganisationUnitsAtLevels(Mockito.anyList(), Mockito.anyList())).thenReturn(Lists.newArrayList(new OrganisationUnit(), new OrganisationUnit()));
    rb.addOuFilter("LEVEL-2;LEVEL-3;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("level3UID"));
    assertEquals("Chiefdom", keywords.getKeyword("level3UID").getMetadataItem().getName());
    assertNull(keywords.getKeyword("level3UID").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 3 with DataQueryRequest

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithOrgUnitGroup.

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

Example 4 with DataQueryRequest

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithDataElementGroup.

@Test
void convertAnalyticsRequestWithDataElementGroup() {
    when(dimensionService.getDataDimensionalItemObject(UID, DATA_ELEMENT_2.getUid())).thenReturn(DATA_ELEMENT_2);
    final String DATA_ELEMENT_GROUP_UID = "oehv9EO3vP7";
    when(dimensionService.getDataDimensionalItemObject(UID, "cYeuwXTCPkU")).thenReturn(new DataElement());
    DataElementGroup dataElementGroup = new DataElementGroup("dummy");
    dataElementGroup.setUid(DATA_ELEMENT_GROUP_UID);
    dataElementGroup.setCode("CODE_10");
    dataElementGroup.setMembers(Sets.newHashSet(new DataElement(), new DataElement()));
    when(idObjectManager.getObject(DataElementGroup.class, UID, DATA_ELEMENT_GROUP_UID)).thenReturn(dataElementGroup);
    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("DE_GROUP-" + DATA_ELEMENT_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(dataElementGroup.getUid()));
    assertThat(aggregation.getMetadataItem().getCode(), is(dataElementGroup.getCode()));
    assertThat(aggregation.getMetadataItem().getName(), is(dataElementGroup.getName()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test)

Example 5 with DataQueryRequest

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithRelativePeriodAsFilter.

@Test
void convertAnalyticsRequestWithRelativePeriodAsFilter() {
    mockDimensionService();
    when(i18n.getString("LAST_12_MONTHS")).thenReturn("Last 12 months");
    when(i18n.getString("LAST_YEAR")).thenReturn("Last year");
    rb.addDimension(concatenateUuid(DATA_ELEMENT_1, DATA_ELEMENT_2, DATA_ELEMENT_3));
    rb.addPeDimension(PERIOD_DIMENSION);
    rb.addFilter("pe", "QUARTERS_THIS_YEAR");
    DataQueryRequest request = DataQueryRequest.newBuilder().filter(rb.getFilterParams()).dimension(rb.getDimensionParams()).build();
    DataQueryParams params = target.getFromRequest(request);
    DimensionalObject dimension = params.getDimension(PERIOD_DIM_ID);
    DimensionItemKeywords keywords = dimension.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword("LAST_12_MONTHS"));
    assertEquals("Last 12 months", keywords.getKeyword("LAST_12_MONTHS").getMetadataItem().getName());
    assertNotNull(keywords.getKeyword("LAST_YEAR"));
    assertEquals("Last year", keywords.getKeyword("LAST_YEAR").getMetadataItem().getName());
}
Also used : 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)

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