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