Search in sources :

Example 6 with Visualization

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);
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) ListGrid(org.hisp.dhis.system.grid.ListGrid) AnalyticsUtils.getDataValueSetFromGrid(org.hisp.dhis.analytics.util.AnalyticsUtils.getDataValueSetFromGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 7 with Visualization

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));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with Visualization

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());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with Visualization

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));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 10 with Visualization

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());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

Visualization (org.hisp.dhis.visualization.Visualization)48 Test (org.junit.jupiter.api.Test)36 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)26 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)14 User (org.hisp.dhis.user.User)13 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)7 DataElement (org.hisp.dhis.dataelement.DataElement)6 List (java.util.List)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 Period (org.hisp.dhis.period.Period)4 Date (java.util.Date)3 Dashboard (org.hisp.dhis.dashboard.Dashboard)3 DataSet (org.hisp.dhis.dataset.DataSet)3 ErrorReport (org.hisp.dhis.feedback.ErrorReport)3 UserAccess (org.hisp.dhis.user.sharing.UserAccess)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ArrayList (java.util.ArrayList)2