From 1b5d5ceabc3ac7aaaf7474677af3566a32e4cfa6 Mon Sep 17 00:00:00 2001 From: Daniel Kuppitz Date: Sun, 7 Dec 2014 17:10:39 +0100 Subject: [PATCH] minor bug fixes --- .../neo4j/plugins/GremlinPlugin.java | 15 ++++++++++++--- .../neo4j/plugins/GremlinPlugin.java | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/tinkerpop2/src/main/java/com/thinkaurelius/neo4j/plugins/GremlinPlugin.java b/tinkerpop2/src/main/java/com/thinkaurelius/neo4j/plugins/GremlinPlugin.java index 3cee78c..d7902f2 100644 --- a/tinkerpop2/src/main/java/com/thinkaurelius/neo4j/plugins/GremlinPlugin.java +++ b/tinkerpop2/src/main/java/com/thinkaurelius/neo4j/plugins/GremlinPlugin.java @@ -26,6 +26,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.StringWriter; +import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.file.Paths; import java.util.ArrayList; @@ -44,9 +45,7 @@ public class GremlinPlugin { private final static Object LOCK = new Object(); private final static JSONResultConverter RESULT_CONVERTER = new JSONResultConverter(GraphSONMode.NORMAL, 0, Long.MAX_VALUE, null); private final static ConcurrentMap CACHED_SCRIPTS = new ConcurrentHashMap<>(); - private final static String SCRIPT_DIRECTORY = Paths.get(GremlinPlugin.class - .getProtectionDomain().getCodeSource().getLocation().toURI()) - .getParent().getParent().getParent() + File.separator + "scripts"; + private final static String SCRIPT_DIRECTORY = getScriptDirectory(); private static volatile ScriptEngine engine; private static Neo4j2Graph neo4jGraph; @@ -54,6 +53,16 @@ public class GremlinPlugin { private final GraphDatabaseService neo4j; private final Neo4j2Graph graph; + private static String getScriptDirectory() { + try { + return Paths.get(GremlinPlugin.class + .getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParent().getParent().getParent() + File.separator + "scripts"; + } catch (URISyntaxException e) { + return "." + File.separator + "scripts"; + } + } + public GremlinPlugin(@Context GraphDatabaseService database) { this.graph = getOrCreateGraph(this.neo4j = database); } diff --git a/tinkerpop3/src/main/java/com/thinkaurelius/neo4j/plugins/GremlinPlugin.java b/tinkerpop3/src/main/java/com/thinkaurelius/neo4j/plugins/GremlinPlugin.java index 0a3e714..65533b3 100644 --- a/tinkerpop3/src/main/java/com/thinkaurelius/neo4j/plugins/GremlinPlugin.java +++ b/tinkerpop3/src/main/java/com/thinkaurelius/neo4j/plugins/GremlinPlugin.java @@ -24,6 +24,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.StringWriter; +import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.file.Paths; import java.util.ArrayList; @@ -41,9 +42,7 @@ public class GremlinPlugin { private final static Object LOCK = new Object(); private final static ConcurrentMap CACHED_SCRIPTS = new ConcurrentHashMap<>(); - private final static String SCRIPT_DIRECTORY = Paths.get(GremlinPlugin.class - .getProtectionDomain().getCodeSource().getLocation().toURI()) - .getParent().getParent().getParent() + File.separator + "scripts"; + private final static String SCRIPT_DIRECTORY = getScriptDirectory(); private static volatile ScriptEngine engine; private static Neo4jGraph neo4jGraph; @@ -51,6 +50,16 @@ public class GremlinPlugin { private final GraphDatabaseService neo4j; private final Neo4jGraph graph; + private static String getScriptDirectory() { + try { + return Paths.get(GremlinPlugin.class + .getProtectionDomain().getCodeSource().getLocation().toURI()) + .getParent().getParent().getParent() + File.separator + "scripts"; + } catch (URISyntaxException e) { + return "." + File.separator + "scripts"; + } + } + public GremlinPlugin(@Context GraphDatabaseService database) { this.graph = getOrCreateGraph(this.neo4j = database); } @@ -93,7 +102,7 @@ public Response execute(@QueryParam("script") final String script, Object result = null; - final GraphSONObjectMapper mapper = GraphSONObjectMapper.build().embedTypes(false).build(); + final GraphSONObjectMapper mapper = GraphSONObjectMapper.build().embedTypes(false).create(); final String[] loadScripts = load != null && !load.isEmpty() ? load.split(",") : null; final JSONObject parameters = params != null ? new JSONObject(params) : null;