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