Search in sources :

Example 91 with BaseDimensionalObject

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

the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementIsAggregatedWithTwoQueryGroupWhenDataTypeIsDifferent.

@Test
void verifyMultipleDataElementIsAggregatedWithTwoQueryGroupWhenDataTypeIsDifferent() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    // DataQueryParams with **two** DataElement with different data type as
    // dimension
    DataQueryParams queryParams = DataQueryParams.newBuilder().withDimensions(// PERIOD DIMENSION
    Lists.newArrayList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods), new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.TEXT, AggregationType.COUNT, DataElementDomain.AGGREGATE))))).withFilters(Lists.newArrayList(// OU FILTER
    new BaseDimensionalObject("ou", DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, ImmutableList.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))))).withAggregationType(AnalyticsAggregationType.AVERAGE).build();
    DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
    assertThat(dataQueryGroups.getAllQueries(), hasSize(2));
    assertThat(dataQueryGroups.getAllQueries(), hasItem(both(hasProperty("aggregationType", hasProperty("aggregationType", is(AggregationType.AVERAGE)))).and(hasProperty("aggregationType", hasProperty("dataType", is(DataType.NUMERIC))))));
    assertThat(dataQueryGroups.getAllQueries(), hasItem(both(hasProperty("aggregationType", hasProperty("aggregationType", is(AggregationType.AVERAGE)))).and(hasProperty("aggregationType", hasProperty("dataType", is(DataType.TEXT))))));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 92 with BaseDimensionalObject

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

the class QueryPlannerGroupByAggregationTypeTest method createDataQueryParams.

private DataQueryParams createDataQueryParams(BaseDimensionalObject filterDataElements) {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    return DataQueryParams.newBuilder().withDimensions(// PERIOD DIMENSION
    Lists.newArrayList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods))).withFilters(Lists.newArrayList(// OU FILTER
    new BaseDimensionalObject("ou", DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, ImmutableList.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))), // DATA ELEMENT AS FILTER
    filterDataElements)).build();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime)

Example 93 with BaseDimensionalObject

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

the class QueryPlannerGroupByAggregationTypeTest method verifySingleNonDataElementRetainAggregationTypeButNullDataType.

@Test
void verifySingleNonDataElementRetainAggregationTypeButNullDataType() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    // DataQueryParams with **one** Indicator
    DataQueryParams queryParams = DataQueryParams.newBuilder().withDimensions(// PERIOD DIMENSION
    Lists.newArrayList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods), new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createIndicator('A', createIndicatorType('A')))))).withFilters(Lists.newArrayList(// OU FILTER
    new BaseDimensionalObject("ou", DimensionType.ORGANISATION_UNIT, null, DISPLAY_NAME_ORGUNIT, ImmutableList.of(new OrganisationUnit("bbb", "bbb", "OU_2", null, null, "c2"))))).withAggregationType(AnalyticsAggregationType.AVERAGE).build();
    DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
    assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
    assertThat(dataQueryGroups.getAllQueries(), hasItem(both(hasProperty("aggregationType", hasProperty("aggregationType", is(AggregationType.AVERAGE)))).and(hasProperty("aggregationType", hasProperty("dataType", is(nullValue()))))));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 94 with BaseDimensionalObject

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

the class QueryValidatorTest method validateErrorSingleIndicatorAsFilter.

@Test
void validateErrorSingleIndicatorAsFilter() {
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).addFilter(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, inA))).build();
    ErrorMessage error = queryValidator.validateForErrorMessage(params);
    assertEquals(ErrorCode.E7108, error.getErrorCode());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) Test(org.junit.jupiter.api.Test)

Example 95 with BaseDimensionalObject

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

the class QueryValidatorTest method validateFailureOptionCombosWithIndicators.

@Test
void validateFailureOptionCombosWithIndicators() {
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, inA))).addDimension(new BaseDimensionalObject(CATEGORYOPTIONCOMBO_DIM_ID, DimensionType.DATA_X, getList())).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).build();
    assertValidatonError(ErrorCode.E7114, params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test)

Aggregations

BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)108 Test (org.junit.jupiter.api.Test)77 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)69 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)31 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DimensionalObject (org.hisp.dhis.common.DimensionalObject)22 ArrayList (java.util.ArrayList)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)18 Grid (org.hisp.dhis.common.Grid)17 HashMap (java.util.HashMap)14 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)14 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 CategoryCombo (org.hisp.dhis.category.CategoryCombo)11 DataElement (org.hisp.dhis.dataelement.DataElement)11 Test (org.junit.Test)11 Map (java.util.Map)9 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)9 Period (org.hisp.dhis.period.Period)9 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)8 QueryItem (org.hisp.dhis.common.QueryItem)8