diff --git a/karma-common/src/main/java/edu/isi/karma/controller/history/WorksheetCommandHistoryExecutor.java b/karma-common/src/main/java/edu/isi/karma/controller/history/WorksheetCommandHistoryExecutor.java index 0a4597873..0b480143f 100644 --- a/karma-common/src/main/java/edu/isi/karma/controller/history/WorksheetCommandHistoryExecutor.java +++ b/karma-common/src/main/java/edu/isi/karma/controller/history/WorksheetCommandHistoryExecutor.java @@ -41,7 +41,9 @@ import edu.isi.karma.controller.update.AbstractUpdate; import edu.isi.karma.controller.update.TrivialErrorUpdate; import edu.isi.karma.controller.update.UpdateContainer; +import edu.isi.karma.modeling.alignment.AlignmentManager; import edu.isi.karma.rep.HNode; +import edu.isi.karma.rep.HNode.HNodeType; import edu.isi.karma.rep.HTable; import edu.isi.karma.rep.Workspace; import edu.isi.karma.util.Util; @@ -97,38 +99,38 @@ private UpdateContainer executeCommand(JSONObject commObject, boolean saveToHist // Change the hNode ids, vworksheet id to point to the current worksheet ids try { UpdateContainer uc = normalizeCommandHistoryJsonInput(workspace, worksheetId, inputParamArr, commandName); - if(uc == null) { //No error - // Invoke the command + // Invoke the command + if (uc == null) { uc = new UpdateContainer(); - CommandFactory cf = commandFactoryMap.get(commObject.get(HistoryArguments.commandName.name())); - if(cf != null) { - try { // This is sort of a hack the way I did this, but could not think of a better way to get rid of the dependency - Command comm = cf.createCommand(inputParamArr, workspace); - if(comm != null){ - try { - logger.info("Executing command: " + commandName); - uc.append(workspace.getCommandHistory().doCommand(comm, workspace, saveToHistory)); - } catch(Exception e) { - logger.error("Error executing command: "+ commandName + ". Please notify this error"); - Util.logException(logger, e); - //make these InfoUpdates so that the UI can still process the rest of the model - return new UpdateContainer(new TrivialErrorUpdate("Error executing command " + commandName + " from history")); - } - } - else { - logger.error("Error occured while creating command (Could not create Command object): " - + commObject.get(HistoryArguments.commandName.name())); + } + CommandFactory cf = commandFactoryMap.get(commObject.get(HistoryArguments.commandName.name())); + if(cf != null) { + try { // This is sort of a hack the way I did this, but could not think of a better way to get rid of the dependency + Command comm = cf.createCommand(inputParamArr, workspace); + if(comm != null){ + try { + logger.info("Executing command: " + commandName); + uc.append(workspace.getCommandHistory().doCommand(comm, workspace, saveToHistory)); + } catch(Exception e) { + logger.error("Error executing command: "+ commandName + ". Please notify this error"); + Util.logException(logger, e); + //make these InfoUpdates so that the UI can still process the rest of the model return new UpdateContainer(new TrivialErrorUpdate("Error executing command " + commandName + " from history")); } - } catch (UnsupportedOperationException ignored) { - } + else { + logger.error("Error occured while creating command (Could not create Command object): " + + commObject.get(HistoryArguments.commandName.name())); + return new UpdateContainer(new TrivialErrorUpdate("Error executing command " + commandName + " from history")); + } + } catch (UnsupportedOperationException ignored) { + } - } + } + return uc; } catch(Exception e) { - logger.error("Error executing command: "+ commandName + ". Please notify this error"); - Util.logException(logger, e); + logger.error("Error executing command: "+ commandName + ".", e); //make these InfoUpdates so that the UI can still process the rest of the model return new UpdateContainer(new TrivialErrorUpdate("Error executing command " + commandName + " from history")); } @@ -169,15 +171,13 @@ public UpdateContainer normalizeCommandHistoryJsonInput(Workspace workspace, Str String nameObjColumnName = cNameObj.getString("columnName"); logger.debug("Column being normalized: "+ nameObjColumnName); HNode node = hTable.getHNodeFromColumnName(nameObjColumnName); - if(node == null && !ignoreIfBeforeColumnDoesntExist(commandName)) { //Because add column can happen even if the column after which it is to be added is not present - logger.info("null HNode " + nameObjColumnName + " while normalizing JSON input for the command " + commandName); - AbstractUpdate update = new TrivialErrorUpdate("Column " + nameObjColumnName + " does not exist. " + - "All commands for this column are being skipped. You can add the column to the data or Worksheet and apply the model again."); + 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); - continue; + hTable.addHNode(nameObjColumnName, HNodeType.Regular, workspace.getWorksheet(worksheetId), workspace.getFactory()); } if (j == hNodeJSONRep.length()-1) { // Found! @@ -186,6 +186,7 @@ public UpdateContainer normalizeCommandHistoryJsonInput(Workspace workspace, Str else { //Get the id of the last node in the table ArrayList allNodeIds = hTable.getOrderedNodeIds(); + //TODO check for allNodeIds.size == 0 String lastNodeId = allNodeIds.get(allNodeIds.size()-1); inpP.put(ClientJsonKeys.value.name(), lastNodeId); } @@ -193,6 +194,9 @@ public UpdateContainer normalizeCommandHistoryJsonInput(Workspace workspace, Str getWorksheet(worksheetId).getHeaders(); } else if(node != null) { hTable = node.getNestedTable(); + if (hTable == null) { + hTable = node.addNestedTable("NestedTable", workspace.getWorksheet(worksheetId), workspace.getFactory()); + } } } } else if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.worksheetId) { @@ -215,16 +219,13 @@ public UpdateContainer normalizeCommandHistoryJsonInput(Workspace workspace, Str String nameObjColumnName = cNameObj.getString("columnName"); logger.debug("Column being normalized: "+ nameObjColumnName); HNode node = hTable.getHNodeFromColumnName(nameObjColumnName); - if(node == null && !ignoreIfBeforeColumnDoesntExist(commandName)) { //Because add column can happen even if the column after which it is to be added is not present - logger.info("null HNode " + nameObjColumnName + " while normalizing JSON input for the command " + commandName); - AbstractUpdate update = new TrivialErrorUpdate("Column " + nameObjColumnName + " does not exist. " + - "All commands for this column are being skipped. You can add the column to the data or Worksheet and apply the model again."); + 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); - continue; - //return false; + hTable.addHNode(nameObjColumnName, HNodeType.Regular, workspace.getWorksheet(worksheetId), workspace.getFactory()); } if (j == hNodeJSONRep.length()-1) { // Found! @@ -240,6 +241,9 @@ public UpdateContainer normalizeCommandHistoryJsonInput(Workspace workspace, Str getWorksheet(worksheetId).getHeaders(); } else if(node != null) { hTable = node.getNestedTable(); + if (hTable == null) { + hTable = node.addNestedTable("NestedTable", workspace.getWorksheet(worksheetId), workspace.getFactory()); + } } } } @@ -255,14 +259,15 @@ else if (HistoryJsonUtil.getParameterType(inpP) == ParameterType.orderedColumns) JSONArray children = new JSONArray(hnodeJSON.get(ClientJsonKeys.children.name()).toString()); hnodeJSON.put(ClientJsonKeys.children.name(), processChildren(children, hTable, commandName)); } - + } inpP.put(ClientJsonKeys.value.name(), hNodes.toString()); } } + AlignmentManager.Instance().getAlignmentOrCreateIt(workspace.getId(), worksheetId, workspace.getOntologyManager()); return uc; } - + private boolean processHNodeId(JSONArray hNodeJSONRep, HTable hTable, String commandName, JSONObject hnodeJSON) { for (int j=0; j