Search in sources :

Example 11 with BaseDimensionalObject

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

the class DefaultQueryPlanner method groupByOrgUnitLevel.

@Override
public List<DataQueryParams> groupByOrgUnitLevel(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (!params.getOrganisationUnits().isEmpty()) {
        ListMap<Integer, DimensionalItemObject> levelOrgUnitMap = QueryPlannerUtils.getLevelOrgUnitMap(params.getOrganisationUnits());
        for (Integer level : levelOrgUnitMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).addOrSetDimensionOptions(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, LEVEL_PREFIX + level, levelOrgUnitMap.get(level)).build();
            queries.add(query);
        }
    } else if (!params.getFilterOrganisationUnits().isEmpty()) {
        ListMap<Integer, DimensionalItemObject> levelOrgUnitMap = QueryPlannerUtils.getLevelOrgUnitMap(params.getFilterOrganisationUnits());
        DimensionalObject filter = params.getFilter(ORGUNIT_DIM_ID);
        DataQueryParams.Builder query = DataQueryParams.newBuilder(params).removeFilter(ORGUNIT_DIM_ID);
        for (Integer level : levelOrgUnitMap.keySet()) {
            query.addFilter(new BaseDimensionalObject(filter.getDimension(), filter.getDimensionType(), LEVEL_PREFIX + level, filter.getDisplayName(), levelOrgUnitMap.get(level)));
        }
        queries.add(query.build());
    } else {
        queries.add(DataQueryParams.newBuilder(params).build());
        return queries;
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on org unit level: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) ListMap(org.hisp.dhis.common.ListMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 12 with BaseDimensionalObject

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

the class DataQueryGroupsTest method getQueryA.

@Test
public void getQueryA() {
    DimensionalObject dimA = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB));
    DimensionalObject dimB = new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB, ouC));
    DimensionalObject dimC = new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, getList(createPeriod("2000Q1")));
    DataQueryParams paramsA = DataQueryParams.newBuilder().addDimension(dimA).addDimension(dimB).addFilter(dimC).build();
    assertNotNull(paramsA.getDimension(DimensionalObject.DATA_X_DIM_ID));
    assertNotNull(paramsA.getDimension(DimensionalObject.ORGUNIT_DIM_ID));
    assertNotNull(paramsA.getFilter(DimensionalObject.PERIOD_DIM_ID));
    assertEquals(2, paramsA.getDimension(DimensionalObject.DATA_X_DIM_ID).getItems().size());
    assertEquals(3, paramsA.getDimension(DimensionalObject.ORGUNIT_DIM_ID).getItems().size());
    assertEquals(1, paramsA.getFilter(DimensionalObject.PERIOD_DIM_ID).getItems().size());
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 13 with BaseDimensionalObject

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

the class QueryPlannerTest method validateFailureSingleIndicatorAsFilter.

@Test(expected = IllegalQueryException.class)
public void validateFailureSingleIndicatorAsFilter() {
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addFilter(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, inA))).build();
    queryPlanner.validate(params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 14 with BaseDimensionalObject

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

the class QueryPlannerTest method validateFailureReportingRatesAndDataElementGroupSetAsDimensions.

@Test(expected = IllegalQueryException.class)
public void validateFailureReportingRatesAndDataElementGroupSetAsDimensions() {
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(rrA, inA))).addDimension(new BaseDimensionalObject(dgsA.getDimension(), DimensionType.DATA_ELEMENT_GROUP_SET, getList(deA))).build();
    queryPlanner.validate(params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 15 with BaseDimensionalObject

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

the class QueryPlannerTest method validateFailureAggregationType.

@Test(expected = IllegalQueryException.class)
public void validateFailureAggregationType() {
    deB.setAggregationType(AggregationType.CUSTOM);
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB))).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).build();
    queryPlanner.validate(params);
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)21 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)16 Test (org.junit.Test)13 DhisSpringTest (org.hisp.dhis.DhisSpringTest)11 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)8 DimensionalObject (org.hisp.dhis.common.DimensionalObject)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)2 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)2 Grid (org.hisp.dhis.common.Grid)2 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)2 ListMap (org.hisp.dhis.common.ListMap)2 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)1 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)1 QueryFilter (org.hisp.dhis.common.QueryFilter)1 QueryItem (org.hisp.dhis.common.QueryItem)1