Skip to content

Commit

Permalink
Fix #1418 import spreadsheet (csv) The id class does not match with t…
Browse files Browse the repository at this point in the history
…he expected type
  • Loading branch information
eduramiba committed Nov 6, 2016
1 parent 4a5895e commit 95bec4b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public void readRows(XMLStreamReader reader, GraphModel graphModel, LegacyMapHel
case XMLStreamReader.START_ELEMENT:
String name = reader.getLocalName();
if (ELEMENT_NODE_ROW.equalsIgnoreCase(name)) {
int id = Integer.parseInt(reader.getAttributeValue(null, "for"));
String id = reader.getAttributeValue(null, "for");
Node node = graph.getNode(id);

readRow(reader, node, graphModel.getNodeTable(), mapHelper);
} else if (ELEMENT_EDGE_ROW.equalsIgnoreCase(name)) {
int id = Integer.parseInt(reader.getAttributeValue(null, "for"));
String id = reader.getAttributeValue(null, "for");
Edge edge = graph.getEdge(id);

readRow(reader, edge, graphModel.getEdgeTable(), mapHelper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public void readData(XMLStreamReader reader, GraphModel graphModel, LegacyMapHel
if (eventType.equals(XMLEvent.START_ELEMENT)) {
String name = reader.getLocalName();
if (ELEMENT_NODEDATA.equalsIgnoreCase(name)) {
Node node = graph.getNode(helper.preToIdMap.get(Integer.parseInt(reader.getAttributeValue(null, "nodepre"))));
Node node = graph.getNode(helper.preToIdMap.get(reader.getAttributeValue(null, "nodepre")));
readNodeData(reader, node);
} else if (ELEMENT_EDGEDATA.equalsIgnoreCase(name)) {
Node source = graph.getNode(helper.preToIdMap.get(Integer.parseInt(reader.getAttributeValue(null, "sourcepre"))));
Node target = graph.getNode(helper.preToIdMap.get(Integer.parseInt(reader.getAttributeValue(null, "targetpre"))));
Node source = graph.getNode(helper.preToIdMap.get(reader.getAttributeValue(null, "sourcepre")));
Node target = graph.getNode(helper.preToIdMap.get(reader.getAttributeValue(null, "targetpre")));
Edge edge = graph.getEdge(source, target, 0);
readEdgeData(reader, edge);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public void readTreeStructure(XMLStreamReader reader, GraphModel graphModel, Gra
case XMLStreamReader.START_ELEMENT:
String name = reader.getLocalName();
if (ELEMENT_TREESTRUCTURE_NODE.equalsIgnoreCase(name)) {
int id = Integer.parseInt(reader.getAttributeValue(null, "id"));
int pre = Integer.parseInt(reader.getAttributeValue(null, "pre"));
String id = reader.getAttributeValue(null, "id");
String pre = reader.getAttributeValue(null, "pre");
mapHelper.preToIdMap.put(pre, id);

Node node = factory.newNode(id);
Expand All @@ -142,28 +142,31 @@ public void readEdges(XMLStreamReader reader, GraphModel graphModel, GraphFactor

switch (type) {
case XMLStreamReader.START_ELEMENT:
String name = reader.getLocalName();

Integer source = 0;
Integer target = 0;
Integer id = 0;
String source = null;
String target = null;
String id = null;
Boolean directed = false;
Float weight = 0f;

for (int i = 0; i < reader.getAttributeCount(); i++) {
String attName = reader.getAttributeName(i).getLocalPart();
if ("id".equalsIgnoreCase(attName)) {
id = Integer.parseInt(reader.getAttributeValue(i));
id = reader.getAttributeValue(i);
} else if ("source".equalsIgnoreCase(attName)) {
source = Integer.parseInt(reader.getAttributeValue(i));
source = reader.getAttributeValue(i);
} else if ("target".equalsIgnoreCase(attName)) {
target = Integer.parseInt(reader.getAttributeValue(i));
target = reader.getAttributeValue(i);
} else if ("directed".equalsIgnoreCase(attName)) {
directed = Boolean.parseBoolean(reader.getAttributeValue(i));
} else if ("weight".equalsIgnoreCase(attName)) {
weight = Float.parseFloat(reader.getAttributeValue(i));
}
}

if (source == null || target == null || id == null) {
throw new IllegalArgumentException("source, target or id cannot be null");
}

Node srcNode = graph.getNode(mapHelper.preToIdMap.get(source));
Node destNode = graph.getNode(mapHelper.preToIdMap.get(target));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class LegacyMapHelper {

protected Map<Integer, String> nodeIndexToIds = new HashMap<>();
protected Map<Integer, String> edgeIndexToIds = new HashMap<>();
protected Map<Integer, Integer> preToIdMap = new HashMap<>();
protected Map<String, String> preToIdMap = new HashMap<>();

protected static LegacyMapHelper get(Workspace workspace) {
LegacyMapHelper lh = workspace.getLookup().lookup(LegacyMapHelper.class);
Expand All @@ -35,8 +35,6 @@ protected static GraphModel getGraphModel(Workspace workspace) {
GraphModel gm = workspace.getLookup().lookup(GraphModel.class);
if (gm == null) {
Configuration configuration = new Configuration();
configuration.setNodeIdType(Integer.class);
configuration.setEdgeIdType(Integer.class);
configuration.setTimeRepresentation(TimeRepresentation.INTERVAL);

gm = GraphModel.Factory.newInstance(configuration);
Expand Down
2 changes: 1 addition & 1 deletion modules/GraphAPI/src/main/nbm/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module-Localizing-Bundle: org/gephi/graph/api/Bundle.properties
AutoUpdate-Essential-Module: true
OpenIDE-Module-Specification-Version: ${gephi.modules.specification.version}
OpenIDE-Module-Specification-Version: 0.9.1.1
OpenIDE-Module-Display-Category: Gephi Core
OpenIDE-Module-Name: Graph API

0 comments on commit 95bec4b

Please sign in to comment.