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);
}
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;
}
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;
}
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());
}
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;
}
Aggregations