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));
}
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));
}
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());
}
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());
}
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());
}
Aggregations