}
@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
RepFactory Repfactory = workspace.getFactory();
Worksheet worksheet = workspace.getWorksheet(
worksheetId);
SuperSelection selection = getSuperSelection(worksheet);
inputColumns.clear();
outputColumns.clear();
Object para = JSONUtil.createJson(this.getInputParameterJson());
HTable htable;
if (hNodeId.compareTo("") != 0)
htable = Repfactory.getHTable(Repfactory.getHNode(hNodeId).getHTableId());
else
htable = worksheet.getHeaders();
hnodes.clear();
//List<String> HNodeIds = new ArrayList<String>();
JSONArray checked = (JSONArray) JSONUtil.createJson(CommandInputJSONUtil.getStringValue("values", (JSONArray)para));
for (int i = 0; i < checked.length(); i++) {
JSONObject t = (checked.getJSONObject(i));
hnodes.add(htable.getHNode((String) t.get("value")));
inputColumns.add(t.getString("value"));
}
ArrayList<Row> rows = worksheet.getDataTable().getRows(0, worksheet.getDataTable().getNumRows(), selection);
if (htable != worksheet.getHeaders()) {
HTable parentHT = htable.getParentHNode().getHTable(Repfactory);
List<Table> parentTables = new ArrayList<Table>();
CloneTableUtils.getDatatable(worksheet.getDataTable(), parentHT,parentTables, selection);
ArrayList<Row> parentRows = new ArrayList<Row>();
rows.clear();
for (Table tmp : parentTables) {
for (Row row : tmp.getRows(0, tmp.getNumRows(), selection)) {
parentRows.add(row);
}
}
for (Row parentRow : parentRows) {
Table t = null;
for (Node node : parentRow.getNodes()) {
if (node.hasNestedTable() && node.getNestedTable().getHTableId().compareTo(htable.getId()) == 0) {
t = node.getNestedTable();
break;
}
}
ArrayList<Row> tmpRows = t.getRows(0, t.getNumRows(), selection);
for (Row r : tmpRows) {
rows.add(r);
}
}
}
//System.out.println("HNodeID: " + htable.getHNodeIdFromColumnName("homeworks"));
//HNodeIds.add(htable.getHNodeIdFromColumnName("homeworks"));
//HashValueManager.getHashValue(rows.get(0), HNodeIds);
//hnodes.add(htable.getHNode("HN5"));
//hnodes.add(htable.getHNode("HN7"));
JSONArray array = new JSONArray();
JSONArray input = new JSONArray();
for (Row row : rows) {
String id = row.getId();
JSONArray t = new JSONArray();
for (HNode hnode : hnodes) {
Node node = row.getNode(hnode.getId());
String name = hnode.getColumnName();
Object value = CloneTableUtils.cloneNodeToJSON(hnode, node, selection);
JSONObject obj = new JSONObject();
JSONObject obj2 = new JSONObject();
if (value instanceof String)
obj2.put("values", value);
else
obj2.put(worksheet.getHeaders().getNewColumnName("nested"), value);
obj.put("values", obj2);
obj.put("names", name);
t.put(obj);
}
JSONObject obj = new JSONObject();
obj.put("rowId", id);
obj.put("rowIdHash", "");
obj.put("values", t);
array.put(obj);
}
JSONObject obj = new JSONObject();
obj.put("name", "AddValues");
obj.put("value", array.toString());
obj.put("type", "other");
input.put(obj);
try{
AddValuesCommandFactory factory = new AddValuesCommandFactory();
//hNodeId = hnodes.get(0).getId();
cmd = factory.createCommand(input, workspace, hNodeId, worksheetId, hTableId, worksheet.getHeaders().getNewColumnName("fold"), HNodeType.Transformation, selection.getName());
cmd.doIt(workspace);
outputColumns.addAll(cmd.getOutputColumns());
WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this);
UpdateContainer c = new UpdateContainer();
c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));