if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.hNodeId) {
JSONArray hNodeJSONRep = new JSONArray(inpP.get(ClientJsonKeys.value.name()).toString());
for (int j=0; j<hNodeJSONRep.length(); j++) {
JSONObject cNameObj = (JSONObject) hNodeJSONRep.get(j);
if(hTable == null) {
AbstractUpdate update = new TrivialErrorUpdate("null HTable while normalizing JSON input for the command " + commandName);
if (uc == null)
uc = new UpdateContainer(update);
else
uc.add(update);
continue;
}
String nameObjColumnName = cNameObj.getString("columnName");
logger.debug("Column being normalized: "+ nameObjColumnName);
HNode node = hTable.getHNodeFromColumnName(nameObjColumnName);
if(node == null) { //Because add column can happen even if the column after which it is to be added is not present
AbstractUpdate update = new TrivialErrorUpdate(nameObjColumnName + " does not exist, using empty values");
if (uc == null)
uc = new UpdateContainer(update);
else
uc.add(update);
if (addIfNonExist) {
node = hTable.addHNode(nameObjColumnName, HNodeType.Regular, workspace.getWorksheet(worksheetId), workspace.getFactory());
}
else {
continue;
}
}
if (j == hNodeJSONRep.length()-1) { // Found!
if(node != null)
inpP.put(ClientJsonKeys.value.name(), node.getId());
else {
//Get the id of the last node in the table
ArrayList<String> allNodeIds = hTable.getOrderedNodeIds();
//TODO check for allNodeIds.size == 0
String lastNodeId = allNodeIds.get(allNodeIds.size()-1);
inpP.put(ClientJsonKeys.value.name(), lastNodeId);
}
hTable = workspace.
getWorksheet(worksheetId).getHeaders();
} else if(node != null) {
hTable = node.getNestedTable();
if (hTable == null && addIfNonExist) {
hTable = node.addNestedTable("NestedTable", workspace.getWorksheet(worksheetId), workspace.getFactory());
}
}
}
} else if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.worksheetId) {
inpP.put(ClientJsonKeys.value.name(), worksheetId);
} else if (HistoryJsonUtil.getParameterType(inpP) == ParameterType.hNodeIdList) {
JSONArray hNodes = new JSONArray(inpP.get(ClientJsonKeys.value.name()).toString());
for (int k = 0; k < hNodes.length(); k++) {
JSONObject hnodeJSON = hNodes.getJSONObject(k);
JSONArray hNodeJSONRep = new JSONArray(hnodeJSON.get(ClientJsonKeys.value.name()).toString());
for (int j=0; j<hNodeJSONRep.length(); j++) {
JSONObject cNameObj = (JSONObject) hNodeJSONRep.get(j);
if(hTable == null) {
AbstractUpdate update = new TrivialErrorUpdate("null HTable while normalizing JSON input for the command " + commandName);
if (uc == null)
uc = new UpdateContainer(update);
else
uc.add(update);
continue;
}
String nameObjColumnName = cNameObj.getString("columnName");
logger.debug("Column being normalized: "+ nameObjColumnName);
HNode node = hTable.getHNodeFromColumnName(nameObjColumnName);
if(node == null) { //Because add column can happen even if the column after which it is to be added is not present
AbstractUpdate update = new TrivialErrorUpdate(nameObjColumnName + " does not exist, using empty values");
if (uc == null)
uc = new UpdateContainer(update);
else
uc.add(update);
if (addIfNonExist) {