use of org.hisp.dhis.system.grid.ListGrid 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;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class DefaultOrgUnitAnalyticsService method getOrgUnitDataNormalized.
private Grid getOrgUnitDataNormalized(OrgUnitQueryParams params) {
Grid grid = new ListGrid();
addHeaders(params, grid);
addMetadata(params, grid);
getOrgUnitDataMap(params).entrySet().forEach(entry -> {
grid.addRow().addValues(entry.getKey().split(DIMENSION_SEP)).addValue(entry.getValue());
});
return grid;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class PeriodOffsetUtilsTest method verifyGetPeriodOffsetRow.
@Test
void verifyGetPeriodOffsetRow() {
// Given
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));
int periodIndex = 2;
grid.addRow();
grid.addValue("de1");
grid.addValue("ou2");
grid.addValue("202001");
grid.addValue(3);
grid.addRow();
grid.addValue("de1");
grid.addValue("ou3");
grid.addValue("202002");
grid.addValue(5);
DataElement dataElement = createDataElement(0);
dataElement.setUid("de1");
// When
final List<Object> row1 = PeriodOffsetUtils.getPeriodOffsetRow(grid.getRow(0), periodIndex, 1);
// Then
assertThat(row1, is(notNullValue()));
assertThat(row1, hasSize(4));
assertThat(row1.get(periodIndex), is("201912"));
// When
final List<Object> row2 = PeriodOffsetUtils.getPeriodOffsetRow(grid.getRow(1), periodIndex, -1);
// Then
assertThat(row2, is(notNullValue()));
assertThat(row2, hasSize(4));
assertThat(row2.get(periodIndex), is("202003"));
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class EventPredictionServiceTest method newGrid.
// -------------------------------------------------------------------------
// Local convenience methods
// -------------------------------------------------------------------------
/**
* Make a data grid for MockAnalyticsService to return.
*
* @param dimensionItem Dimension item to be queried for
* @param values (if any), starting with March 2017
* @return the Grid, as would be returned by analytics
*/
private Grid newGrid(String dimensionItem, double... values) {
Grid grid = new ListGrid();
grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ATTRIBUTEOPTIONCOMBO_DIM_ID));
grid.addHeader(new GridHeader(VALUE_ID));
int month = Integer.valueOf(testYear + "03");
for (double value : values) {
grid.addRow();
grid.addValue(dimensionItem);
grid.addValue(Integer.toString(month++));
grid.addValue(orgUnitA.getUid());
grid.addValue("HllvX50cXC0");
grid.addValue(new Double(value));
}
return grid;
}
use of org.hisp.dhis.system.grid.ListGrid in project dhis2-core by dhis2.
the class DefaultVisualizationGridService method getVisualizationGridByUser.
@Override
@Transactional(readOnly = true)
public Grid getVisualizationGridByUser(final String uid, final Date relativePeriodDate, final String organisationUnitUid, final User user) {
Visualization visualization = visualizationService.getVisualization(uid);
final boolean hasPermission = visualization != null;
if (hasPermission) {
I18nFormat format = i18nManager.getI18nFormat();
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitUid);
List<OrganisationUnit> atLevels = new ArrayList<>();
List<OrganisationUnit> inGroups = new ArrayList<>();
if (visualization.hasOrganisationUnitLevels()) {
atLevels.addAll(organisationUnitService.getOrganisationUnitsAtLevels(visualization.getOrganisationUnitLevels(), visualization.getOrganisationUnits()));
}
if (visualization.hasItemOrganisationUnitGroups()) {
inGroups.addAll(organisationUnitService.getOrganisationUnits(visualization.getItemOrganisationUnitGroups(), visualization.getOrganisationUnits()));
}
visualization.init(user, relativePeriodDate, organisationUnit, atLevels, inGroups, format);
Map<String, Object> valueMap = analyticsService.getAggregatedDataValueMapping(visualization);
Grid visualizationGrid = visualization.getGrid(new ListGrid(), valueMap, SHORTNAME, true);
visualization.clearTransientState();
return visualizationGrid;
} else {
return new ListGrid();
}
}
Aggregations