Search in sources :

Example 31 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class Visualization method addHierarchyColumns.

/**
 * Adds grid columns for each organisation unit level.
 */
@SuppressWarnings("unchecked")
private void addHierarchyColumns(final Grid grid, final int ouIdColumnIndex) {
    Map<Object, List<?>> ancestorMap = (Map<Object, List<?>>) grid.getInternalMetaData().get(ORG_UNIT_ANCESTORS.getKey());
    Assert.notEmpty(ancestorMap, "Ancestor map cannot be null or empty when show hierarchy is enabled");
    int newColumns = ancestorMap.values().stream().mapToInt(List::size).max().orElseGet(() -> 0);
    List<GridHeader> headers = new ArrayList<>();
    for (int i = 0; i < newColumns; i++) {
        int level = i + 1;
        String name = String.format("Org unit level %d", level);
        String column = String.format("orgunitlevel%d", level);
        headers.add(new GridHeader(name, column, TEXT, false, true));
    }
    grid.addHeaders(ouIdColumnIndex, headers);
    grid.addAndPopulateColumnsBefore(ouIdColumnIndex, ancestorMap, newColumns);
}
Also used : ArrayList(java.util.ArrayList) BaseAnalyticalObject(org.hisp.dhis.common.BaseAnalyticalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) MetadataObject(org.hisp.dhis.common.MetadataObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) DimensionalObjectUtils.getSortedKeysMap(org.hisp.dhis.common.DimensionalObjectUtils.getSortedKeysMap) Map(java.util.Map) HashMap(java.util.HashMap) GridHeader(org.hisp.dhis.common.GridHeader)

Example 32 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class QueryItemHelperTest method stubGridWithEmptyRowsAndOptionSet.

private Grid stubGridWithEmptyRowsAndOptionSet(final OptionSet optionSet) {
    final Grid grid = new ListGrid();
    final GridHeader headerA = new GridHeader("ColA", "colA", ValueType.TEXT, false, true, optionSet, null, "programStage", new RepeatableStageParams());
    final GridHeader headerB = new GridHeader("ColB", "colB", ValueType.TEXT, false, true);
    grid.addHeader(headerA);
    grid.addHeader(headerB);
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 33 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class QueryItemHelperTest method stubGridWithRowsAndOptionSet.

private Grid stubGridWithRowsAndOptionSet(final OptionSet optionSet) {
    final Grid grid = new ListGrid();
    final GridHeader headerA = new GridHeader("ColA", "colA", ValueType.TEXT, false, true, optionSet, null, "programStage", new RepeatableStageParams());
    final GridHeader headerB = new GridHeader("ColB", "colB", ValueType.TEXT, false, true);
    grid.addHeader(headerA);
    grid.addHeader(headerB);
    grid.addRow();
    grid.addValue("Code-A");
    grid.addValue(11);
    grid.addRow();
    grid.addValue(21);
    grid.addValue(22);
    grid.addRow();
    grid.addValue(31);
    grid.addValue(32);
    grid.addRow();
    grid.addValue(41);
    grid.addValue(42);
    return grid;
}
Also used : ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 34 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class AnalyticsCacheTest method returnSameObjectAfterModifyCachedObject.

@Test
void returnSameObjectAfterModifyCachedObject() {
    // arrange
    final AnalyticsCacheSettings settings = new AnalyticsCacheSettings(systemSettingManager);
    final CacheBuilder<Grid> cacheBuilder = new SimpleCacheBuilder<>();
    cacheBuilder.expireAfterWrite(1L, TimeUnit.MINUTES);
    final Cache<Grid> cache = new LocalCache<>(cacheBuilder);
    Mockito.<Cache<Grid>>when(cacheProvider.createAnalyticsCache()).thenReturn(cache);
    final AnalyticsCache analyticsCache = new AnalyticsCache(cacheProvider, settings);
    final Grid grid = new ListGrid();
    grid.addHeader(new GridHeader("Header1")).addHeader(new GridHeader("Header2")).addRow().addValue("Value11").addValue("Value12").addRow().addValue("Value21").addValue("Value22");
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(Lists.newArrayList(new DataElement("dataElementA"), new DataElement("dataElementB"))).build();
    // act, assert
    analyticsCache.put(params.getKey(), grid, 60);
    Optional<Grid> optCachedGrid = analyticsCache.get(params.getKey());
    assertTrue(optCachedGrid.isPresent());
    assertEquals(2, optCachedGrid.get().getHeaderWidth());
    assertEquals(2, optCachedGrid.get().getRows().size());
    // when the cachedGrid is not the clone of grid, next actions will
    // modify it
    grid.addHeader(new GridHeader("Header3")).addRow().addValue("31").addValue("32");
    optCachedGrid = analyticsCache.get(params.getKey());
    assertTrue(optCachedGrid.isPresent());
    assertEquals(2, optCachedGrid.get().getHeaderWidth());
    assertEquals(2, optCachedGrid.get().getRows().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) LocalCache(org.hisp.dhis.cache.LocalCache) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) SimpleCacheBuilder(org.hisp.dhis.cache.SimpleCacheBuilder) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader) Test(org.junit.jupiter.api.Test)

Example 35 with GridHeader

use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.

the class GridRenderUtils method asGrid.

/**
 * Generates a grid according to the provided columns, rows and values.
 *
 * @param columns the columns.
 * @param rows the rows.
 * @param valueMap the values as a mapping between metadata key and value.
 * @return a grid.
 */
public static Grid asGrid(List<? extends DimensionalObject> columns, List<? extends DimensionalObject> rows, Map<String, Object> valueMap) {
    List<List<DimensionalItemObject>> columnItems = columns.stream().map(DimensionalObject::getItems).collect(Collectors.toList());
    List<List<DimensionalItemObject>> rowItems = rows.stream().map(DimensionalObject::getItems).collect(Collectors.toList());
    List<List<DimensionalItemObject>> gridColumns = CombinationGenerator.newInstance(columnItems).getCombinations();
    List<List<DimensionalItemObject>> gridRows = CombinationGenerator.newInstance(rowItems).getCombinations();
    Map<String, Object> internalValueMap = getSortedKeysMap(valueMap);
    Grid grid = new ListGrid();
    for (DimensionalObject object : rows) {
        grid.addHeader(new GridHeader(object.getDimension(), object.getDimensionDisplayName()));
    }
    for (List<DimensionalItemObject> column : gridColumns) {
        grid.addHeader(new GridHeader(getKey(column), getName(column)));
    }
    for (List<DimensionalItemObject> row : gridRows) {
        grid.addRow();
        for (DimensionalItemObject object : row) {
            grid.addValue(object.getDisplayName());
        }
        for (List<DimensionalItemObject> column : gridColumns) {
            String key = getKey(column, row);
            Object value = internalValueMap.get(key);
            grid.addValue(value);
        }
    }
    return grid;
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) List(java.util.List) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject) ListGrid(org.hisp.dhis.system.grid.ListGrid) DimensionalObject(org.hisp.dhis.common.DimensionalObject) GridHeader(org.hisp.dhis.common.GridHeader)

Aggregations

GridHeader (org.hisp.dhis.common.GridHeader)63 Grid (org.hisp.dhis.common.Grid)41 ListGrid (org.hisp.dhis.system.grid.ListGrid)31 Test (org.junit.jupiter.api.Test)17 ArrayList (java.util.ArrayList)15 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)15 DimensionalObject (org.hisp.dhis.common.DimensionalObject)13 HashMap (java.util.HashMap)9 List (java.util.List)8 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)7 Map (java.util.Map)6 QueryItem (org.hisp.dhis.common.QueryItem)6 LinkedHashSet (java.util.LinkedHashSet)5 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)5 DataElement (org.hisp.dhis.dataelement.DataElement)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 RepeatableStageParams (org.hisp.dhis.common.RepeatableStageParams)4 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)3