use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.
the class DefaultAnalyticsService method getAggregatedDataValuesTableLayout.
/**
* Returns a Grid with aggregated data in table layout.
*
* @param params the {@link DataQueryParams}.
* @param columns the column dimensions.
* @param rows the row dimensions.
* @return a Grid with aggregated data in table layout.
*/
private Grid getAggregatedDataValuesTableLayout(DataQueryParams params, List<String> columns, List<String> rows) {
params.setOutputIdScheme(null);
Grid grid = getAggregatedDataValues(params);
removeEmptys(columns);
removeEmptys(rows);
queryValidator.validateTableLayout(params, columns, rows);
queryValidator.validate(params);
final Visualization visualization = new Visualization();
List<List<DimensionalItemObject>> tableColumns = new ArrayList<>();
List<List<DimensionalItemObject>> tableRows = new ArrayList<>();
if (columns != null) {
for (String dimension : columns) {
visualization.addDimensionDescriptor(dimension, params.getDimension(dimension).getDimensionType());
visualization.getColumnDimensions().add(dimension);
tableColumns.add(params.getDimensionItemsExplodeCoc(dimension));
}
}
if (rows != null) {
for (String dimension : rows) {
visualization.addDimensionDescriptor(dimension, params.getDimension(dimension).getDimensionType());
visualization.getRowDimensions().add(dimension);
tableRows.add(params.getDimensionItemsExplodeCoc(dimension));
}
}
visualization.setGridTitle(IdentifiableObjectUtils.join(params.getFilterItems())).setGridColumns(CombinationGenerator.newInstance(tableColumns).getCombinations()).setGridRows(CombinationGenerator.newInstance(tableRows).getCombinations());
addListIfEmpty(visualization.getGridColumns());
addListIfEmpty(visualization.getGridRows());
visualization.setHideEmptyRows(params.isHideEmptyRows());
visualization.setHideEmptyColumns(params.isHideEmptyColumns());
visualization.setShowHierarchy(params.isShowHierarchy());
Map<String, Object> valueMap = AnalyticsUtils.getAggregatedDataValueMapping(grid);
return visualization.getGrid(new ListGrid(grid.getMetaData(), grid.getInternalMetaData()), valueMap, params.getDisplayProperty(), false);
}
use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.
the class AnalyticalObjectOrgUnitMergeHandlerTest method testMergeVisualizations.
@Test
void testMergeVisualizations() {
Visualization vA = createVisualization('A');
vA.addDataDimensionItem(deA);
vA.getOrganisationUnits().add(ouA);
vA.getOrganisationUnits().add(ouB);
Visualization vB = createVisualization('B');
vB.addDataDimensionItem(deA);
vB.getOrganisationUnits().add(ouA);
vB.getOrganisationUnits().add(ouB);
idObjectManager.save(vA);
idObjectManager.save(vB);
assertEquals(2, getVisualizationCount(ouA));
assertEquals(2, getVisualizationCount(ouB));
assertEquals(0, getVisualizationCount(ouC));
OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
handler.mergeAnalyticalObjects(request);
idObjectManager.update(ouC);
assertEquals(0, getVisualizationCount(ouA));
assertEquals(0, getVisualizationCount(ouB));
assertEquals(2, getVisualizationCount(ouC));
}
use of org.hisp.dhis.visualization.Visualization 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.visualization.Visualization 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));
}
use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.
the class DimensionServiceTest method testMergeAnalyticalObjectOrgUnitGroupSet.
@Test
void testMergeAnalyticalObjectOrgUnitGroupSet() {
Visualization visualization = new Visualization();
visualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
visualization.getRows().add(ouGroupSetA);
visualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB)));
dimensionService.mergeAnalyticalObject(visualization);
assertEquals(2, visualization.getDataDimensionItems().size());
assertEquals(2, visualization.getPeriods().size());
assertEquals(1, visualization.getOrganisationUnitGroupSetDimensions().size());
assertEquals(3, visualization.getOrganisationUnitGroupSetDimensions().get(0).getItems().size());
}
Aggregations