public Command createCommand(JSONArray inputJson, String model, Workspace workspace, String hNodeID, String worksheetId, String hTableId, HNodeType type, String selectionId) throws JSONException, KarmaException { AddValuesCommand valCmd = new AddValuesCommand(getNewId(workspace), model, worksheetId, hTableId, hNodeID, type, selectionId); valCmd.setInputParameterJson(inputJson.toString()); valCmd.setColumnName(""); return valCmd; }
private boolean addJSONArrayValues(JSONArray array, Worksheet worksheet, HTable htable, RepFactory factory, Row row, String newHNodeId) { boolean flag = false; for (int i = 0; i < array.length(); i++) { JSONObject obj = (JSONObject)array.get(i); flag |= addJSONObjectValues(obj, worksheet, htable, factory, row, newHNodeId); } return flag; }
protected AddValuesCommand(String id, String model, String worksheetId, String hTableId, String hNodeId, HNodeType type, String selectionId) { super(id, model, worksheetId, selectionId); this.hNodeId = hNodeId; this.hTableId = hTableId; isNewNode = false; this.type = type; addTag(CommandTag.Transformation); }
AddValuesCommand command = (AddValuesCommand) addFactory.createCommand(input, model, workspace, hNodeId, worksheetId, hnode.getHTableId(), label.getDisplayName(), HNodeType.AugmentData, selection.getName()); command.doIt(workspace); outputColumns.addAll(command.getOutputColumns()); isNewNode |= command.isNewNode(); if (command.isNewNode()) appliedCommands.push(command); newhNodeId = command.getNewHNodeId();
cmd.setColumnName(hnode.getColumnName()+" Extractions"); cmd.doIt(workspace); newHNodeId = cmd.getNewHNodeId();
inputColumns.clear(); outputColumns.clear(); Object para = JSONUtil.createJson(this.getInputParameterJson()); String addValues; HNode ndid = null; if (t instanceof JSONArray) { JSONArray a = (JSONArray) t; ndid = addColumn(workspace, worksheet, newColumnName, a); c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet), workspace.getContextId())); if (ndid == null) { System.err.println("error: ndid"); c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace)); return c; } catch (Exception e) {
private void populateRowsWithDefaultValues(Worksheet worksheet, RepFactory factory, JSONArray array, HTable htable) { SuperSelection selection = getSuperSelection(worksheet); HNodePath selectedPath = null; List<HNodePath> columnPaths = worksheet.getHeaders().getAllPaths(); if (t instanceof String) { String value = (String)t; addValues(node, value, factory, null); addJSONObjectValues((JSONObject)t, worksheet, htable, factory, node.getBelongsToRow(), newHNodeId); addJSONArrayValues((JSONArray)t, worksheet, htable, factory, node.getBelongsToRow(), newHNodeId);
input.put(obj3); AddValuesCommand command = (AddValuesCommand) addFactory.createCommand(input, model, workspace, hNodeId, worksheetId, newNode.getHTableId(), name, HNodeType.Transformation, getSuperSelection(workspace).getName()); command.doIt(workspace);
private boolean addJSONObjectValues(JSONObject obj, Worksheet worksheet, HTable htable, RepFactory factory, Row row, String newHNodeId) { HNode ndid = htable.getHNode(newHNodeId); HTable nestedHTable = ndid.getNestedTable(); if (nestedHTable == null) nestedHTable = ndid.addNestedTable("Table for test", worksheet, factory); Table nestedTable = row.getNode(newHNodeId).getNestedTable(); Row r = nestedTable.addRow(factory); boolean flag = false; for (Object key : IteratorUtils.toList(obj.keys())) { Object value = obj.get(key.toString()); HNode h = nestedHTable.getHNodeFromColumnName(key.toString()); if ( h == null) { h = nestedHTable.addHNode(key.toString(), type, worksheet, factory); } outputColumns.add(h.getId()); // if (value instanceof String) flag |= addValues(r.getNode(h.getId()), (String)value, factory, nestedTable); if (value instanceof JSONObject) flag |= addJSONObjectValues((JSONObject)value, worksheet, nestedHTable, factory, r, h.getId()); if (value instanceof JSONArray) flag |= addJSONArrayValues((JSONArray) value, worksheet, nestedHTable, factory,r, h.getId()); } if (!flag) nestedTable.removeRow(r); return flag; }
@Override public Command createCommand(JSONArray inputJson, String model, Workspace workspace) throws JSONException, KarmaException { String hNodeID = CommandInputJSONUtil.getStringValue(Arguments.hNodeId.name(), inputJson); String worksheetId = CommandInputJSONUtil.getStringValue(Arguments.worksheetId.name(), inputJson); String hTableId = CommandInputJSONUtil.getStringValue(Arguments.hTableId.name(), inputJson); this.normalizeSelectionId(worksheetId, inputJson, workspace); String selectionName = CommandInputJSONUtil.getStringValue(Arguments.selectionName.name(), inputJson); AddValuesCommand valCmd = new AddValuesCommand(getNewId(workspace), model, worksheetId, hTableId, hNodeID, HNodeType.Transformation, selectionName); valCmd.setInputParameterJson(inputJson.toString()); return valCmd; }
@Override public UpdateContainer undoIt(Workspace workspace) { UpdateContainer c = new UpdateContainer(); Worksheet worksheet = workspace.getWorksheet(worksheetId); HTable currentTable = workspace.getFactory().getHTable(hTableId); HNode ndid = workspace.getFactory().getHNode(newHNodeId); 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; }
@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 AddValuesCommand(getNewId(workspace), Command.NEW_MODEL, worksheetId, hTableId, hNodeId, HNodeType.Transformation, selectionName); }
public Command createCommand(JSONArray inputJson, String model, Workspace workspace, String hNodeID, String worksheetId, String hTableId, String newColumnName, HNodeType type, String selectionId) throws JSONException, KarmaException { AddValuesCommand valCmd = new AddValuesCommand(getNewId(workspace), model, worksheetId, hTableId, hNodeID, type, selectionId); valCmd.setInputParameterJson(inputJson.toString()); valCmd.setColumnName(newColumnName); return valCmd; }