* @param columnMap map of column index to value used to update the column
* headers of the table.
*/
public Data getDataFromParams(Data data,
Map<String, String> dataParams, Map<String, String> columnMap) {
Data newData = new Data();
if (data == null) {
data = new Data();
}
if (dataParams.get("numrows") != null) {
newData.setNumberOfRows(Integer.parseInt(dataParams.get("numrows")));
} else {
newData.setNumberOfRows(data.getNumberOfRows());
}
if (dataParams.get("startrow") != null) {
newData.setStartIndex(Integer.parseInt(dataParams.get("startrow")));
} else {
newData.setStartIndex(data.getStartIndex());
}
String insertionMode = dataParams.get("insertionmode");
if (insertionMode != null && insertionMode.equals("insert")) {
newData.setInsertionMode(Data.InsertionMode.INSERT);
}
List<Column> existing = data.getColumns();
// Add existing column data to column map.
for (Column existingCol : existing) {
String index = existingCol.getIndex();
String name = existingCol.getName();
// If column is being updated, set value, else add a new one.
if (columnMap.get(index) == null) {
columnMap.put(index, name);
}
}
// Set columns on new data object.
for (String key : columnMap.keySet()) {
newData.addColumn(new Column(key, columnMap.get(key)));
}
return newData;
}