use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByStartEndDateRestriction.
@Override
public List<DataQueryParams> groupByStartEndDateRestriction(DataQueryParams params) {
List<DataQueryParams> queries = new ArrayList<>();
if (!params.getPeriods().isEmpty()) {
for (DimensionalItemObject item : params.getPeriods()) {
Period period = (Period) item;
DataQueryParams query = DataQueryParams.newBuilder(params).withStartDateRestriction(period.getStartDate()).withEndDateRestriction(period.getEndDate()).build();
BaseDimensionalObject staticPeriod = (BaseDimensionalObject) query.getDimension(PERIOD_DIM_ID);
staticPeriod.setDimensionName(period.getIsoDate());
staticPeriod.setFixed(true);
queries.add(query);
}
} else if (!params.getFilterPeriods().isEmpty()) {
Period period = (Period) params.getFilterPeriods().get(0);
DataQueryParams query = DataQueryParams.newBuilder(params).withStartDateRestriction(period.getStartDate()).withEndDateRestriction(period.getEndDate()).removeFilter(PERIOD_DIM_ID).build();
queries.add(query);
} else {
throwIllegalQueryEx(ErrorCode.E7104);
}
logQuerySplit(queries, "period start and end date");
return queries;
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class DimensionServiceTest method testMergeAnalyticalObjectRelativePeriods.
@Test
void testMergeAnalyticalObjectRelativePeriods() {
Visualization visualization = new Visualization();
visualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
visualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA, ouB, ouC, ouD, ouE)));
visualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peLast12Months)));
dimensionService.mergeAnalyticalObject(visualization);
assertEquals(2, visualization.getDataDimensionItems().size());
assertEquals(0, visualization.getPeriods().size());
assertTrue(visualization.getRelatives().isLast12Months());
assertEquals(5, visualization.getOrganisationUnits().size());
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class DimensionServiceTest method testMergeAnalyticalEventObjectDataElementGroupSet.
@Test
void testMergeAnalyticalEventObjectDataElementGroupSet() {
// Given
EventVisualization eventVisualization = new EventVisualization("any");
eventVisualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
eventVisualization.getRows().add(deGroupSetA);
eventVisualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB)));
// When
dimensionService.mergeAnalyticalObject(eventVisualization);
// Then
assertEquals(2, eventVisualization.getDataDimensionItems().size());
assertEquals(2, eventVisualization.getPeriods().size());
assertEquals(1, eventVisualization.getDataElementGroupSetDimensions().size());
assertEquals(3, eventVisualization.getDataElementGroupSetDimensions().get(0).getItems().size());
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class DimensionServiceTest method testMergeAnalyticalEventObjectUserOrgUnit.
@Test
void testMergeAnalyticalEventObjectUserOrgUnit() {
// Given
EventVisualization eventVisualization = new EventVisualization("any");
eventVisualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
eventVisualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouUser)));
eventVisualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA)));
// When
dimensionService.mergeAnalyticalObject(eventVisualization);
// Then
assertEquals(2, eventVisualization.getDataDimensionItems().size());
assertEquals(1, eventVisualization.getPeriods().size());
assertEquals(0, eventVisualization.getOrganisationUnits().size());
assertTrue(eventVisualization.isUserOrganisationUnit());
}
use of org.hisp.dhis.common.BaseDimensionalObject in project dhis2-core by dhis2.
the class DimensionServiceTest method testMergeAnalyticalObjectOrgUnitLevel.
@Test
void testMergeAnalyticalObjectOrgUnitLevel() {
Visualization visualization = new Visualization();
visualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
visualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouLevel2, ouA)));
visualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA)));
dimensionService.mergeAnalyticalObject(visualization);
assertEquals(2, visualization.getDataDimensionItems().size());
assertEquals(1, visualization.getPeriods().size());
assertEquals(1, visualization.getOrganisationUnits().size());
assertEquals(Integer.valueOf(2), visualization.getOrganisationUnitLevels().get(0));
}
Aggregations