use of org.hisp.dhis.common.DataDimensionalItemObject in project dhis2-core by dhis2.
the class AnalyticsUtils method handleGridForDataValueSet.
/**
* Prepares the given grid to be converted to a data value set.
*
* <ul>
* <li>Converts data values from double to integer based on the associated
* data item if required.</li>
* <li>Adds a category option combo and a attribute option combo column to
* the grid based on the aggregated export properties of the associated data
* item.</li>
* <li>For data element operand data items, the operand identifier is split
* and the data element identifier is used for the data dimension column and
* the category option combo identifier is used for the category option
* combo column.</li>
* </ul>
*
* @param params the data query parameters.
* @param grid the grid.
*/
public static void handleGridForDataValueSet(DataQueryParams params, Grid grid) {
Map<String, DimensionalItemObject> dimItemObjectMap = AnalyticsUtils.getDimensionalItemObjectMap(params);
List<Object> cocCol = Lists.newArrayList();
List<Object> aocCol = Lists.newArrayList();
int dxInx = grid.getIndexOfHeader(DATA_X_DIM_ID);
int vlInx = grid.getHeaderWidth() - 1;
Assert.isTrue(dxInx >= 0, "Data dimension index must be greater than or equal to zero");
Assert.isTrue(vlInx >= 0, "Value index must be greater than or equal to zero");
for (List<Object> row : grid.getRows()) {
String dx = String.valueOf(row.get(dxInx));
Assert.notNull(dx, "Data dimension item cannot be null");
DimensionalItemObject item = dimItemObjectMap.get(dx);
Assert.notNull(item, "Dimensional item cannot be null");
Object value = AnalyticsUtils.getIntegerOrValue(row.get(vlInx), item);
row.set(vlInx, value);
String coc = null, aoc = null;
if (DataDimensionalItemObject.class.isAssignableFrom(item.getClass())) {
DataDimensionalItemObject dataItem = (DataDimensionalItemObject) item;
coc = dataItem.getAggregateExportCategoryOptionCombo();
aoc = dataItem.getAggregateExportAttributeOptionCombo();
} else if (DataElementOperand.class.isAssignableFrom(item.getClass())) {
row.set(dxInx, DimensionalObjectUtils.getFirstIdentifer(dx));
coc = DimensionalObjectUtils.getSecondIdentifer(dx);
}
cocCol.add(coc);
aocCol.add(aoc);
}
grid.addHeader(vlInx, new GridHeader(ATTRIBUTEOPTIONCOMBO_DIM_ID, ATTRIBUTEOPTIONCOMBO_DIM_ID, ValueType.TEXT, false, true)).addHeader(vlInx, new GridHeader(CATEGORYOPTIONCOMBO_DIM_ID, CATEGORYOPTIONCOMBO_DIM_ID, ValueType.TEXT, false, true)).addColumn(vlInx, aocCol).addColumn(vlInx, cocCol);
}
Aggregations