Skip to content

Commit 241f477

Browse files
committed
Fix #1454 Suddenly not importing all of my edges
1 parent 95e5646 commit 241f477

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

modules/DataLaboratoryAPI/src/main/java/org/gephi/datalab/impl/AttributeColumnsControllerImpl.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public boolean setAttributeValue(Object value, Element row, Column column) {
102102
if (value != null && !value.getClass().equals(targetType)) {
103103
try {
104104
GraphModel graphModel = column.getTable().getGraph().getModel();
105-
105+
106106
String stringValue = AttributeUtils.print(value, graphModel.getTimeFormat(), graphModel.getTimeZone());
107107
value = AttributeUtils.parse(stringValue, targetType);//Try to convert to target type from string representation
108108
} catch (Exception ex) {
@@ -691,7 +691,7 @@ public void importCSVToNodesTable(Graph graph, File file, Character separator, C
691691
} finally {
692692
graph.readUnlockAll();
693693
graph.writeUnlock();
694-
694+
695695
if (reader != null) {
696696
reader.close();
697697
}
@@ -838,13 +838,15 @@ public void importCSVToEdgesTable(Graph graph, File file, Character separator, C
838838
}
839839
} else {
840840
edge = graph.getEdge(source, target);
841-
if (edge == null) {
841+
if (edge == null && !directed) {
842842
//Not from source to target but undirected and reverse?
843843
edge = graph.getEdge(target, source);
844-
if (edge != null && edge.isDirected()) {
845-
edge = null;//Cannot use it since it's actually directed
846-
}
847844
}
845+
846+
if (edge != null && edge.isDirected() != directed) {
847+
edge = null;//Cannot use it since directedness is different
848+
}
849+
848850
if (edge != null) {
849851
//Increase non dynamic edge weight with specified weight (if specified), else increase by 1:
850852
if (!isDynamicWeight) {
@@ -856,12 +858,24 @@ public void importCSVToEdgesTable(Graph graph, File file, Character separator, C
856858
} catch (NumberFormatException numberFormatException) {
857859
//Not valid weight, add 1
858860
edge.setWeight(edge.getWeight() + 1);
861+
862+
Logger.getLogger("").log(
863+
Level.WARNING,
864+
"Could not parse weight {0}, adding 1",
865+
weight
866+
);
859867
}
860868
} else {
861869
//Add 1 (weight not specified)
862870
edge.setWeight(edge.getWeight() + 1);
863871
}
864872
}
873+
} else {
874+
Logger.getLogger("").log(
875+
Level.WARNING,
876+
"Could not add edge [source = {0}, target = {1}, directed = {2}] to the graph and could not find the existing edge to add its weight",
877+
new Object[]{source.getId(), target.getId(), directed}
878+
);
865879
}
866880
}
867881
}
@@ -872,7 +886,7 @@ public void importCSVToEdgesTable(Graph graph, File file, Character separator, C
872886
} finally {
873887
graph.readUnlockAll();
874888
graph.writeUnlock();
875-
889+
876890
if (reader != null) {
877891
reader.close();
878892
}
@@ -918,10 +932,10 @@ public List<List<Node>> detectNodeDuplicatesByColumn(Column column, boolean case
918932
Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
919933
Object value;
920934
String strValue;
921-
935+
922936
TimeFormat timeFormat = graph.getModel().getTimeFormat();
923937
DateTimeZone timeZone = graph.getModel().getTimeZone();
924-
938+
925939
for (Node node : graph.getNodes().toArray()) {
926940
value = node.getAttribute(column);
927941
if (value != null) {

modules/DataLaboratoryAPI/src/main/java/org/gephi/datalab/impl/GraphElementsControllerImpl.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Development and Distribution License("CDDL") (collectively, the
4444
import java.util.Arrays;
4545
import java.util.HashSet;
4646
import java.util.Set;
47+
import java.util.logging.Level;
48+
import java.util.logging.Logger;
4749
import org.gephi.datalab.api.AttributeColumnsController;
4850
import org.gephi.datalab.api.GraphElementsController;
4951
import org.gephi.datalab.spi.rows.merge.AttributeRowsMergeStrategy;
@@ -148,22 +150,19 @@ public Edge createEdge(String id, Node source, Node target, boolean directed, Gr
148150

149151
@Override
150152
public Edge createEdge(String id, Node source, Node target, boolean directed, Object typeLabel, Graph graph) {
151-
Edge newEdge;
152-
if (directed) {
153-
newEdge = buildEdge(graph, id, source, target, true, typeLabel);
154-
if (graph.addEdge(newEdge)) {//The edge will be created if it does not already exist.
155-
return newEdge;
156-
} else {
157-
return null;
158-
}
159-
} else {
160-
newEdge = buildEdge(graph, id, source, target, false, typeLabel);
153+
Edge newEdge = buildEdge(graph, id, source, target, directed, typeLabel);
154+
try {
161155
if (graph.addEdge(newEdge)) {//The edge will be created if it does not already exist.
162156
return newEdge;
163-
} else {
164-
return null;
165157
}
158+
} catch (Exception e) {
159+
Logger.getLogger("").log(
160+
Level.SEVERE,
161+
"Error when adding edge [source = {0}, target = {1}, directed = {2}, typeLabel = {3}] to the graph. Exception message: {4}",
162+
new Object[]{source.getId(), target.getId(), directed, typeLabel, e.getMessage()}
163+
);
166164
}
165+
return null;
167166
}
168167

169168
@Override
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Manifest-Version: 1.0
22
AutoUpdate-Essential-Module: true
33
OpenIDE-Module-Localizing-Bundle: org/gephi/datalab/api/Bundle.properties
4-
OpenIDE-Module-Specification-Version: 0.9.1.1
4+
OpenIDE-Module-Specification-Version: 0.9.1.2
55
OpenIDE-Module-Display-Category: Gephi Core
66
OpenIDE-Module-Name: Data Laboratory API

0 commit comments

Comments
 (0)