public JSONArray getCommandsJSON() { JSONArray commandsArray = new JSONArray(); for (Command command : commands) { commandsArray.put(workspace.getCommandHistory().getCommandJSON(workspace, command)); } return commandsArray; }
public static boolean historyExists(String workspaceId, String worksheetId) { String filename = CommandHistory.getHistorySaver(workspaceId).getHistoryFilepath(worksheetId); File file = new File(filename); return file.exists(); }
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; }
SuperSelection selection = getSuperSelection(worksheet); CommandHistory history = workspace.getCommandHistory(); List<Command> oldCommands = history.getCommandsFromWorksheetId(worksheetId); if (storeOldHistory) { JSONArray oldCommandsArray = new JSONArray(); for (Command refined : oldCommands) oldCommandsArray.put(workspace.getCommandHistory().getCommandJSON(workspace, refined)); worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue( Property.oldCommandHistory, oldCommandsArray.toString()); CommandHistoryUtil historyUtil = new CommandHistoryUtil(history.getCommandsFromWorksheetId(worksheetId), workspace, worksheetId); boolean isHistoryStale = history.isStale(worksheetId); if (isHistoryStale) { System.out.println("**** REPLAY HISTORY ***"); worksheet = workspace.getWorksheet(worksheetId); selection = getSuperSelection(worksheet); historyUtil = new CommandHistoryUtil(history.getCommandsFromWorksheetId(worksheetId), workspace, worksheetId); SetSemanticTypeCommand cmd = (SetSemanticTypeCommand)wkCommand; if(cmd.hasProvenanceType()) { uc.append(workspace.getCommandHistory().doCommand(cmd, workspace, false)); uc.append(workspace.getCommandHistory().doCommand(cmd, workspace, false)); try { Command changeInternalNodeLinksCommand = cinlcf.createCommand(inputJSON, model, workspace); workspace.getCommandHistory().doCommand(changeInternalNodeLinksCommand, workspace); uc.add(new HistoryUpdate(workspace.getCommandHistory()));
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 { List<Command> commands = workspace.getCommandHistory().getCommandsFromWorksheetId(volatileWorksheetId); for (Command command : commands) { historyCommandsBackup.put(workspace.getCommandHistory().getCommandJSON(workspace, command));
List<Command> tmp = gatherAllOperateSelectionCommands(history.getCommandsFromWorksheetId(worksheetId), workspace); if (!tmp.isEmpty()) { JSONArray inputJSON = new JSONArray(); history._getHistory().add(t); history._getHistory().addAll(tmp);
/** * Commands go onto the history when they have all their arguments and are * ready to be executed. If a command needs multiple user interactions to * define the parameters, then the command object must be created, * interacted with and then executed. * * @param command * @param workspace * @return UpdateContainer with all the changes done by the command. * @throws CommandException */ public UpdateContainer doCommand(Command command, Workspace workspace) throws CommandException { return doCommand(command, workspace, true); }
@Override public UpdateContainer doIt(Workspace workspace) throws CommandException { CommandHistory history = workspace.getCommandHistory(); UpdateContainer updateContainer = new UpdateContainer(); if (history.isStale(worksheetId)) { CommandHistoryUtil util = new CommandHistoryUtil(history.getCommandsFromWorksheetId(worksheetId), workspace, worksheetId); updateContainer.append(util.replayHistory()); updateContainer.add(new HistoryUpdate(history)); } return updateContainer; }
public void deleteExistingTransformationCommands() { CommandHistory history = workspace.getCommandHistory(); CommandHistoryUtil util = new CommandHistoryUtil(history.getCommandsFromWorksheetId(worksheetId), workspace, worksheetId); Set<String> outputColumns = util.generateOutputColumns(); JSONArray newHistoryJSON = new JSONArray();
public CommandHistory getCommandHistory() { if(commandHistory == null) { commandHistory = new CommandHistory(); } return commandHistory; }
@Override public UpdateContainer doIt(Workspace workspace) throws CommandException { setRequestedInteractionType(InteractionType.importTable); UpdateContainer c = super.doIt(workspace); try { // Create a new Database Import Command. The interface allows the user to import // multiple tables ImportDatabaseTableCommand comm = new ImportDatabaseTableCommand(workspace.getFactory().getNewId("C"), model, dbType.name(), hostname, portnumber, username, password, dBorSIDName); workspace.getCommandHistory().addPreviewCommand(comm); NewDatabaseCommandUpdate upd = new NewDatabaseCommandUpdate(comm.getId()); c.add(upd); } catch (Throwable e) { String message = e.getMessage().replaceAll("\n", "").replaceAll("\"", "\\\""); ErrorUpdate errUpdt = new ErrorUpdate(message); c.add(errUpdt); } return c; }
public UpdateContainer invokeCommand(Command command) { synchronized (this) { try { UpdateContainer updateContainer = workspace.getCommandHistory().doCommand(command, workspace); return updateContainer; } catch (CommandException e) { logger.error( "Error occured with command " + command.toString(), e); UpdateContainer updateContainer = new UpdateContainer(); updateContainer.add(new ErrorUpdate("Error occured with command " + command.toString())); return updateContainer; // TODO probably need a return that indicates an // error. } } } }
public void deleteExistingTransformationAndModelingCommands() { CommandHistory history = workspace.getCommandHistory(); CommandHistoryUtil util = new CommandHistoryUtil(history.getCommandsFromWorksheetId(worksheetId), workspace, worksheetId); Set<String> outputColumns = util.generateOutputColumns(); JSONArray newHistoryJSON = new JSONArray();
public CommandHistory clone() { return new CommandHistory(worksheetCommandHistory.clone()); }
@Override public UpdateContainer doIt(Workspace workspace) throws CommandException { setRequestedInteractionType(InteractionType.importSQL); UpdateContainer c = super.doIt(workspace); try { // Create a new Database Import Command. The interface allows the user to import // multiple tables ImportSQLCommand comm = new ImportSQLCommand(workspace.getFactory().getNewId("C"), model, dbType.name(), hostname, portnumber, username, password, dBorSIDName, query); workspace.getCommandHistory().addPreviewCommand(comm); c.add(new InfoUpdate("Sucessfully imported data using SQL")); c.add(new SQLCommandUpdate(comm.getId())); } catch (Throwable e) { String message = e.getMessage().replaceAll("\n", "").replaceAll("\"", "\\\""); ErrorUpdate errUpdt = new ErrorUpdate(message); c.add(errUpdt); } return c; }
public JSONArray readCommandsByTag(List<CommandTag> tag) { JSONArray filteredHistoryJson = new JSONArray(); try { String filename = CommandHistory.getHistorySaver(workspace.getId()).getHistoryFilepath(worksheetId); JSONArray historyJson = CommandHistory.getHistorySaver(workspace.getId()).loadHistory(filename); filteredHistoryJson = HistoryJsonUtil.filterCommandsByTag(tag, historyJson); } catch (JSONException e) { logger.error("Error occured while working with JSON!", e); } catch(Exception e) { logger.error("Error reading from history file!", e); } return filteredHistoryJson; }
private UpdateContainer addNewLinks(WorksheetCommandHistoryExecutor histExecutor, Workspace workspace, Alignment alignment, OntologyManager ontMgr) throws JSONException { UpdateContainer uc = new UpdateContainer(); boolean saveToHistory = !this.isExecutedInBatch(); for (int i = 0; i < newEdges.length(); i++) { JSONObject newEdge = newEdges.getJSONObject(i); try { Command cmd = (new AddLinkCommandFactory()).createCommand(worksheetId, alignmentId, newEdge, model, workspace); cmd.setExecutedInBatch(this.isExecutedInBatch()); uc.append(workspace.getCommandHistory().doCommand(cmd, workspace, saveToHistory && i==newEdges.length()-1)); } catch(CommandException e) { logger.error("Error adding a new link: " + newEdge.toString(), e); } } return uc; }
public UpdateContainer replayHistory() { JSONArray redoCommandsArray = new JSONArray(); for (Command refined : commands) { redoCommandsArray.put(workspace.getCommandHistory().getCommandJSON(workspace, refined)); } return replayHistory(redoCommandsArray); }
@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; }