use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class EventQueryParamsTest method testReplacePeriodsWithStartEndDates.
@Test
public void testReplacePeriodsWithStartEndDates() {
List<DimensionalItemObject> periods = new ArrayList<>();
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 5, 1, 0, 0).toDate()));
periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 6, 1, 0, 0).toDate()));
EventQueryParams params = new EventQueryParams.Builder().addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, periods)).build();
assertNull(params.getStartDate());
assertNull(params.getEndDate());
params = new EventQueryParams.Builder(params).withStartEndDatesForPeriods().build();
assertEquals(new DateTime(2014, 4, 1, 0, 0).toDate(), params.getStartDate());
assertEquals(new DateTime(2014, 6, 30, 0, 0).toDate(), params.getEndDate());
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class QueryPlannerTest method validateFailureOptionCombosWithIndicators.
@Test(expected = IllegalQueryException.class)
public 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();
queryPlanner.validate(params);
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class QueryPlannerTest method validateSuccesB.
@Test
public void validateSuccesB() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, deB, pdeA, pdeB))).addFilter(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);
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class QueryPlannerTest method validateFailureValueType.
@Test(expected = IllegalQueryException.class)
public void validateFailureValueType() {
deB.setValueType(ValueType.FILE_RESOURCE);
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);
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class DefaultAnalyticsService method getOrgUnitTargetMap.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Generates a mapping of permutations keys (organisation unit id or null)
* and mappings of organisation unit group and counts.
*
* @param params the {@link DataQueryParams}.
* @param indicators the indicators for which formulas to scan for organisation
* unit groups.
* @return a map of maps.
*/
private Map<String, Map<String, Integer>> getOrgUnitTargetMap(DataQueryParams params, Collection<Indicator> indicators) {
Set<OrganisationUnitGroup> orgUnitGroups = expressionService.getOrganisationUnitGroupsInIndicators(indicators);
if (orgUnitGroups.isEmpty()) {
return null;
}
DataQueryParams orgUnitTargetParams = DataQueryParams.newBuilder(params).pruneToDimensionType(DimensionType.ORGANISATION_UNIT).addDimension(new BaseDimensionalObject(DimensionalObject.ORGUNIT_GROUP_DIM_ID, null, new ArrayList<DimensionalItemObject>(orgUnitGroups))).withSkipPartitioning(true).build();
Map<String, Double> orgUnitCountMap = getAggregatedOrganisationUnitTargetMap(orgUnitTargetParams);
return DataQueryParams.getPermutationOrgUnitGroupCountMap(orgUnitCountMap);
}
Aggregations