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