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