public Set<String> generateOutputColumns() { Set<String> outputColumns = new HashSet<>(); for (Command t : commands) { if (t.getOutputColumns() != null) outputColumns.addAll(t.getOutputColumns()); } return outputColumns; }
public static void detectSelectionStatusChange(String worksheetId, Workspace workspace, Command command) { Worksheet worksheet = workspace.getWorksheet(worksheetId); for (Selection sel : worksheet.getSelectionManager().getAllDefinedSelection()) { Set<String> inputColumns = sel.getInputColumns(); inputColumns.retainAll(command.getOutputColumns()); if (!inputColumns.isEmpty() && !command.getCommandName().equals("OperateSelectionCommand") && !command.getCommandName().equals("ClearSelectionCommand")) sel.invalidateSelection(); if (sel.isSelectedRowsMethod() && checkSelection(sel, command, workspace.getFactory())) { sel.invalidateSelection(); } } }
private void placeTransformCommandByInput(Command command) { ICommand placeAfterCmd = null; Set<String> cmdInputs = command.getInputColumns(); Set<String> cmdOutputs = command.getOutputColumns(); List<Command> commandsToMove = new ArrayList<>(); for (ICommand afterCmd : worksheetCommandHistory.getCommandsAfterCommand(command, CommandTag.Transformation)) { Set<String> afterCmdOutputs = ((Command)afterCmd).getOutputColumns(); Set<String> afterCmdInputs = ((Command)afterCmd).getInputColumns(); for(String input : cmdInputs) { if(afterCmdOutputs.contains(input)) { JSONArray inputJSON = new JSONArray(command.getInputParameterJson()); JSONArray placeAfterCmdInputJSON = new JSONArray(command.getInputParameterJson()); String placeHNodeId = HistoryJsonUtil.getStringValue("hNodeId", placeAfterCmdInputJSON); HistoryJsonUtil.setArgumentValue("hNodeId", placeHNodeId, inputJSON); command.setInputParameterJson(inputJSON.toString()); worksheetCommandHistory.insertCommandToHistoryAfterCommand(command, placeAfterCmd);
protected void logCommand(Logger logger, Workspace workspace) { try { logger.info("Executing command:" + getCommandName() + "\n" + getInputParameterJson()); } catch (JSONException e) { e.printStackTrace(); } }
private void createShortcut(Command command){ Intent shortcutIntent = new Intent(this, FormActivity.class); // As binary because OS does not know type Command command.putToIntentAsXml(shortcutIntent); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, command.getTitle()); Parcelable iconResource = Intent .ShortcutIconResource .fromContext(this, R.drawable.ic_launcher); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(intent); }
public class Main { private static Map<String, Command> commands = new HashMap<String, Command>(); private static void init() { Command addCommand = new AddCommand(); commands.put(addCommand.getCommandName(), addCommand); } public static void main (String[] args) { init(); if (args[0] != null) { Command command = commands.get(args[0]); if (command != null) { System.out.println(command.doAction()); } else { System.out.println("Command not found"); } } }
String worksheetId = worksheetCommandHistory.getWorksheetId(command); RepFactory factory = workspace.getFactory(); List<ICommand> potentialConsolidateCommands = worksheetCommandHistory.getCommandsFromWorksheetIdAndCommandTag(worksheetId, command.getTagFromPriority()); for (CommandConsolidator consolidator : consolidators) { consolidatedCommand = consolidator.consolidateCommand(potentialConsolidateCommands, command, workspace); if (consolidatorName.equals("PyTransformConsolidator")) { Command runCommand = (Command)consolidatedCommand.getLeft(); effects.append(runCommand.doIt(workspace)); if(runCommand.getInputColumns().size() > 0 && !runCommand.getInputColumns().equals(command.getInputColumns())) { Pair<Boolean, Set<String>> cycleDetect = detectTransformCycle(worksheetId); if(cycleDetect.getLeft() == false) { effects.append(command.doIt(workspace)); effects.append(command.doIt(workspace)); effects.append(command.doIt(workspace)); effects.append(command.doIt(workspace)); command.setExecuted(true); if (command.getCommandType() != CommandType.notInHistory) { worksheetId = worksheetCommandHistory.getWorksheetId(command); worksheetCommandHistory.clearRedoCommand(worksheetId);
private Map<Command, List<Command> > generateGraph() { Map<Command, List<Command> > dag = new HashMap<>(); Map<String, List<Command> > outputMapping = new HashMap<>(); for (Command command : commands) { Set<String> inputs = command.getInputColumns(); for (String input : inputs) { List<Command> outputCommands = outputMapping.get(input); if (outputCommands != null) { List<Command> edges = dag.get(command); if (edges == null) edges = new ArrayList<>(); for (Command tmp : outputCommands) { if (tmp != command) edges.add(tmp); } dag.put(command, edges); } } Set<String> outputs = command.getOutputColumns(); for (String output : outputs) { List<Command> tmp = outputMapping.get(output); if (tmp == null) tmp = new ArrayList<>(); tmp.add(command); outputMapping.put(output, tmp); } } return dag; }
cmd.doIt(workspace); outputColumns.addAll(cmd.getOutputColumns()); WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this); UpdateContainer c = new UpdateContainer();
@Override public UpdateContainer doIt(Workspace workspace) throws CommandException { ApplyHistoryFromR2RMLModelCommandFactory factory = new ApplyHistoryFromR2RMLModelCommandFactory(); try { String context = (modelContext != null && !modelContext.isEmpty()? (modelContext + "/") : ""); URL url = new URL(baseUrl + context + modelURL + "?modelRepository=" + modelRepository); File file = new File("tmp.ttl"); FileUtils.copyURLToFile(url, file); Command cmd = factory.createCommandFromFile(model, worksheetId, file, workspace, override); UpdateContainer uc = cmd.doIt(workspace); workspace.getWorksheet(worksheetId).getMetadataContainer().getWorksheetProperties().setPropertyValue(Property.modelUrl, modelURL); workspace.getWorksheet(worksheetId).getMetadataContainer().getWorksheetProperties().setPropertyValue(Property.modelContext, modelContext); workspace.getWorksheet(worksheetId).getMetadataContainer().getWorksheetProperties().setPropertyValue(Property.modelRepository, modelRepository); file.delete(); return uc; }catch(Exception e) { String msg = "Error occured while applying history!"; logger.error(msg, e); return new UpdateContainer(new ErrorUpdate(msg)); } }
@Override public Command createCommand(JSONArray inputJson, String model, Workspace workspace) throws JSONException, KarmaException { String worksheetId = CommandInputJSONUtil.getStringValue(Arguments.worksheetId.name(), inputJson); String currentSelectionName = CommandInputJSONUtil.getStringValue(Arguments.selectionName.name(), inputJson); Command cmd = new RefreshSuperSelectionCommand(getNewId(workspace), model, worksheetId, currentSelectionName); cmd.setInputParameterJson(inputJson.toString()); return cmd; }
protected void generateCommandJSONAttributes(String prefix, PrintWriter pw, VWorkspace vWorkspace, HistoryType historyType) { String newPref = prefix + " "; pw.println(newPref + JSONUtil.json(JsonKeys.commandId, getId())); pw.println(newPref + JSONUtil.json(JsonKeys.title, getTitle())); pw.println(newPref + JSONUtil.json(JsonKeys.description, getDescription())); pw.println(newPref + JSONUtil.json(JsonKeys.historyType, historyType.name())); pw.println(newPref + JSONUtil.jsonLast(JsonKeys.commandType, getCommandType() .name())); }
public Set<String> generateInputColumns() { Map<Command, List<Command> > dag = generateGraph(); Set<String> inputColumns = new HashSet<>(); for (Command t : commands) { if (t.getCommandName().equals("SetSemanticTypeCommand") || t.getCommandName().equals("SetMetaPropertyCommand")) { inputColumns.addAll(getParents(t, dag)); } } return inputColumns; }
@Override public UpdateContainer undoIt(Workspace workspace) { UpdateContainer c = new UpdateContainer(); while (!appliedCommands.isEmpty()) { Command command = appliedCommands.pop(); command.undoIt(workspace); } c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(workspace), workspace.getContextId())); c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace)); return c; }
public Command getPreviewCommand(String commandId) { if (previewCommand.getId().equals(commandId)) return previewCommand; return null; }
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; }
private Set<String> getParents(Command c, Map<Command, List<Command> >dag) { List<Command> parents = dag.get(c); Set<String> terminalColumns = new HashSet<>(); if (parents == null || parents.size() == 0) terminalColumns.addAll(c.getInputColumns()); else { for (Command t : parents) { terminalColumns.addAll(getParents(t, dag)); for (String hNodeId : c.getInputColumns()) { HNode hn = workspace.getFactory().getHNode(hNodeId); if (hn != null && hn.getHNodeType() == HNodeType.Regular) terminalColumns.add(hNodeId); } } } return terminalColumns; }
private Pair<Boolean, Set<String>> detectTransformCycle(String worksheetId) { DirectedGraph<String, DefaultEdge> historyInputOutputGraph = new DefaultDirectedGraph<>(DefaultEdge.class); for (ICommand cmd : worksheetCommandHistory.getCommandsFromWorksheetIdAndCommandTag(worksheetId, CommandTag.Transformation)) { Set<String> outputs = ((Command)cmd).getOutputColumns(); Set<String> inputs = ((Command)cmd).getInputColumns(); String commandId = "Command-" + cmd.getId(); historyInputOutputGraph.addVertex(commandId);
false, semanticTypesArray, false, "", "", selection.getName()); appliedCommands.push(sstCommand); sstCommand.doIt(workspace); if(!resultClass.get(i).trim().isEmpty()) changeInternalNodeLinksCommand.doIt(workspace); appliedCommands.push(changeInternalNodeLinksCommand); Command setMetaDataCommand = smpcf.createCommand(model, workspace, nestedHNodeId, worksheetId, "isUriOfClass", targetUri, targetId, false, "", "", selection.getName()); setMetaDataCommand.doIt(workspace); appliedCommands.push(setMetaDataCommand);
@Override public Command createCommand(JSONArray inputJson, String model, Workspace workspace) throws JSONException, KarmaException { String worksheetId = CommandInputJSONUtil.getStringValue(Arguments.worksheetId.name(), inputJson); this.normalizeSelectionId(worksheetId, inputJson, workspace); String selectionName = CommandInputJSONUtil.getStringValue(Arguments.selectionName.name(), inputJson); Command command = new RefreshHistoryCommand(getNewId(workspace), model, worksheetId, selectionName); command.setInputParameterJson(inputJson.toString()); return command; }