@Override public Command createCommand(HttpServletRequest request, Workspace workspace) { String hNodeId = request.getParameter(Arguments.hNodeId.name()); String hTableId = request.getParameter(Arguments.hTableId.name()); String worksheetId = request.getParameter(Arguments.worksheetId.name()); String selectionName = request.getParameter(Arguments.selectionName.name()); return new GroupByCommand(getNewId(workspace), Command.NEW_MODEL, worksheetId, hTableId, hNodeId, selectionName); }
protected GroupByCommand(String id, String model, String worksheetId, String hTableId, String hNodeId, String selectionId) { super(id, model, worksheetId, selectionId); this.hNodeId = hNodeId; addTag(CommandTag.Transformation); }
RepFactory factory = workspace.getFactory(); Worksheet oldws = workspace.getWorksheet(worksheetId); Object para = JSONUtil.createJson(this.getInputParameterJson()); List<String> hnodeIDs = new ArrayList<>(); List<HNode> keyhnodes = new ArrayList<>(); newws = groupByTopLevel(oldws, workspace, hnodeIDs, keyhnodes, valuehnodes, factory); else { inputColumns.addAll(hnodeIDs); groupByNestedTable(oldws, workspace, ht, hnodeIDs, keyhnodes, valuehnodes, factory); c.add(new WorksheetListUpdate()); if (newws == null) c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(oldws.getId(), getSuperSelection(oldws), workspace.getContextId())); if (newws != null) { c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(newws.getId(), SuperSelectionManager.DEFAULT_SELECTION, workspace.getContextId())); c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace)); return c; } catch (Exception e) {
@Override public Command createCommand(JSONArray inputJson, String model, Workspace workspace) throws JSONException, KarmaException { /** Parse the input arguments and create proper data structures to be passed to the command **/ String hNodeID = CommandInputJSONUtil.getStringValue(Arguments.hNodeId.name(), inputJson); String worksheetId = CommandInputJSONUtil.getStringValue(Arguments.worksheetId.name(), inputJson); String hTableId = ""; this.normalizeSelectionId(worksheetId, inputJson, workspace); String selectionName = CommandInputJSONUtil.getStringValue(Arguments.selectionName.name(), inputJson); //System.out.println(worksheetId); GroupByCommand unfoldCmd = new GroupByCommand(getNewId(workspace), model, worksheetId, hTableId, hNodeID, selectionName); unfoldCmd.setInputParameterJson(inputJson.toString()); return unfoldCmd; }
@Override public UpdateContainer undoIt(Workspace workspace) { UpdateContainer c = new UpdateContainer(); if (this.newWorksheetId != null) { workspace.removeWorksheet(newWorksheetId); workspace.getFactory().removeWorksheet(newWorksheetId, workspace.getCommandHistory()); c.add(new WorksheetListUpdate()); c.add(new WorksheetDeleteUpdate(newWorksheetId)); } if (this.newHNodeId != null) { Worksheet worksheet = workspace.getWorksheet(worksheetId); HNode ndid = workspace.getFactory().getHNode(newHNodeId); HTable currentTable = workspace.getFactory().getHTable(ndid.getHTableId()); ndid.removeNestedTable(); //remove the new column currentTable.removeHNode(newHNodeId, worksheet); c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet), workspace.getContextId())); c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace)); } return c; }
private void groupByNestedTable(Worksheet oldws, Workspace workspace, HTable ht, List<String> hnodeIDs, List<HNode> keyhnodes, List<HNode> valuehnodes, RepFactory factory) { SuperSelection selection = getSuperSelection(oldws); HTable parentHT = ht.getParentHNode().getHTable(factory); List<Table> parentTables = new ArrayList<>();
private Worksheet groupByTopLevel(Worksheet oldws, Workspace workspace, List<String> hnodeIDs, List<HNode> keyhnodes, List<HNode> valuehnodes, RepFactory factory) { SuperSelection selection = getSuperSelection(oldws); Worksheet newws = factory.createWorksheet("GroupBy: " + oldws.getTitle(), workspace, oldws.getEncoding()); newws.getMetadataContainer().getWorksheetProperties().setPropertyValue(Property.sourceType, oldws.getMetadataContainer().getWorksheetProperties().getPropertyValue(Property.sourceType));