Search in sources :

Example 56 with BaseDimensionalObject

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

the class EventQueryParamsTest method testGetKey.

@Test
void testGetKey() {
    QueryItem qiA = new QueryItem(deA, null, deA.getValueType(), deA.getAggregationType(), osA);
    QueryItem qiB = new QueryItem(deB, null, deB.getValueType(), deB.getAggregationType(), osB);
    EventQueryParams paramsA = new EventQueryParams.Builder().addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB, peC))).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA, ouB))).addItem(qiA).addItem(qiB).build();
    EventQueryParams paramsB = new EventQueryParams.Builder().addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB))).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA))).addItem(qiA).addItem(qiB).withGeometryOnly(true).build();
    assertNotNull(paramsA.getKey());
    assertEquals(40, paramsA.getKey().length());
    assertNotNull(paramsB.getKey());
    assertEquals(40, paramsB.getKey().length());
    assertNotEquals(paramsA.getKey(), paramsB.getKey());
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 57 with BaseDimensionalObject

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

the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentDataTypeDoNotRetainAggregationType.

@Test
void verifyMultipleDataElementAsFilterHavingDifferentDataTypeDoNotRetainAggregationType() {
    // DataQueryParams with **two** DataElement as filter
    // One Data Element has Type Numeric
    // Aggregation type is overridden (COUNT)
    DataQueryParams queryParams = createDataQueryParamsWithAggregationType(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.TEXT, AggregationType.COUNT))), AnalyticsAggregationType.COUNT);
    DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
    assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
    DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
    // Aggregation type defaults to SUM
    assertDefaultAggregationType(dataQueryParam);
    assertThat(dataQueryParam.getAggregationType().getDataType(), is(nullValue()));
    assertThat(dataQueryParam.getPeriods(), hasSize(1));
    assertThat(dataQueryParam.getFilterDataElements(), hasSize(2));
    assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Test(org.junit.jupiter.api.Test)

Example 58 with BaseDimensionalObject

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

the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterRetainAggregationTypeAndAggregationDataType.

@Test
void verifyMultipleDataElementAsFilterRetainAggregationTypeAndAggregationDataType() {
    // DataQueryParams with **two** DataElement as filter
    // Both have DataType NUMERIC and AggregationType SUM
    DataQueryParams queryParams = createDataQueryParams(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', new CategoryCombo()))));
    DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
    assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
    DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
    assertTrue(dataQueryParam.getAggregationType().isAggregationType(AggregationType.SUM));
    assertThat(dataQueryParam.getAggregationType().getDataType(), is(DataType.NUMERIC));
    assertThat(dataQueryParam.getPeriods(), hasSize(1));
    assertThat(dataQueryParam.getFilterDataElements(), hasSize(2));
    assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Test(org.junit.jupiter.api.Test)

Example 59 with BaseDimensionalObject

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

the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentAggTypeDoNotRetainAggregationType.

@Test
void verifyMultipleDataElementAsFilterHavingDifferentAggTypeDoNotRetainAggregationType() {
    // DataQueryParams with **two** DataElement as filter
    // Both have DataType NUMERIC but different AggregationType
    DataQueryParams queryParams = createDataQueryParams(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.INTEGER, AggregationType.COUNT))));
    DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
    assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
    DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
    // Aggregation type defaults to SUM
    assertDefaultAggregationType(dataQueryParam);
    assertThat(dataQueryParam.getAggregationType().getDataType(), is(nullValue()));
    assertThat(dataQueryParam.getPeriods(), hasSize(1));
    assertThat(dataQueryParam.getFilterDataElements(), hasSize(2));
    assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Test(org.junit.jupiter.api.Test)

Example 60 with BaseDimensionalObject

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

the class AbstractJdbcEventAnalyticsManagerTest method verifyGetColumnsWithAttributeOrgUnitTypeAndCoordinatesReturnsFetchesCoordinatesFromOrgUnite.

@Test
void verifyGetColumnsWithAttributeOrgUnitTypeAndCoordinatesReturnsFetchesCoordinatesFromOrgUnite() {
    // Given
    DataElement deA = createDataElement('A', ValueType.ORGANISATION_UNIT, AggregationType.NONE);
    DimensionalObject periods = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, newArrayList(MonthlyPeriodType.getPeriodFromIsoString("201701")));
    DimensionalObject orgUnits = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, "ouA", newArrayList(createOrganisationUnit('A')));
    QueryItem qiA = new QueryItem(deA, null, deA.getValueType(), deA.getAggregationType(), null);
    // When
    EventQueryParams params = new EventQueryParams.Builder().addDimension(periods).addDimension(orgUnits).addItem(qiA).withCoordinateField(deA.getUid()).withSkipData(true).withSkipMeta(false).build();
    final List<String> columns = this.subject.getSelectColumns(params);
    // Then
    assertThat(columns, hasSize(3));
    assertThat(columns, containsInAnyOrder("ax.\"pe\"", "ax.\"ou\"", "'[' || round(ST_X(ST_Centroid(\"" + deA.getUid() + "_geom" + "\"))::numeric, 6) || ',' || round(ST_Y(ST_Centroid(\"" + deA.getUid() + "_geom" + "\"))::numeric, 6) || ']' as \"" + deA.getUid() + "_geom" + "\""));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) QueryItem(org.hisp.dhis.common.QueryItem) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) 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