Search in sources :

Example 11 with DataQueryRequest

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

the class DataQueryServiceTest method testGetFromUrlInvalidDimension.

@Test
void testGetFromUrlInvalidDimension() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + BASE_UID + "A;" + BASE_UID + "B;" + BASE_UID + "C;" + BASE_UID + "D");
    dimensionParams.add("yebo:2012,2012S1,2012S2");
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).build();
    assertThrows(IllegalQueryException.class, () -> dataQueryService.getFromRequest(dataQueryRequest));
}
Also used : 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)

Example 12 with DataQueryRequest

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

the class DataQueryServiceTest method testGetFromUrlNoDx.

@Test
void testGetFromUrlNoDx() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx");
    dimensionParams.add("pe:2012,2012S1,2012S2");
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).build();
    assertThrows(IllegalQueryException.class, () -> dataQueryService.getFromRequest(dataQueryRequest));
}
Also used : 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)

Example 13 with DataQueryRequest

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

the class DataQueryServiceTest method testGetFromUrlC.

@Test
void testGetFromUrlC() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getDimensionItem() + ";" + deB.getDimensionItem() + ";" + pdA.getDimensionItem() + ";" + pdB.getDimensionItem());
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getDimensionItem());
    DataQueryRequest dataQueryRequest = DataQueryRequest.newBuilder().dimension(dimensionParams).filter(filterParams).build();
    DataQueryParams params = dataQueryService.getFromRequest(dataQueryRequest);
    assertEquals(2, params.getDataElements().size());
    assertEquals(2, params.getProgramDataElements().size());
    assertEquals(1, params.getFilterOrganisationUnits().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)

Example 14 with DataQueryRequest

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithOrgUnitLevelAndOrgUnitGroupAsFilter.

@Test
void convertAnalyticsRequestWithOrgUnitLevelAndOrgUnitGroupAsFilter() {
    OrganisationUnit level2OuA = new OrganisationUnit("Bo");
    OrganisationUnit level2OuB = new OrganisationUnit("Bombali");
    OrganisationUnit ou1Group = new OrganisationUnit("ou1-group");
    OrganisationUnit ou2Group = new OrganisationUnit("ou2-group");
    OrganisationUnitGroup groupOu = rnd.nextObject(OrganisationUnitGroup.class);
    mockDimensionService();
    when(organisationUnitService.getOrganisationUnitLevelByLevelOrUid("wjP19dkFeIk")).thenReturn(2);
    when(idObjectManager.getObject(OrganisationUnit.class, UID, "ImspTQPwCqd")).thenReturn(rootOu);
    when(idObjectManager.getObject(OrganisationUnitGroup.class, UID, "tDZVQ1WtwpA")).thenReturn(groupOu);
    when(organisationUnitService.getOrganisationUnitsAtLevels(Mockito.anyList(), Mockito.anyList())).thenReturn(Lists.newArrayList(level2OuA, level2OuB));
    when(organisationUnitService.getOrganisationUnitLevelByLevel(2)).thenReturn(buildOrgUnitLevel(2, "level2UID", "District", null));
    when(organisationUnitService.getOrganisationUnits(Lists.newArrayList(groupOu), Lists.newArrayList(rootOu))).thenReturn(Lists.newArrayList(ou1Group, ou2Group));
    rb.addOuFilter("LEVEL-wjP19dkFeIk;OU_GROUP-tDZVQ1WtwpA;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(3, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword("level2UID"));
    assertEquals("District", keywords.getKeyword("level2UID").getMetadataItem().getName());
    assertNull(keywords.getKeyword("level2UID").getMetadataItem().getCode());
    assertNotNull(keywords.getKeyword(groupOu.getUid()));
    assertEquals(groupOu.getName(), keywords.getKeyword(groupOu.getUid()).getMetadataItem().getName());
    assertEquals(groupOu.getCode(), keywords.getKeyword(groupOu.getUid()).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 : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) 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 15 with DataQueryRequest

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

the class DataQueryServiceDimensionItemKeywordTest method convertAnalyticsRequestWithDataElementGroupAndIndicatorGroup.

@Test
void convertAnalyticsRequestWithDataElementGroupAndIndicatorGroup() {
    final String DATA_ELEMENT_GROUP_UID = "oehv9EO3vP7";
    final String INDICATOR_GROUP_UID = "iezv4GO4vD9";
    when(dimensionService.getDataDimensionalItemObject(UID, "cYeuwXTCPkU")).thenReturn(new DataElement());
    DataElementGroup dataElementGroup = new DataElementGroup("dummyDG");
    dataElementGroup.setUid(DATA_ELEMENT_GROUP_UID);
    dataElementGroup.setCode("CODE_10");
    dataElementGroup.setMembers(Sets.newHashSet(new DataElement(), new DataElement()));
    IndicatorGroup indicatorGroup = new IndicatorGroup("dummyIG");
    indicatorGroup.setUid(INDICATOR_GROUP_UID);
    indicatorGroup.setCode("CODE_10");
    indicatorGroup.setMembers(Sets.newHashSet(new Indicator(), new Indicator()));
    when(idObjectManager.getObject(DataElementGroup.class, UID, DATA_ELEMENT_GROUP_UID)).thenReturn(dataElementGroup);
    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("DE_GROUP-" + DATA_ELEMENT_GROUP_UID + ";cYeuwXTCPkU;Jtf34kNZhz;IN_GROUP-" + INDICATOR_GROUP_UID);
    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");
    DimensionItemKeywords keywords = dimension.getDimensionItemKeywords();
    assertEquals(2, keywords.getKeywords().size());
    assertNotNull(keywords.getKeyword(dataElementGroup.getUid()));
    assertEquals("dummyDG", keywords.getKeyword(dataElementGroup.getUid()).getMetadataItem().getName());
    assertEquals("CODE_10", keywords.getKeyword(dataElementGroup.getUid()).getMetadataItem().getCode());
    assertNotNull(keywords.getKeyword(indicatorGroup.getUid()));
    assertEquals("dummyIG", keywords.getKeyword(indicatorGroup.getUid()).getMetadataItem().getName());
    assertEquals("CODE_10", keywords.getKeyword(indicatorGroup.getUid()).getMetadataItem().getCode());
}
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) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) DataQueryRequest(org.hisp.dhis.common.DataQueryRequest) Indicator(org.hisp.dhis.indicator.Indicator) 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