Search in sources :

Example 46 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetDataValueSetFromGrid.

@Test
void testGetDataValueSetFromGrid() {
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, false, false));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peA", "coA", "aoA", 1d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouA", "peB", null, null, 2d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouB", "peA", null, null, 3d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxA", "ouB", "peB", null, null, 4d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peA", "coA", null, 5d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxB", "ouA", "peB", "coA", "aoB", 6d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peA", null, "aoA", 7));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxC", "ouA", "peB", null, null, 8d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxD", "ouA", "peA", "coB", null, 9d));
    grid.addRow().addValuesAsList(Lists.newArrayList("dxE", "ouA", "peB", null, null, 10));
    DataValueSet dvs = AnalyticsUtils.getDataValueSetFromGrid(DataQueryParams.newBuilder().build(), grid);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataValues());
    assertEquals(10, dvs.getDataValues().size());
    assertEquals("dxA", dvs.getDataValues().get(1).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(1).getOrgUnit());
    assertEquals("peB", dvs.getDataValues().get(1).getPeriod());
    assertNull(dvs.getDataValues().get(1).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(1).getAttributeOptionCombo());
    assertEquals("2.0", dvs.getDataValues().get(1).getValue());
    assertEquals("dxB", dvs.getDataValues().get(4).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(4).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(4).getPeriod());
    assertEquals("coA", dvs.getDataValues().get(4).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(4).getAttributeOptionCombo());
    assertEquals("5.0", dvs.getDataValues().get(4).getValue());
    assertEquals("dxC", dvs.getDataValues().get(6).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(6).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(6).getPeriod());
    assertNull(dvs.getDataValues().get(6).getCategoryOptionCombo());
    assertEquals("aoA", dvs.getDataValues().get(6).getAttributeOptionCombo());
    assertEquals("7", dvs.getDataValues().get(6).getValue());
    assertEquals("dxD", dvs.getDataValues().get(8).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(8).getOrgUnit());
    assertEquals("peA", dvs.getDataValues().get(8).getPeriod());
    assertEquals("coB", dvs.getDataValues().get(8).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(8).getAttributeOptionCombo());
    assertEquals("9.0", dvs.getDataValues().get(8).getValue());
    assertEquals("dxE", dvs.getDataValues().get(9).getDataElement());
    assertEquals("ouA", dvs.getDataValues().get(9).getOrgUnit());
    assertEquals("peB", dvs.getDataValues().get(9).getPeriod());
    assertNull(dvs.getDataValues().get(9).getCategoryOptionCombo());
    assertNull(dvs.getDataValues().get(9).getAttributeOptionCombo());
    assertEquals("10", dvs.getDataValues().get(9).getValue());
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 47 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testGetDataValueSetFromGridEmpty.

@Test
void testGetDataValueSetFromGridEmpty() {
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.CATEGORYOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, false, false));
    DataValueSet dvs = AnalyticsUtils.getDataValueSetFromGrid(DataQueryParams.newBuilder().build(), grid);
    assertNotNull(dvs);
    assertNotNull(dvs.getDataValues());
    assertEquals(0, dvs.getDataValues().size());
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 48 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultSqlViewService method getSqlViewGrid.

@Override
public Grid getSqlViewGrid(SqlView sqlView, Map<String, String> criteria, Map<String, String> variables, List<String> filters, List<String> fields) {
    canAccess(sqlView);
    validateSqlView(sqlView, criteria, variables);
    Grid grid = new ListGrid();
    grid.setTitle(sqlView.getName());
    grid.setSubtitle(sqlView.getDescription());
    log.info(String.format("Retrieving data for SQL view: '%s'", sqlView.getUid()));
    String sql = sqlView.isQuery() ? getSqlForQuery(sqlView, criteria, variables, filters, fields) : getSqlForView(sqlView, criteria, filters, fields);
    sqlViewStore.populateSqlViewGrid(grid, sql);
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid)

Example 49 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultEventAnalyticsService method getEventClusters.

@Override
public Grid getEventClusters(EventQueryParams params) {
    if (!databaseInfo.isSpatialSupport()) {
        throwIllegalQueryEx(ErrorCode.E7218);
    }
    params = new EventQueryParams.Builder(params).withGeometryOnly(true).withStartEndDatesForPeriods().build();
    securityManager.decideAccessEventQuery(params);
    queryValidator.validate(params);
    Grid grid = new ListGrid();
    // ---------------------------------------------------------------------
    // Headers
    // ---------------------------------------------------------------------
    grid.addHeader(new GridHeader(ITEM_COUNT, NAME_COUNT, NUMBER, false, false)).addHeader(new GridHeader(ITEM_CENTER, NAME_CENTER, TEXT, false, false)).addHeader(new GridHeader(ITEM_EXTENT, NAME_EXTENT, TEXT, false, false)).addHeader(new GridHeader(ITEM_POINTS, NAME_POINTS, TEXT, false, false));
    // ---------------------------------------------------------------------
    // Data
    // ---------------------------------------------------------------------
    params = queryPlanner.planEventQuery(params);
    eventAnalyticsManager.getEventClusters(params, grid, queryValidator.getMaxLimit());
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 50 with ListGrid

use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.

the class DefaultEventAnalyticsService method generateOutputGrid.

/**
 * Generates an output grid for event analytics download based on input
 * parameters.
 *
 * @param grid the result grid.
 * @param params the {@link EventQueryParams}.
 * @param rowPermutations the row permutations
 * @param columnPermutations the column permutations.
 * @param rowDimensions the row dimensions.
 * @return grid with table layout.
 */
@SuppressWarnings("unchecked")
private Grid generateOutputGrid(Grid grid, EventQueryParams params, List<Map<String, EventAnalyticsDimensionalItem>> rowPermutations, List<Map<String, EventAnalyticsDimensionalItem>> columnPermutations, List<String> rowDimensions) {
    Grid outputGrid = new ListGrid();
    outputGrid.setTitle(IdentifiableObjectUtils.join(params.getFilterItems()));
    for (String row : rowDimensions) {
        MetadataItem metadataItem = (MetadataItem) ((Map<String, Object>) grid.getMetaData().get(ITEMS.getKey())).get(row);
        String name = StringUtils.defaultIfEmpty(metadataItem.getName(), row);
        String col = StringUtils.defaultIfEmpty(COLUMN_NAMES.get(row), row);
        outputGrid.addHeader(new GridHeader(name, col, ValueType.TEXT, false, true));
    }
    columnPermutations.forEach(permutation -> {
        StringBuilder builder = new StringBuilder();
        permutation.forEach((key, value) -> {
            if (!key.equals(ORGUNIT_DIM_ID) && !key.equals(PERIOD_DIM_ID)) {
                builder.append(key).append(SPACE);
            }
            builder.append(value.getDisplayProperty(params.getDisplayProperty())).append(DASH_PRETTY_SEPARATOR);
        });
        String display = builder.length() > 0 ? builder.substring(0, builder.lastIndexOf(DASH_PRETTY_SEPARATOR)) : TOTAL_COLUMN_PRETTY_NAME;
        outputGrid.addHeader(new GridHeader(display, display, ValueType.NUMBER, false, false));
    });
    for (Map<String, EventAnalyticsDimensionalItem> rowCombination : rowPermutations) {
        outputGrid.addRow();
        List<List<String>> ids = new ArrayList<>();
        Map<String, EventAnalyticsDimensionalItem> displayObjects = new HashMap<>();
        boolean fillDisplayList = true;
        for (Map<String, EventAnalyticsDimensionalItem> columnCombination : columnPermutations) {
            List<String> idList = new ArrayList<>();
            boolean finalFillDisplayList = fillDisplayList;
            rowCombination.forEach((key, value) -> {
                idList.add(value.toString());
                if (finalFillDisplayList) {
                    displayObjects.put(value.getParentUid(), value);
                }
            });
            columnCombination.forEach((key, value) -> idList.add(value.toString()));
            ids.add(idList);
            fillDisplayList = false;
        }
        rowDimensions.forEach(dimension -> outputGrid.addValue(displayObjects.get(dimension).getDisplayProperty(params.getDisplayProperty())));
        EventAnalyticsUtils.addValues(ids, grid, outputGrid);
    }
    return outputGrid;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) EventAnalyticsDimensionalItem(org.hisp.dhis.analytics.EventAnalyticsDimensionalItem) EventAnalyticalObject(org.hisp.dhis.common.EventAnalyticalObject) ValueTypedDimensionalItemObject(org.hisp.dhis.common.ValueTypedDimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) AnalyticalObject(org.hisp.dhis.common.AnalyticalObject) List(java.util.List) ArrayList(java.util.ArrayList) MetadataItem(org.hisp.dhis.common.MetadataItem)

Aggregations

ListGrid (org.hisp.dhis.system.grid.ListGrid)58 Grid (org.hisp.dhis.common.Grid)41 GridHeader (org.hisp.dhis.common.GridHeader)28 Test (org.junit.jupiter.api.Test)21 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)14 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)11 ArrayList (java.util.ArrayList)10 DimensionalObject (org.hisp.dhis.common.DimensionalObject)10 HashMap (java.util.HashMap)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 DataElement (org.hisp.dhis.dataelement.DataElement)8 List (java.util.List)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 Test (org.junit.Test)7 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)6 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)5 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5