Skip to content

Commit 8971800

Browse files
committed
First working version with a GUI
1 parent 1ef53c1 commit 8971800

26 files changed

Lines changed: 3101 additions & 624 deletions

modules/Neo4jPlugin/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
This plugin allows you to import a network from Neo4j database 4.X.
44

5-
Three modes are available :
5+
Two modes are availables :
66

7-
- Import the full database
87
- Import just a set of node labels and relationship types
98
- Import by specifying a query for nodes and edges
109

Binary file not shown.

modules/Neo4jPlugin/pom.xml

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>gephi-plugin-parent</artifactId>
77
<groupId>org.gephi</groupId>
8-
<version>0.9.3</version>
8+
<version>0.9.5</version>
99
</parent>
1010

1111
<groupId>ouestware</groupId>
@@ -21,31 +21,73 @@
2121
</properties>
2222

2323
<dependencies>
24+
<!-- Gephi dependencies -->
2425
<dependency>
25-
<groupId>org.neo4j.driver</groupId>
26-
<artifactId>neo4j-java-driver</artifactId>
27-
<version>${neo4j.driver.version}</version>
26+
<groupId>org.netbeans.api</groupId>
27+
<artifactId>org-openide-dialogs</artifactId>
2828
</dependency>
2929
<dependency>
30-
<groupId>io.reactivex.rxjava2</groupId>
31-
<artifactId>rxjava</artifactId>
32-
<version>${rxjava.version}</version>
30+
<groupId>org.netbeans.api</groupId>
31+
<artifactId>org-openide-awt</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.gephi</groupId>
35+
<artifactId>core-library-wrapper</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.netbeans.api</groupId>
39+
<artifactId>org-openide-util-lookup</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.gephi</groupId>
43+
<artifactId>graph-api</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.netbeans.api</groupId>
47+
<artifactId>org-openide-io</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.netbeans.api</groupId>
51+
<artifactId>org-openide-util</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.netbeans.api</groupId>
55+
<artifactId>org-openide-util-ui</artifactId>
3356
</dependency>
3457
<dependency>
3558
<groupId>org.gephi</groupId>
3659
<artifactId>io-importer-api</artifactId>
37-
<scope>provided</scope>
60+
<exclusions>
61+
<exclusion>
62+
<groupId>org.gephi</groupId>
63+
<artifactId>db-drivers</artifactId>
64+
</exclusion>
65+
</exclusions>
3866
</dependency>
3967
<dependency>
4068
<groupId>org.gephi</groupId>
41-
<artifactId>desktop-import</artifactId>
42-
<scope>provided</scope>
69+
<artifactId>project-api</artifactId>
4370
</dependency>
4471
<dependency>
4572
<groupId>org.gephi</groupId>
4673
<artifactId>utils-longtask</artifactId>
47-
<scope>provided</scope>
4874
</dependency>
75+
<dependency>
76+
<groupId>org.netbeans.api</groupId>
77+
<artifactId>org-netbeans-api-annotations-common</artifactId>
78+
</dependency>
79+
<!-- Project internal dependencies -->
80+
<dependency>
81+
<groupId>org.neo4j.driver</groupId>
82+
<artifactId>neo4j-java-driver</artifactId>
83+
<version>${neo4j.driver.version}</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>io.reactivex.rxjava2</groupId>
87+
<artifactId>rxjava</artifactId>
88+
<version>${rxjava.version}</version>
89+
</dependency>
90+
<!-- Testing dependencies -->
4991
<dependency>
5092
<groupId>org.testcontainers</groupId>
5193
<artifactId>testcontainers</artifactId>
@@ -89,6 +131,11 @@
89131
<enabled>true</enabled>
90132
</snapshots>
91133
</repository>
134+
<repository>
135+
<id>unknown-jars-temp-repo</id>
136+
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
137+
<url>file:${project.basedir}/lib</url>
138+
</repository>
92139
</repositories>
93140
</project>
94141

modules/Neo4jPlugin/src/main/java/org/gephi/plugins/neo4j/importer/Neo4jDatabaseImporter.java

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.gephi.plugins.neo4j.importer;
22

3+
import cern.colt.list.ObjectArrayList;
34
import io.reactivex.Flowable;
45
import io.reactivex.Observable;
56
import org.gephi.io.importer.api.*;
@@ -90,30 +91,6 @@ public class Neo4jDatabaseImporter implements WizardImporter, LongTask {
9091
*/
9192
private Driver driver;
9293

93-
94-
public static void checkConnection(String url, String username, String password, String dbName) {
95-
Driver driver = GraphDatabase.driver(url, password != null ? AuthTokens.basic(username, password) : AuthTokens.none());
96-
try {
97-
driver.verifyConnectivity();
98-
driver.session(dbName != null ? SessionConfig.forDatabase(dbName) : SessionConfig.defaultConfig()).run("RETURN 1");
99-
} catch (Exception e) {
100-
throw e;
101-
} finally {
102-
driver.close();
103-
}
104-
}
105-
106-
public static void checkQuery(String url, String username, String password, String dbName, String query) {
107-
Driver driver = GraphDatabase.driver(url, password != null ? AuthTokens.basic(username, password) : AuthTokens.none(), Config.builder().withFetchSize(5).build());
108-
try {
109-
driver.session(dbName != null ? SessionConfig.forDatabase(dbName) : SessionConfig.defaultConfig()).run(query);
110-
} catch (Exception e) {
111-
throw e;
112-
} finally {
113-
driver.close();
114-
}
115-
}
116-
11794
@Override
11895
public boolean execute(ContainerLoader containerLoader) {
11996
this.container = containerLoader;
@@ -131,7 +108,6 @@ public boolean execute(ContainerLoader containerLoader) {
131108
this.driver.verifyConnectivity();
132109
// Creating default columns for nodes/edges
133110
this.getContainer().addNodeColumn("labels", String[].class);
134-
this.getContainer().addEdgeColumn("type", String.class);
135111

136112
// Do the related import
137113
if (this.nodeQuery != null && this.edgeQuery != null) {
@@ -317,6 +293,8 @@ private Boolean mergeNodeInGephi(String id, String[] labels, Map<String, Value>
317293
draft.setLabel(attributes.get("name").asString());
318294
} else if (attributes.containsKey("id")) {
319295
draft.setLabel(attributes.get("id").asString());
296+
} else if (attributes.containsKey("title")) {
297+
draft.setLabel(attributes.get("title").asString());
320298
} else {
321299
draft.setLabel(id);
322300
}
@@ -375,62 +353,86 @@ private void addNeo4jAttributes(ElementDraft draft, Map<String, Value> attribute
375353
attributes.keySet().forEach(key -> {
376354
Value value = attributes.get(key);
377355
String gephiColKey = attributePrefix != null ? attributePrefix + "_" + key : key;
378-
379356
try {
380-
switch (value.getClass().getSimpleName()) {
381-
case "BooleanValue":
382-
draft.setValue(gephiColKey, value.asBoolean());
383-
break;
384-
case "BytesValue":
385-
throw new NotImplementedException("Bytes value is not implemented");
386-
case "DateTimeValue":
387-
throw new NotImplementedException("DateTime value is not implemented");
388-
case "DateValue":
389-
throw new NotImplementedException("Date value is not implemented");
390-
case "DurationValue":
391-
throw new NotImplementedException("Duration value is not implemented");
392-
case "FloatValue":
393-
draft.setValue(gephiColKey, value.asFloat());
394-
break;
395-
case "IntegerValue":
396-
draft.setValue(gephiColKey, value.asInt());
397-
break;
398-
case "ListValue":
399-
draft.setValue(gephiColKey, value.asList());
400-
break;
401-
case "LocalDateTimeValue":
402-
throw new NotImplementedException("LocalDateTime value is not implemented");
403-
case "LocalTimeValue":
404-
throw new NotImplementedException("LocalTime value is not implemented");
405-
case "MapValue":
406-
throw new NotImplementedException("Map value is not implemented");
407-
case "NodeValue":
408-
throw new NotImplementedException("Node value is not implemented");
409-
case "NullValue":
410-
break;
411-
case "NumberValueAdapter":
412-
draft.setValue(gephiColKey, value.asNumber());
413-
break;
414-
case "ObjectValueAdapter":
415-
throw new NotImplementedException("Object value is not implemented");
416-
case "PathValue":
417-
throw new NotImplementedException("Path value is not implemented");
418-
case "PointValue":
419-
throw new NotImplementedException("Point value is not implemented");
420-
case "RelationshipValue":
421-
throw new NotImplementedException("Relationship value is not implemented");
422-
case "TimeValue":
423-
throw new NotImplementedException("Time value is not implemented");
424-
case "StringValue":
425-
draft.setValue(gephiColKey, value.asString());
426-
break;
357+
Object gephiValue = this.neo4jValueToGephi(value);
358+
if (gephiValue != null) {
359+
System.out.println(gephiValue.getClass().toString());
360+
draft.setValue(gephiColKey, gephiValue);
427361
}
428362
} catch (Exception e) {
429-
this.getReport().log(String.format("Property %s on node %s has been skipped due to bad type", key, draft.getId()));
363+
this.getReport().log(String.format("Property %s on %s %s has been skipped due to bad type", key, draft instanceof NodeDraft ? "node" : "edge", draft.getId()));
430364
}
431365
});
432366
}
433367

368+
private Object neo4jValueToGephi(Value value) {
369+
Object result = null;
370+
System.out.println(value);
371+
System.out.println(value.type().name());
372+
switch (value.type().name()) {
373+
case "ANY":
374+
throw new NotImplementedException("Any value is not implemented");
375+
case "BOOLEAN":
376+
result = value.asBoolean();
377+
break;
378+
case "BYTES":
379+
throw new NotImplementedException("Bytes value is not implemented");
380+
case "DATE_TIME":
381+
throw new NotImplementedException("DateTime value is not implemented");
382+
case "DATE":
383+
throw new NotImplementedException("Date value is not implemented");
384+
case "DURATION":
385+
throw new NotImplementedException("Duration value is not implemented");
386+
case "FLOAT":
387+
result = value.asFloat();
388+
break;
389+
case "INTEGER":
390+
result = value.asInt();
391+
break;
392+
case "LIST":
393+
case "LIST OF ANY?":
394+
if(value.asList().size() > 0) {
395+
result = toArray(value.asList(this::neo4jValueToGephi));
396+
}
397+
398+
break;
399+
case "LOCAL_DATE_TIME":
400+
throw new NotImplementedException("LocalDateTime value is not implemented");
401+
case "LOCAL_TIME":
402+
throw new NotImplementedException("LocalTime value is not implemented");
403+
case "MAP":
404+
throw new NotImplementedException("Map value is not implemented");
405+
case "NODE":
406+
throw new NotImplementedException("Node value is not implemented");
407+
case "NULL":
408+
result = null;
409+
break;
410+
case "NUMBER":
411+
result = value.asNumber();
412+
break;
413+
case "ObjectValueAdapter":
414+
throw new NotImplementedException("Object value is not implemented");
415+
case "PATH":
416+
throw new NotImplementedException("Path value is not implemented");
417+
case "POINT":
418+
throw new NotImplementedException("Point value is not implemented");
419+
case "RELATIONSHIP":
420+
throw new NotImplementedException("Relationship value is not implemented");
421+
case "STRING":
422+
result = value.asString();
423+
break;
424+
case "TIME":
425+
throw new NotImplementedException("Time value is not implemented");
426+
}
427+
return result;
428+
}
429+
430+
public <T> T[] toArray(List<T> list) {
431+
Class clazz = list.get(0).getClass(); // check for size and null before
432+
T[] array = (T[]) java.lang.reflect.Array.newInstance(clazz, list.size());
433+
return list.toArray(array);
434+
}
435+
434436
@Override
435437
public void setProgressTicket(ProgressTicket progressTicket) {
436438
}

0 commit comments

Comments
 (0)