Author: clopes
Date: 2012-08-08 14:42:52 -0700 (Wed, 08 Aug 2012)
New Revision: 30133
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/CyActivator.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/SUIDUpdater.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/nnf/NNFParser.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy2SessionReaderImpl.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy3SessionReaderImpl.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/sif/SIFNetworkReader.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/ObjectTypeMap.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraphDone.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleListAttribute.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/ReadCache.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/SUIDUpdaterTest.java
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
Log:
Fixed compilation errors and unit tests.
XGMML parser now creates most of the attributes in the shared tables, except
network attributes (not sure about these!) and "selected".
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/CyActivator.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/CyActivator.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/CyActivator.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -189,7 +189,7 @@
UnrecognizedVisualPropertyManager
unrecognizedVisualPropertyManager = new
UnrecognizedVisualPropertyManager(cyTableFactoryServiceRef,cyTableManagerServiceRef);
GMLNetworkReaderFactory gmlNetworkViewReaderFactory = new
GMLNetworkReaderFactory(gmlFilter,cyNetworkViewFactoryServiceRef,cyNetworkFactoryServiceRef,renderingEngineManagerServiceRef,unrecognizedVisualPropertyManager);
- ReadCache readCache = new ReadCache();
+ ReadCache readCache = new
ReadCache(cyNetworkTableManagerServiceRef);
SUIDUpdater suidUpdater = new SUIDUpdater();
ReadDataManager readDataManager = new
ReadDataManager(readCache,suidUpdater,equationCompilerServiceRef,cyNetworkFactoryServiceRef,cyRootNetworkManagerServiceRef);
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/SUIDUpdater.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/SUIDUpdater.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/SUIDUpdater.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -1,12 +1,12 @@
package org.cytoscape.io.internal.read;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.WeakHashMap;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyRow;
@@ -18,10 +18,11 @@
*/
public class SUIDUpdater {
- private static final String SUID_COLUMN_SUFFIX = ".SUID";
+ public static final String SUID_COLUMN_SUFFIX = ".SUID";
private Map<Long/*old SUID*/, Long/*new SUID*/> suidMap;
- private Map<CyTable, Set<String>/*column names*/> suidColumnMap;
+ private Set<CyTable> tables;
+ private Map<CyTable, Set<String>/*column names*/> ignoredColumns;
public SUIDUpdater() {
init();
@@ -29,7 +30,8 @@
public void init() {
suidMap = new HashMap<Long, Long>();
- suidColumnMap = new WeakHashMap<CyTable, Set<String>>();
+ tables = new HashSet<CyTable>();
+ ignoredColumns = new HashMap<CyTable, Set<String>>();
}
public void addSUIDMapping(final Long oldSUID, final Long newSUID) {
@@ -37,46 +39,75 @@
suidMap.put(oldSUID, newSUID);
}
- public Long getNewSUID(final Long oldSUID) {
- return suidMap.get(oldSUID);
+ public void addTable(final CyTable table) {
+ tables.add(table);
}
- public void addSUIDColumn(final CyTable table, final String name) {
- Set<String> columnNames = suidColumnMap.get(table);
+ public void addTables(final Set<CyTable> networkTables) {
+ if (networkTables != null)
+ tables.addAll(networkTables);
+ }
+
+ public void ignoreColumn(final CyTable table, final String columnName) {
+ if (table != null && columnName != null) {
+ Set<String> names = ignoredColumns.get(table);
- if (columnNames == null) {
- columnNames = new HashSet<String>();
- suidColumnMap.put(table, columnNames);
+ if (names == null) {
+ names = new HashSet<String>();
+ ignoredColumns.put(table, names);
+ }
+
+ names.add(columnName);
}
-
- columnNames.add(name);
}
public void updateSUIDColumns() {
- for (final Map.Entry<CyTable, Set<String>> entry :
suidColumnMap.entrySet()) {
- final CyTable tbl = entry.getKey();
- final Set<String> columnNames = entry.getValue();
+ final Set<CyColumn> updated = new HashSet<CyColumn>();
+
+ for (final CyTable tbl : tables) {
+ final Collection<CyColumn> columns = tbl.getColumns();
- for (final String name : columnNames)
- updateRows(tbl, name);
+ for (final CyColumn c : columns) {
+ if (isUpdatableSUIDColumn(c) &&
!updated.contains(c)) {
+ Set<String> ignoredNames =
ignoredColumns.get(tbl);
+
+ if (ignoredNames != null &&
ignoredNames.contains(c.getName()))
+ continue;
+
+ updateRows(tbl, c);
+ updated.add(c);
+ }
+ }
}
}
+ public static boolean isUpdatableSUIDColumn(final CyColumn column) {
+ if (column != null
+ && !column.isPrimaryKey()
+ && !column.getVirtualColumnInfo().isVirtual()
+ && (column.getType() == Long.class ||
+
(Collection.class.isAssignableFrom(column.getType()) &&
+
column.getListElementType() == Long.class)))
+ return isUpdatableSUIDColumnName(column.getName());
+
+ return false;
+ }
+
+ public static boolean isUpdatableSUIDColumnName(final String
columnName) {
+ return columnName != null &&
columnName.endsWith(SUID_COLUMN_SUFFIX);
+ }
+
public void dispose() {
init();
}
- public static boolean isUpdatableSUIDColumn(final String columnName) {
- return columnName != null && columnName.endsWith(SUID_COLUMN_SUFFIX);
- }
-
@Override
public String toString() {
- return "SUIDUpdater{ suidMap=" + suidMap + ", suidColumnMap=" +
suidColumnMap + " }";
+ return "SUIDUpdater{ suidMap=" + suidMap + ", tables=" + tables
+ " }";
}
-
- private void updateRows(final CyTable tbl, final String columnName) {
- final CyColumn column = tbl.getColumn(columnName);
+
+ private void updateRows(final CyTable tbl, final CyColumn column) {
+ final String columnName = column.getName();
final Class<?> type = column.getType();
final Class<?> listType = column.getListElementType();
@@ -87,9 +118,7 @@
if (type == Long.class) {
final Long oldSUID = row.get(columnName,
Long.class);
final Long newSUID = getNewSUID(oldSUID);
-
- if (newSUID != null)
- row.set(columnName, newSUID);
+ row.set(columnName, newSUID);
} else if (type == List.class) {
final List<Long> oldList =
row.getList(columnName, Long.class);
@@ -108,4 +137,8 @@
}
}
}
+
+ private Long getNewSUID(final Long oldSUID) {
+ return suidMap.get(oldSUID);
+ }
}
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/nnf/NNFParser.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/nnf/NNFParser.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/nnf/NNFParser.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -50,7 +50,7 @@
private CyNetwork getNetworkByTitle(final String networkTitle) {
Set<CyNetwork> networks =
this.cyNetworkManagerServiceRef.getNetworkSet();
for (final CyNetwork network : networks) {
- String title =
network.getDefaultNetworkTable().getRow(network).get(CyNetwork.NAME,
String.class);
+ String title =
network.getLocalNetworkTable().getRow(network).get(CyNetwork.NAME,
String.class);
if (title.equals(networkTitle))
return network;
@@ -100,7 +100,7 @@
} else if (length == 4) {
CyNode source = null;
// Check if the source node already existed in the
network
- Collection<CyRow> matchingRows =
network.getDefaultNodeTable().getMatchingRows(CyNetwork.NAME, parts[1]);
+ Collection<CyRow> matchingRows =
network.getLocalNodeTable().getMatchingRows(CyNetwork.NAME, parts[1]);
if (!matchingRows.isEmpty()){
// source node already existed, get it
CyRow row = matchingRows.iterator().next();
@@ -123,7 +123,7 @@
CyNode target = null;
// Check if the target already existed in the network
- Collection<CyRow> matchingRows2 =
network.getDefaultNodeTable().getMatchingRows(CyNetwork.NAME, parts[3]);
+ Collection<CyRow> matchingRows2 =
network.getLocalNodeTable().getMatchingRows(CyNetwork.NAME, parts[3]);
if (!matchingRows2.isEmpty()){
// source node already existed, get it
CyRow row = matchingRows2.iterator().next();
@@ -166,7 +166,7 @@
while (it.hasNext()){
CyNetwork network = networkMap.get(it.next());
- Collection<CyRow> matchingRows =
network.getDefaultNodeTable().getMatchingRows(CyNetwork.NAME, nodeName);
+ Collection<CyRow> matchingRows =
network.getLocalNodeTable().getMatchingRows(CyNetwork.NAME, nodeName);
if (matchingRows.isEmpty()){
continue;
}
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy2SessionReaderImpl.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy2SessionReaderImpl.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy2SessionReaderImpl.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -33,7 +33,7 @@
import static org.cytoscape.io.internal.util.session.SessionUtil.NETWORK_ROOT;
import static
org.cytoscape.io.internal.util.session.SessionUtil.VIZMAP_PROPS_FILE;
import static org.cytoscape.io.internal.util.session.SessionUtil.XGMML_EXT;
-import static org.cytoscape.model.CyNetwork.DEFAULT_ATTRS;
+import static org.cytoscape.model.CyNetwork.LOCAL_ATTRS;
import static org.cytoscape.model.CyNetwork.SELECTED;
import java.io.BufferedInputStream;
@@ -328,9 +328,9 @@
List<Edge> selEdges =
edgeSelectionLookup.get(netName);
if (selNodes != null)
- setBooleanNodeAttr(net, selNodes,
SELECTED, DEFAULT_ATTRS);
+ setBooleanNodeAttr(net, selNodes,
SELECTED, LOCAL_ATTRS);
if (selEdges != null)
- setBooleanEdgeAttr(net, selEdges,
SELECTED, DEFAULT_ATTRS);
+ setBooleanEdgeAttr(net, selEdges,
SELECTED, LOCAL_ATTRS);
networks.add(net);
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy3SessionReaderImpl.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy3SessionReaderImpl.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/session/Cy3SessionReaderImpl.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -300,7 +300,7 @@
builderFilenameMap.put(builder, filename);
// Look for SUID-type columns--only global tables now
- findSUIDColumns(table);
+ suidUpdater.addTable(table);
}
}
@@ -500,12 +500,12 @@
networkTableMgr.setTable(network, type, namespace, src);
builder.setCyTable(src);
- findSUIDColumns(src);
+ suidUpdater.addTable(src);
} else {
mergeTables(src, tgt, type);
builder.setCyTable(tgt);
- findSUIDColumns(tgt);
+ suidUpdater.addTable(tgt);
}
}
@@ -561,13 +561,6 @@
}
}
- private void findSUIDColumns(final CyTable table) {
- for (final CyColumn column : table.getColumns()) {
- if (SUIDUpdater.isUpdatableSUIDColumn(column.getName()))
- suidUpdater.addSUIDColumn(table,
column.getName());
- }
- }
-
private void updateSUIDColumns() {
suidUpdater.updateSUIDColumns();
}
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/sif/SIFNetworkReader.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/sif/SIFNetworkReader.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/sif/SIFNetworkReader.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -41,7 +41,6 @@
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNode;
-import org.cytoscape.model.CyTable;
import org.cytoscape.view.layout.CyLayoutAlgorithm;
import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
import org.cytoscape.view.model.CyNetworkView;
@@ -99,9 +98,6 @@
Map<String, CyNode> nMap = new HashMap<String, CyNode>(10000);
CyNetwork network = cyNetworkFactory.createNetwork();
- final CyTable nodeTable = network.getDefaultNodeTable();
- final CyTable edgeTable = network.getDefaultEdgeTable();
-
tm.setProgress(0.1);
// Generate bundled event to avoid too many events problem.
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/ObjectTypeMap.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/ObjectTypeMap.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/ObjectTypeMap.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -44,7 +44,7 @@
break;
case REAL:
if (value != null) {
- if (SUIDUpdater.isUpdatableSUIDColumn(name))
+ if (SUIDUpdater.isUpdatableSUIDColumnName(name))
typedValue = new Long(value);
else
typedValue = new Double(value);
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -46,6 +46,8 @@
import org.cytoscape.model.CyTable;
import org.cytoscape.model.CyIdentifiable;
import org.cytoscape.model.VirtualColumnInfo;
+import org.cytoscape.model.subnetwork.CyRootNetwork;
+import org.cytoscape.model.subnetwork.CySubNetwork;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
@@ -178,7 +180,6 @@
final String hiddenStr = atts.getValue("cy:hidden");
final boolean isHidden = hiddenStr != null ?
Boolean.parseBoolean(hiddenStr) : false;
- final String tableName = isHidden ? CyNetwork.HIDDEN_ATTRS :
CyNetwork.DEFAULT_ATTRS;
final CyIdentifiable curElement = manager.getCurrentElement();
CyNetwork curNet = manager.getCurrentNetwork();
@@ -193,7 +194,20 @@
curNet = manager.getRootNetwork();
}
- CyRow row = curNet.getRow(curElement, tableName);
+ CyRow row = null;
+
+ if (isHidden) {
+ row = curNet.getRow(curElement, CyNetwork.HIDDEN_ATTRS);
+ } else {
+ // TODO: What are the rules here?
+ // Node/edge attributes are always shared, except
"selected"?
+ // Network name must be local, right? What about other
network attributes?
+ if (CyNetwork.SELECTED.equals(name) || (curElement
instanceof CyNetwork))
+ row = curNet.getRow(curElement,
CyNetwork.LOCAL_ATTRS);
+ else
+ row = curNet.getRow(curElement,
CyNetwork.SHARED_ATTRS);
+ }
+
CyTable table = row.getTable();
CyColumn column = table.getColumn(name);
@@ -251,7 +265,7 @@
break;
case REAL:
if (name != null) {
- if
(SUIDUpdater.isUpdatableSUIDColumn(name))
+ if
(SUIDUpdater.isUpdatableSUIDColumnName(name))
setAttribute(row, name,
Long.class, (Long) value);
else
setAttribute(row, name,
Double.class, (Double) value);
@@ -276,9 +290,6 @@
if (column != null &&
List.class.isAssignableFrom(column.getType()))
row.set(name, null);
- if (SUIDUpdater.isUpdatableSUIDColumn(name))
- manager.getSUIDUpdater().addSUIDColumn(row.getTable(),
name);
-
return ParseState.LIST_ATT;
}
@@ -299,9 +310,6 @@
if (value != null) {
row.set(name, value);
-
- if (SUIDUpdater.isUpdatableSUIDColumn(name))
- manager.getSUIDUpdater().addSUIDColumn(row.getTable(),
name);
}
}
}
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraphDone.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraphDone.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraphDone.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -30,6 +30,7 @@
import java.util.Map;
import java.util.Set;
+import org.cytoscape.io.internal.read.SUIDUpdater;
import org.cytoscape.io.internal.read.xgmml.ParseState;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork;
@@ -144,7 +145,9 @@
private void updateSUIDAttributes() {
if (!manager.isSessionFormat()) {
- manager.getSUIDUpdater().updateSUIDColumns();
+ final SUIDUpdater updater = manager.getSUIDUpdater();
+
updater.addTables(manager.getCache().getNetworkTables());
+ updater.updateSUIDColumns();
}
}
}
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleListAttribute.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleListAttribute.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleListAttribute.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -53,7 +53,7 @@
clazz = Boolean.class;
break;
case REAL:
- clazz = SUIDUpdater.isUpdatableSUIDColumn(name) ? Long.class :
Double.class;
+ clazz = SUIDUpdater.isUpdatableSUIDColumnName(name) ?
Long.class : Double.class;
break;
case INTEGER:
clazz = Integer.class;
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -61,7 +61,10 @@
public class ReadDataManager {
- protected final static String XLINK = "http://www.w3.org/1999/xlink";
+ public static final String GROUP_STATE_ATTRIBUTE = "__groupState";
+ public static final String EXTERNAL_EDGE_ATTRIBUTE =
"__externalEdges.SUID";
+
+ protected static final String XLINK = "http://www.w3.org/1999/xlink";
/* RDF Data */
protected String RDFDate;
@@ -497,18 +500,22 @@
// Check for the group's metadata attribute
final CyRow grhRow = grNet.getRow(grNode,
CyNetwork.HIDDEN_ATTRS);
- if (grhRow.isSet("__groupState")) { // It's a
group!
+ if (grhRow.isSet(GROUP_STATE_ATTRIBUTE)) { //
It's a group!
// Add extra metadata for external
edges, so that the information is not lost
final CyRow rnRow =
getRootNetwork().getRow(grNode, CyNetwork.HIDDEN_ATTRS);
- if
(rnRow.getTable().getColumn("__externalEdges") == null)
-
rnRow.getTable().createListColumn("__externalEdges", String.class, false);
+ if
(rnRow.getTable().getColumn(EXTERNAL_EDGE_ATTRIBUTE) == null) {
+
rnRow.getTable().createListColumn(EXTERNAL_EDGE_ATTRIBUTE, String.class, false);
+ // These are already the new
SUIDs. Let's tell the SUIDUpdater to ignore this column,
+ // in order to prevent it from
replacing the correct list by an empty one.
+
suidUpdater.ignoreColumn(rnRow.getTable(), EXTERNAL_EDGE_ATTRIBUTE);
+ }
- extEdgeIds =
rnRow.getList("__externalEdges", String.class);
+ extEdgeIds =
rnRow.getList(EXTERNAL_EDGE_ATTRIBUTE, String.class);
if (extEdgeIds == null) {
extEdgeIds = new
ArrayList<String>();
- rnRow.set("__externalEdges",
extEdgeIds);
+
rnRow.set(EXTERNAL_EDGE_ATTRIBUTE, extEdgeIds);
}
}
}
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/ReadCache.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/ReadCache.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/main/java/org/cytoscape/io/internal/util/ReadCache.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -28,6 +28,7 @@
package org.cytoscape.io.internal.util;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
@@ -35,7 +36,10 @@
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyIdentifiable;
import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNetworkTableManager;
import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.subnetwork.CySubNetwork;
import org.cytoscape.view.model.CyNetworkView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,8 +62,15 @@
private Map<CyNetwork, Set<Long>> edgeLinkMap;
private Map<CyNode, Object/*network's id*/> networkPointerMap;
+ private final CyNetworkTableManager netTblMgr;
+
private static final Logger logger =
LoggerFactory.getLogger(ReadCache.class);
+
+ public ReadCache(final CyNetworkTableManager netTblMgr) {
+ this.netTblMgr = netTblMgr;
+ }
+
public void init() {
oldIdMap = new HashMap<Long, Object>();
nodeByIdMap = new HashMap<Object, CyNode>();
@@ -197,6 +208,34 @@
return nodeByNameMap;
}
+ public Set<CyTable> getNetworkTables() {
+ final Set<CyTable> tables = new HashSet<CyTable>();
+ final Set<CyNetwork> networks = new HashSet<CyNetwork>();
+ final Class<?>[] types = new Class[] { CyNetwork.class,
CyNode.class, CyEdge.class };
+
+ if (networkByIdMap.values() != null)
+ networks.addAll(networkByIdMap.values());
+
+ for (final CyNetwork n : networks) {
+ for (final Class t : types) {
+ Map<String, CyTable> tabMap =
netTblMgr.getTables(n, t);
+
+ if (tabMap != null)
+ tables.addAll(tabMap.values());
+
+ if (n instanceof CySubNetwork) {
+ // Don't forget the root-network tables.
+ tabMap =
netTblMgr.getTables(((CySubNetwork) n).getRootNetwork(), t);
+
+ if (tabMap != null)
+ tables.addAll(tabMap.values());
+ }
+ }
+ }
+
+ return tables;
+ }
+
public void createNetworkPointers() {
if (networkPointerMap != null) {
// Iterate the rows and recreate the network pointers
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/SUIDUpdaterTest.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/SUIDUpdaterTest.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/SUIDUpdaterTest.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -1,19 +1,155 @@
package org.cytoscape.io.internal.read;
import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyColumnTest;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.VirtualColumnInfo;
import org.junit.Test;
public class SUIDUpdaterTest {
@Test
public void testIsUpdatableSUIDColumn() {
- assertTrue(SUIDUpdater.isUpdatableSUIDColumn("name.SUID"));
- assertFalse(SUIDUpdater.isUpdatableSUIDColumn("name.suid")); //
Case sensitive!
- assertFalse(SUIDUpdater.isUpdatableSUIDColumn("name.Suid"));
- assertFalse(SUIDUpdater.isUpdatableSUIDColumn("name.id"));
- assertFalse(SUIDUpdater.isUpdatableSUIDColumn("SUID"));
- assertFalse(SUIDUpdater.isUpdatableSUIDColumn("suid"));
- assertFalse(SUIDUpdater.isUpdatableSUIDColumn(""));
- assertFalse(SUIDUpdater.isUpdatableSUIDColumn(null));
+
assertTrue(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.SUID", Long.class,
false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.SUID",
Integer.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.SUID",
Double.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.SUID",
String.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.SUID",
Boolean.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.SUID",
Long.class, true, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.SUID",
Long.class, false, true)));
+
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.suid",
Long.class, false, false))); // Case sensitive!
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.Suid",
Long.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("name.id", Long.class,
false, false)));
+ assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("SUID",
Long.class, false, false)));
+ assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("suid",
Long.class, false, false)));
+ assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn("",
Long.class, false, false)));
+ assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newColumn(null,
Long.class, false, false)));
+
+ // List column
+
assertTrue(SUIDUpdater.isUpdatableSUIDColumn(newListColumn("list.SUID",
Long.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newListColumn("list.SUID",
Integer.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newListColumn("list.SUID",
Double.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newListColumn("list.SUID",
String.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newListColumn("list.SUID",
Boolean.class, false, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newListColumn("list.SUID",
Long.class, true, false)));
+
assertFalse(SUIDUpdater.isUpdatableSUIDColumn(newListColumn("list.SUID",
Long.class, false, true)));
}
+
+ private CyColumn newColumn(final String name, final Class<?> type,
final boolean isPK, final boolean isVirtual) {
+ return new DummyColumn(name, type, null, isPK, new
DummyVirtualColumnInfo(isVirtual));
+ }
+
+ private CyColumn newListColumn(final String name, final Class<?> type,
final boolean isPK, final boolean isVirtual) {
+ return new DummyColumn(name, List.class, type, isPK, new
DummyVirtualColumnInfo(isVirtual));
+ }
+
+ static class DummyColumn implements CyColumn {
+ private String name;
+ private Class<?> type;
+ private Class<?> listType;
+ private boolean isPK;
+ private VirtualColumnInfo virtualInfo;
+
+ public DummyColumn(String name, Class<?> type, Class<?>
listType, boolean isPK, VirtualColumnInfo virtualInfo) {
+ this.name = name;
+ this.type = type;
+ this.listType = listType;
+ this.isPK = isPK;
+ this.virtualInfo = virtualInfo;
+ }
+
+ @Override
+ public void setName(String newName) {
+ this.name = newName;
+ }
+
+ @Override
+ public boolean isPrimaryKey() {
+ return isPK;
+ }
+
+ @Override
+ public boolean isImmutable() {
+ return false;
+ }
+
+ @Override
+ public VirtualColumnInfo getVirtualColumnInfo() {
+ return virtualInfo;
+ }
+
+ @Override
+ public <T> List<T> getValues(Class<? extends T> type) {
+ return null;
+ }
+
+ @Override
+ public Class<?> getType() {
+ return type;
+ }
+
+ @Override
+ public CyTable getTable() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Class<?> getListElementType() {
+ return listType;
+ }
+
+ @Override
+ public Object getDefaultValue() {
+ return null;
+ }
+ };
+
+ private static class DummyVirtualColumnInfo implements
VirtualColumnInfo {
+
+ private final boolean isVirtual;
+
+ public DummyVirtualColumnInfo(boolean isVirtual) {
+ this.isVirtual = isVirtual;
+ }
+
+ @Override
+ public boolean isVirtual() {
+ return isVirtual;
+ }
+
+ @Override
+ public String getSourceColumn() {
+ return null;
+ }
+
+ @Override
+ public String getSourceJoinKey() {
+ return null;
+ }
+
+ @Override
+ public String getTargetJoinKey() {
+ return null;
+ }
+
+ @Override
+ public CyTable getSourceTable() {
+ return null;
+ }
+
+ @Override
+ public boolean isImmutable() {
+ return false;
+ }
+ }
}
Modified:
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
===================================================================
---
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
2012-08-08 21:42:50 UTC (rev 30132)
+++
csplugins/trunk/toronto/jm/cy3-shared-tables/impl/io-impl/impl/src/test/java/org/cytoscape/io/internal/read/xgmml/GenericXGMMLReaderTest.java
2012-08-08 21:42:52 UTC (rev 30133)
@@ -22,6 +22,7 @@
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkFactory;
+import org.cytoscape.model.CyNetworkTableManager;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
@@ -44,6 +45,7 @@
CyNetworkViewFactory networkViewFactory;
CyNetworkFactory networkFactory;
CyRootNetworkManager rootNetworkMgr;
+ CyNetworkTableManager netTablMgr;
CyTableFactory tableFactory;
RenderingEngineManager renderingEngineMgr;
ReadDataManager readDataMgr;
@@ -70,8 +72,9 @@
NetworkViewTestSupport networkViewTestSupport = new
NetworkViewTestSupport();
networkViewFactory =
networkViewTestSupport.getNetworkViewFactory();
+ netTablMgr = networkTestSupport.getNetworkTableManager();
- readCache = new ReadCache();
+ readCache = new ReadCache(netTablMgr);
suidUpdater = new SUIDUpdater();
readDataMgr = new ReadDataManager(readCache, suidUpdater,
mock(EquationCompiler.class), networkFactory, rootNetworkMgr);
@@ -98,7 +101,7 @@
List<CyNetworkView> views = getViews("listAtt.xgmml");
CyNetwork net = checkSingleNetwork(views, 0, 0);
// The column should not be created, because the List type is
not known
-
assertNull(net.getDefaultNetworkTable().getColumn("empty_list"));
+ assertNull(net.getSharedNetworkTable().getColumn("empty_list"));
}
@Test
@@ -123,19 +126,19 @@
CyNetwork net = checkSingleNetwork(views, 2, 1);
// Test CyTables
- CyTable defNetTbl = net.getDefaultNetworkTable();
+ CyTable defNetTbl = net.getLocalNetworkTable();
assertNotNull(defNetTbl.getColumn("test"));
CyTable hiddenNetTbl = net.getRow(net, HIDDEN_ATTRS).getTable();
assertNotNull(hiddenNetTbl.getColumn("_private_int"));
- CyTable defNodeTbl = net.getDefaultNodeTable();
+ CyTable defNodeTbl = net.getSharedNodeTable();
assertNotNull(defNodeTbl.getColumn("name"));
assertNotNull(defNodeTbl.getColumn("list_1"));
CyTable hiddenNodeTbl = net.getRow(net.getNodeList().get(0),
HIDDEN_ATTRS).getTable();
assertNotNull(hiddenNodeTbl.getColumn("_private_str"));
assertNotNull(hiddenNodeTbl.getColumn("_private_list"));
- CyTable defEdgeTbl = net.getDefaultEdgeTable();
+ CyTable defEdgeTbl = net.getSharedEdgeTable();
assertNotNull(defEdgeTbl.getColumn("name"));
CyTable hiddenEdgeTbl = net.getRow(net.getEdgeList().get(0),
HIDDEN_ATTRS).getTable();
assertNotNull(hiddenEdgeTbl.getColumn("_private_real"));
@@ -168,14 +171,14 @@
assertEquals(nodes.get(1).getSUID(), net.getRow(nodes.get(0),
HIDDEN_ATTRS).get("other_node.SUID", Long.class));
assertEquals(nodes.get(0).getSUID(), net.getRow(nodes.get(1),
HIDDEN_ATTRS).get("other_node.SUID", Long.class));
// User List att
- List<Long> nodeAttList =
net.getRow(nodes.get(1)).getList("edges.SUID", Long.class);
+ List<Long> nodeAttList = net.getRow(nodes.get(1),
SHARED_ATTRS).getList("edges.SUID", Long.class);
assertEquals(2, nodeAttList.size());
assertTrue(nodeAttList.contains(edges.get(0).getSUID()));
assertTrue(nodeAttList.contains(edges.get(1).getSUID()));
// Check edge attributes
- assertEquals(edges.get(0).getSource().getSUID(),
net.getRow(edges.get(0)).get("source_node.SUID", Long.class));
- assertEquals(edges.get(1).getSource().getSUID(),
net.getRow(edges.get(1)).get("source_node.SUID", Long.class));
+ assertEquals(edges.get(0).getSource().getSUID(),
net.getRow(edges.get(0), SHARED_ATTRS).get("source_node.SUID", Long.class));
+ assertEquals(edges.get(1).getSource().getSUID(),
net.getRow(edges.get(1), SHARED_ATTRS).get("source_node.SUID", Long.class));
}
@Test
@@ -279,11 +282,11 @@
private void assertCustomColumnsAreMutable(CyNetwork net) {
// User or non-default columns should be immutable
CyTable[] tables = new CyTable[] {
- net.getTable(CyNetwork.class, DEFAULT_ATTRS),
+ net.getTable(CyNetwork.class, LOCAL_ATTRS),
net.getTable(CyNetwork.class, HIDDEN_ATTRS),
- net.getTable(CyNode.class, DEFAULT_ATTRS),
+ net.getTable(CyNode.class, LOCAL_ATTRS),
net.getTable(CyNode.class, HIDDEN_ATTRS),
- net.getTable(CyEdge.class, DEFAULT_ATTRS),
+ net.getTable(CyEdge.class, LOCAL_ATTRS),
net.getTable(CyEdge.class, HIDDEN_ATTRS)
};
for (CyTable t : tables) {
@@ -304,7 +307,7 @@
int npCount = 0;
for (CyNode n : net.getNodeList()) {
- if (net.getRow(n,
CyNetwork.HIDDEN_ATTRS).isSet("__groupState")) {
+ if (net.getRow(n,
CyNetwork.HIDDEN_ATTRS).isSet(ReadDataManager.GROUP_STATE_ATTRIBUTE)) {
gn = n;
if (++npCount > 1) fail("There should be only
one group node!");
} else { // The other nodes have no network pointer!
@@ -325,7 +328,7 @@
// Check external edges metadata (must be added by the reader!)
CyRootNetwork rootNet = rootNetworkMgr.getRootNetwork(np);
CyRow rnRow = rootNet.getRow(gn, HIDDEN_ATTRS);
- List<String> extEdgeIds = rnRow.getList("__externalEdges",
String.class);
+ List<String> extEdgeIds =
rnRow.getList(ReadDataManager.EXTERNAL_EDGE_ATTRIBUTE, String.class);
assertNotNull(extEdgeIds);
assertEquals(1, extEdgeIds.size());
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.