use of org.hisp.dhis.common.DimensionItemKeywords 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.DimensionItemKeywords in project dhis2-core by dhis2.
the class DataQueryServiceDimensionItemKeywordTest method assertOrgUnitGroup.
private void assertOrgUnitGroup(String ouGroupUID, DimensionalObject dimension) {
DimensionItemKeywords keywords = dimension.getDimensionItemKeywords();
assertEquals(2, keywords.getKeywords().size());
assertNotNull(keywords.getKeyword(ouGroupUID));
assertEquals("Chiefdom", keywords.getKeyword(ouGroupUID).getMetadataItem().getName());
assertEquals("CODE_001", keywords.getKeyword(ouGroupUID).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.DimensionItemKeywords 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.DimensionItemKeywords 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());
}
use of org.hisp.dhis.common.DimensionItemKeywords in project dhis2-core by dhis2.
the class AnalyticsServiceMetadataTest method metadataContainsOuLevelData.
@SuppressWarnings("unchecked")
@Test
void metadataContainsOuLevelData() {
DataQueryParams params = DataQueryParams.newBuilder().withPeriod(new Period(YearlyPeriodType.getPeriodFromIsoString("2017W10"))).withDataElements(newArrayList(createDataElement('A', new CategoryCombo()))).withIgnoreLimit(true).withFilters(Collections.singletonList(new BaseDimensionalObject("ou", DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, ImmutableList.of(new OrganisationUnit("aaa", "aaa", "OU_1", null, null, "c1"), new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2")), new DimensionItemKeywords(Lists.newArrayList(buildOrgUnitLevel(2, "wjP19dkFeIk", "District", null), buildOrgUnitLevel(1, "tTUf91fCytl", "Chiefdom", "OU_12345")))))).build();
initMock(params);
Grid grid = target.getAggregatedDataValueGrid(params);
Map<String, Object> items = (Map<String, Object>) grid.getMetaData().get("items");
assertThat(items.get("wjP19dkFeIk"), allOf(hasProperty("name", is("District")), hasProperty("uid", is("wjP19dkFeIk")), hasProperty("code", is(nullValue()))));
assertThat(items.get("tTUf91fCytl"), allOf(hasProperty("name", is("Chiefdom")), hasProperty("uid", is("tTUf91fCytl")), hasProperty("code", is("OU_12345"))));
}
Aggregations