Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
dkapoor committed Jun 6, 2014
2 parents dfd2212 + 3b55c7c commit fa32d3a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -129,7 +128,7 @@ private void glueNestedTable(Worksheet oldws, Workspace workspace, HTable ht, Li
}
}
}
CloneTableUtils.cloneHTable(ht, newht, oldws, factory, childHNodes);
Map<String, String> mapping = CloneTableUtils.cloneHTable(ht, newht, oldws, factory, childHNodes, true);

for (Row parentRow : parentRows) {
Table t = null;
Expand All @@ -142,13 +141,25 @@ private void glueNestedTable(Worksheet oldws, Workspace workspace, HTable ht, Li
ArrayList<Row> rows = t.getRows(0, t.getNumRows());
for (Row row : rows) {
Table nestedTable = row.getNeighbor(newNode.getId()).getNestedTable();
Row newRow = nestedTable.addRow(factory);
int max = 0;
for (HNode hnode : hnodes) {
if (!hnode.hasNestedTable())
continue;
Node tmp = row.getNeighbor(hnode.getId());
if (tmp.getNestedTable().getNumRows() > max)
max = tmp.getNestedTable().getNumRows();
}
List<Row> newRows = new ArrayList<Row>();
for (int i = 0; i < max; i++)
newRows.add(nestedTable.addRow(factory));
for (HNode hnode : hnodes) {
if (!hnode.hasNestedTable())
continue;
Node tmp = row.getNeighbor(hnode.getId());
int i = 0;
for (Row nestedRow : tmp.getNestedTable().getRows(0, tmp.getNestedTable().getNumRows())) {
CloneTableUtils.cloneDataTableExistingRow(nestedRow, newRow, nestedTable, hnode.getNestedTable(), newht, childHNodes, factory);
CloneTableUtils.cloneDataTableExistingRow(nestedRow, newRows.get(i), nestedTable, hnode.getNestedTable(), newht, childHNodes, factory, mapping);
i++;
}
}
}
Expand All @@ -168,17 +179,30 @@ private void glueTopLevel(Worksheet oldws, Workspace workspace, List<HNode> hnod
}
}
}
CloneTableUtils.cloneHTable(oldws.getHeaders(), newht, oldws, factory, childHNodes);
Map<String, String> mapping = CloneTableUtils.cloneHTable(oldws.getHeaders(), newht, oldws, factory, childHNodes, true);
ArrayList<Row> rows = oldws.getDataTable().getRows(0, oldws.getDataTable().getNumRows());
for (Row row : rows) {
Table nestedTable = row.getNeighbor(newNode.getId()).getNestedTable();
Row newRow = nestedTable.addRow(factory);
int max = 0;
for (HNode hnode : hnodes) {
if (!hnode.hasNestedTable())
continue;
Node tmp = row.getNeighbor(hnode.getId());
if (tmp.getNestedTable().getNumRows() > max) {
max = tmp.getNestedTable().getNumRows();
}
}
List<Row> newRows = new ArrayList<Row>();
for (int i = 0; i < max; i++)
newRows.add(nestedTable.addRow(factory));
for (HNode hnode : hnodes) {
if (!hnode.hasNestedTable())
continue;
Node tmp = row.getNeighbor(hnode.getId());
int i = 0;
for (Row nestedRow : tmp.getNestedTable().getRows(0, tmp.getNestedTable().getNumRows())) {
CloneTableUtils.cloneDataTableExistingRow(nestedRow, newRow, nestedTable, hnode.getNestedTable(), newht, childHNodes, factory);
CloneTableUtils.cloneDataTableExistingRow(nestedRow, newRows.get(i), nestedTable, hnode.getNestedTable(), newht, childHNodes, factory, mapping);
i++;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package edu.isi.karma.er.helper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;

import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -28,6 +26,21 @@ public static void cloneHTable(HTable oldht, HTable newht, Worksheet newws, RepF
}
}
}

public static Map<String, String> cloneHTable(HTable oldht, HTable newht, Worksheet newws, RepFactory factory, List<HNode> hnodes, boolean isFirst) {
Collections.sort(hnodes);
Map<String, String> tmp = new HashMap<String, String>();
for (HNode hnode : hnodes) {
HNode newhnode = newht.addHNode(hnode.getColumnName(), newws, factory);
tmp.put(hnode.getId(), newhnode.getId());
if (hnode.hasNestedTable()) {
HTable oldnested = hnode.getNestedTable();
HTable newnested = newhnode.addNestedTable(hnode.getNestedTable().getTableName(), newws, factory);
cloneHTable(oldnested, newnested, newws, factory, new ArrayList<HNode>(oldnested.getHNodes()), false);
}
}
return tmp;
}

public static Row cloneDataTable(Row oldRow, Table newDataTable, HTable oldHTable, HTable newHTable, List<HNode> hnodes, RepFactory factory) {
Row newrow = newDataTable.addRow(factory);
Expand All @@ -51,21 +64,13 @@ public static Row cloneDataTable(Row oldRow, Table newDataTable, HTable oldHTabl
return newrow;
}

public static void cloneDataTableExistingRow(Row oldRow, Row newRow, Table newDataTable, HTable oldHTable, HTable newHTable, List<HNode> hnodes, RepFactory factory) {
public static void cloneDataTableExistingRow(Row oldRow, Row newRow, Table newDataTable, HTable oldHTable, HTable newHTable, List<HNode> hnodes, RepFactory factory, Map<String, String> mapping) {
for (HNode hnode : hnodes) {
HNode newHNode = null;
HNode newHNode = factory.getHNode(mapping.get(hnode.getId()));
Node oldNode = oldRow.getNode(hnode.getId());
Node newNode = null;
for (HNode hn : newHTable.getHNodes()) {
if (hn.getColumnName().compareTo(hnode.getColumnName()) == 0 && !newRow.getNode(hn.getId()).hasNestedTable() && newRow.getNode(hn.getId()).getValue().asString().compareTo("") == 0) {
newHNode = hn;
newNode = newRow.getNode(hn.getId());
}
}
Node newNode = newRow.getNode(newHNode.getId());
if (oldNode == null)
continue;
if (newHNode == null)
continue;
if (!oldNode.hasNestedTable()) {
newNode.setValue(oldNode.getValue(), oldNode.getStatus(), factory);
}
Expand Down
Binary file modified karma-web/external_webapps/cleaningService.war
Binary file not shown.
2 changes: 1 addition & 1 deletion karma-web/src/main/webapp/version.jsp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.012
v2.013

0 comments on commit fa32d3a

Please sign in to comment.