diff --git a/karma-commands/commands-worksheet/src/main/java/edu/isi/karma/controller/command/worksheet/GlueCommand.java b/karma-commands/commands-worksheet/src/main/java/edu/isi/karma/controller/command/worksheet/GlueCommand.java index ed7ddeb31..317f71cb0 100644 --- a/karma-commands/commands-worksheet/src/main/java/edu/isi/karma/controller/command/worksheet/GlueCommand.java +++ b/karma-commands/commands-worksheet/src/main/java/edu/isi/karma/controller/command/worksheet/GlueCommand.java @@ -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; @@ -129,7 +128,7 @@ private void glueNestedTable(Worksheet oldws, Workspace workspace, HTable ht, Li } } } - CloneTableUtils.cloneHTable(ht, newht, oldws, factory, childHNodes); + Map mapping = CloneTableUtils.cloneHTable(ht, newht, oldws, factory, childHNodes, true); for (Row parentRow : parentRows) { Table t = null; @@ -142,13 +141,25 @@ private void glueNestedTable(Worksheet oldws, Workspace workspace, HTable ht, Li ArrayList 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 newRows = new ArrayList(); + 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++; } } } @@ -168,17 +179,30 @@ private void glueTopLevel(Worksheet oldws, Workspace workspace, List hnod } } } - CloneTableUtils.cloneHTable(oldws.getHeaders(), newht, oldws, factory, childHNodes); + Map mapping = CloneTableUtils.cloneHTable(oldws.getHeaders(), newht, oldws, factory, childHNodes, true); ArrayList 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 newRows = new ArrayList(); + 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++; } } } diff --git a/karma-common/src/main/java/edu/isi/karma/er/helper/CloneTableUtils.java b/karma-common/src/main/java/edu/isi/karma/er/helper/CloneTableUtils.java index 94b00257f..74ed4e237 100644 --- a/karma-common/src/main/java/edu/isi/karma/er/helper/CloneTableUtils.java +++ b/karma-common/src/main/java/edu/isi/karma/er/helper/CloneTableUtils.java @@ -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; @@ -28,6 +26,21 @@ public static void cloneHTable(HTable oldht, HTable newht, Worksheet newws, RepF } } } + + public static Map cloneHTable(HTable oldht, HTable newht, Worksheet newws, RepFactory factory, List hnodes, boolean isFirst) { + Collections.sort(hnodes); + Map tmp = new HashMap(); + 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(oldnested.getHNodes()), false); + } + } + return tmp; + } public static Row cloneDataTable(Row oldRow, Table newDataTable, HTable oldHTable, HTable newHTable, List hnodes, RepFactory factory) { Row newrow = newDataTable.addRow(factory); @@ -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 hnodes, RepFactory factory) { + public static void cloneDataTableExistingRow(Row oldRow, Row newRow, Table newDataTable, HTable oldHTable, HTable newHTable, List hnodes, RepFactory factory, Map 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); } diff --git a/karma-web/external_webapps/cleaningService.war b/karma-web/external_webapps/cleaningService.war index f1cdc425f..b58a2356d 100644 Binary files a/karma-web/external_webapps/cleaningService.war and b/karma-web/external_webapps/cleaningService.war differ diff --git a/karma-web/src/main/webapp/version.jsp b/karma-web/src/main/webapp/version.jsp index 3e48fda6d..837d38ae0 100644 --- a/karma-web/src/main/webapp/version.jsp +++ b/karma-web/src/main/webapp/version.jsp @@ -1 +1 @@ -v2.012 +v2.013