protected ICommand extractPreviousCommand(ExecutionController ctrl) { CommandHistory commandHistory = ctrl.getWorkspace().getCommandHistory(); List<ICommand> commands = commandHistory._getHistory(); for(int i = commands.size() -1 ; i>=0; i--) { ICommand command = commands.get(i); if(command instanceof SubmitPythonTransformationCommand) { SubmitPythonTransformationCommand pyCommand = (SubmitPythonTransformationCommand)command; if(pyCommand.worksheetId.equals(this.worksheetId) && pyCommand.pythonNodeId.equals(this.pythonNodeId)) { return command; } } } return null; }
private void writeHistoryPerWorksheet(Workspace workspace, IHistorySaver historySaver) throws Exception { String workspaceId = workspace.getId(); Map<String, JSONArray> comMap = new HashMap<>(); for(ICommand command : _getHistory()) { if(command.isSavedInHistory() && (command.hasTag(CommandTag.Modeling) || command.hasTag(CommandTag.Transformation) || command.hasTag(CommandTag.Selection) || command.hasTag(CommandTag.SemanticType) )) { JSONArray json = new JSONArray(command.getInputParameterJson()); String worksheetId = HistoryJsonUtil.getStringValue(HistoryArguments.worksheetId.name(), json); if(workspace.getWorksheet(worksheetId) != null) { try { if(comMap.get(worksheetId) == null) comMap.put(worksheetId, new JSONArray()); comMap.get(worksheetId).put(getCommandJSON(workspace, command)); } catch(Exception e) { logger.error("Error serializing command {} to history, Input:{}", command.getCommandName(), command.getInputParameterJson()); } } } } for(Map.Entry<String, JSONArray> stringJSONArrayEntry : comMap.entrySet()) { JSONArray comms = stringJSONArrayEntry.getValue(); historySaver.saveHistory(workspaceId, stringJSONArrayEntry.getKey(), comms); } }
@Override public UpdateContainer doIt(Workspace workspace) throws CommandException { HNode columnNode = workspace.getFactory().getHNode(hNodeId); oldColumnName = columnNode.getColumnName(); // Change the column name columnNode.setColumnName(newColumnName); newColumnAbsoluteName = columnNode.getAbsoluteColumnName(workspace.getFactory()); CommandHistory history = workspace.getCommandHistory(); List<ICommand> allCommands = history._getHistory(); for(ICommand command : allCommands) { String json = command.getInputParameterJson(); if(json != null && json.length() > 0) { JSONArray inputs = new JSONArray(json); for(int i=0; i<inputs.length(); i++) { JSONObject input = inputs.getJSONObject(i); replaceColumnName(input); } command.setInputParameterJson(inputs.toString()); } } // Prepare the output to be sent UpdateContainer c = WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, SuperSelectionManager.DEFAULT_SELECTION, workspace.getContextId()); c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace)); return c; }
history._getHistory().add(t); history._getHistory().addAll(tmp);