You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/08/14 13:13:06 UTC
[1/6] incubator-tinkerpop git commit: Renamed TP2 tokens to be
consistent with use of Legacy to refer to the old format.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/tp30-legson f7201fc6b -> ac258c022
Renamed TP2 tokens to be consistent with use of Legacy to refer to the old format.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/3776675f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/3776675f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/3776675f
Branch: refs/heads/tp30-legson
Commit: 3776675f73e90c1d88e876ebd58ecd79df612ba8
Parents: f7201fc
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Aug 13 16:06:04 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Aug 13 16:06:04 2015 -0400
----------------------------------------------------------------------
.../io/graphson/FaunusGraphSONUtility.java | 26 ++---
.../io/graphson/GraphSONLegacyReader.java | 24 ++---
.../io/graphson/GraphSONLegacyWriter.java | 6 +-
.../io/graphson/GraphSONTokensTP2.java | 50 ---------
.../io/graphson/LegacyGraphSONReader.java | 11 +-
.../io/graphson/LegacyGraphSONTokens.java | 50 +++++++++
.../io/graphson/LegacyGraphSONUtility.java | 54 +++++-----
.../io/graphson/TP2GraphSONUtility.java | 106 +++++++++----------
8 files changed, 163 insertions(+), 164 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3776675f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
index e455d5e..37f5a69 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
@@ -52,8 +52,8 @@ public class FaunusGraphSONUtility {
//private static final String _IN_E = "_inE";
private static final String EMPTY_STRING = "";
- private static final Set<String> VERTEX_IGNORE = new HashSet<String>(Arrays.asList(GraphSONTokensTP2._TYPE, GraphSONTokensTP2._OUT_E, GraphSONTokensTP2._IN_E));
- private static final Set<String> EDGE_IGNORE = new HashSet<String>(Arrays.asList(GraphSONTokensTP2._TYPE, GraphSONTokensTP2._OUT_V, GraphSONTokensTP2._IN_V));
+ private static final Set<String> VERTEX_IGNORE = new HashSet<String>(Arrays.asList(LegacyGraphSONTokens._TYPE, LegacyGraphSONTokens._OUT_E, LegacyGraphSONTokens._IN_E));
+ private static final Set<String> EDGE_IGNORE = new HashSet<String>(Arrays.asList(LegacyGraphSONTokens._TYPE, LegacyGraphSONTokens._OUT_V, LegacyGraphSONTokens._IN_V));
private static final ElementFactory elementFactory = new MyElementFactory();
@@ -79,10 +79,10 @@ public class FaunusGraphSONUtility {
final Vertex vertex = graphson.vertexFromJson(json);
- fromJSONEdges(vertex, json.optJSONArray(GraphSONTokensTP2._OUT_E), OUT);
- json.remove(GraphSONTokensTP2._OUT_E); // clear up some memory
- fromJSONEdges(vertex, json.optJSONArray(GraphSONTokensTP2._IN_E), IN);
- json.remove(GraphSONTokensTP2._IN_E); // clear up some memory
+ fromJSONEdges(vertex, json.optJSONArray(LegacyGraphSONTokens._OUT_E), OUT);
+ json.remove(LegacyGraphSONTokens._OUT_E); // clear up some memory
+ fromJSONEdges(vertex, json.optJSONArray(LegacyGraphSONTokens._IN_E), IN);
+ json.remove(LegacyGraphSONTokens._IN_E); // clear up some memory
return vertex;
} catch (Exception e) {
@@ -96,13 +96,13 @@ public class FaunusGraphSONUtility {
final JSONObject jsonEdge = edges.optJSONObject(i);
Edge edge = null;
if (direction.equals(Direction.IN)) {
- DetachedVertex outVertex = new DetachedVertex(jsonEdge.optLong(GraphSONTokensTP2._OUT_V),null,new HashMap<>());
+ DetachedVertex outVertex = new DetachedVertex(jsonEdge.optLong(LegacyGraphSONTokens._OUT_V),null,new HashMap<>());
edge = graphson.edgeFromJson(jsonEdge, outVertex, vertex);
- outVertex.addEdge(jsonEdge.optString(GraphSONTokensTP2._LABEL), vertex);
+ outVertex.addEdge(jsonEdge.optString(LegacyGraphSONTokens._LABEL), vertex);
} else if (direction.equals(Direction.OUT)) {
- DetachedVertex inVertex = new DetachedVertex(jsonEdge.optLong(GraphSONTokensTP2._IN_V),null,new HashMap<>());
+ DetachedVertex inVertex = new DetachedVertex(jsonEdge.optLong(LegacyGraphSONTokens._IN_V),null,new HashMap<>());
edge = graphson.edgeFromJson(jsonEdge, vertex, inVertex);
- vertex.addEdge(jsonEdge.optString(GraphSONTokensTP2._LABEL), inVertex);
+ vertex.addEdge(jsonEdge.optString(LegacyGraphSONTokens._LABEL), inVertex);
}
}
}
@@ -115,7 +115,7 @@ public class FaunusGraphSONUtility {
// force the ID to long. with blueprints, most implementations will send back a long, but
// some like TinkerGraph will return a string. the same is done for edges below
- object.put(GraphSONTokensTP2._ID, Long.valueOf(object.remove(GraphSONTokensTP2._ID).toString()));
+ object.put(LegacyGraphSONTokens._ID, Long.valueOf(object.remove(LegacyGraphSONTokens._ID).toString()));
List<Edge> edges = new ArrayList<Edge>();
vertex.edges(OUT).forEachRemaining(edges::add);
@@ -126,7 +126,7 @@ public class FaunusGraphSONUtility {
final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, null, GraphSONMode.COMPACT);
outEdgesArray.put(edgeObject);
}
- object.put(GraphSONTokensTP2._OUT_E, outEdgesArray);
+ object.put(LegacyGraphSONTokens._OUT_E, outEdgesArray);
}
vertex.edges(IN).forEachRemaining(edges::add);
@@ -137,7 +137,7 @@ public class FaunusGraphSONUtility {
final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, null, GraphSONMode.COMPACT);
inEdgesArray.put(edgeObject);
}
- object.put(GraphSONTokensTP2._IN_E, inEdgesArray);
+ object.put(LegacyGraphSONTokens._IN_E, inEdgesArray);
}
return object;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3776675f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java
index 9fc7477..f48ebae 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java
@@ -157,7 +157,7 @@ public final class GraphSONLegacyReader implements GraphReader {
//final Map<String, Object> vertexData = LegacyGraphSONUtility.readProperties(node);
final Map<String, Object> vertexData = TP2GraphSONUtility.readProperties(node, false, false);
//starGraph.addVertex(T.id, vertexData.get(GraphSONTokensTP2._ID), T.label, vertexData.get(GraphSONTokensTP2._LABEL));
- starGraph.addVertex(T.id, vertexData.get(GraphSONTokensTP2._ID)); //
+ starGraph.addVertex(T.id, vertexData.get(LegacyGraphSONTokens._ID)); //
for (Map.Entry<String, Object> p : vertexData.entrySet()) {
if (LegacyGraphSONUtility.isReservedKey(p.getKey()))
continue;
@@ -165,11 +165,11 @@ public final class GraphSONLegacyReader implements GraphReader {
}
if (vertexAttachMethod != null) vertexAttachMethod.apply(starGraph.getStarVertex());
- if (vertexData.containsKey(GraphSONTokensTP2._OUT_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.OUT))
- readEdges(edgeAttachMethod, starGraph, vertexData, GraphSONTokensTP2._OUT_E);
+ if (vertexData.containsKey(LegacyGraphSONTokens._OUT_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.OUT))
+ readEdges(edgeAttachMethod, starGraph, vertexData, LegacyGraphSONTokens._OUT_E);
- if (vertexData.containsKey(GraphSONTokensTP2._IN_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.IN))
- readEdges(edgeAttachMethod, starGraph, vertexData, GraphSONTokensTP2._IN_E);
+ if (vertexData.containsKey(LegacyGraphSONTokens._IN_E) && (attachEdgesOfThisDirection == Direction.BOTH || attachEdgesOfThisDirection == Direction.IN))
+ readEdges(edgeAttachMethod, starGraph, vertexData, LegacyGraphSONTokens._IN_E);
} catch (Exception ex) {
throw new IOException(ex);
@@ -187,11 +187,11 @@ public final class GraphSONLegacyReader implements GraphReader {
//for (Map.Entry<String, List<Map<String,Object>>> edgeData : edgeDatas.entrySet()) {
for (Map<String,Object> edgeData : edgeDatas) { //edgeData.getValue()) {
final StarGraph.StarEdge starEdge;
- String edgeLabel = edgeData.get(GraphSONTokensTP2._LABEL).toString();
+ String edgeLabel = edgeData.get(LegacyGraphSONTokens._LABEL).toString();
if (direction.equals(GraphSONTokens.OUT_E))
- starEdge = (StarGraph.StarEdge) starGraph.getStarVertex().addOutEdge(edgeLabel, starGraph.addVertex(T.id, edgeData.get(GraphSONTokensTP2._IN_V)), T.id, edgeData.get(GraphSONTokensTP2._ID));
+ starEdge = (StarGraph.StarEdge) starGraph.getStarVertex().addOutEdge(edgeLabel, starGraph.addVertex(T.id, edgeData.get(LegacyGraphSONTokens._IN_V)), T.id, edgeData.get(LegacyGraphSONTokens._ID));
else
- starEdge = (StarGraph.StarEdge) starGraph.getStarVertex().addInEdge(edgeLabel, starGraph.addVertex(T.id, edgeData.get(GraphSONTokensTP2._OUT_V)), T.id, edgeData.get(GraphSONTokensTP2._ID));
+ starEdge = (StarGraph.StarEdge) starGraph.getStarVertex().addInEdge(edgeLabel, starGraph.addVertex(T.id, edgeData.get(LegacyGraphSONTokens._OUT_V)), T.id, edgeData.get(LegacyGraphSONTokens._ID));
for (Map.Entry<String, Object> epd : edgeData.entrySet()) {
if (!LegacyGraphSONUtility.isReservedKey(epd.getKey()))
starEdge.property(epd.getKey(), epd.getValue());
@@ -214,11 +214,11 @@ public final class GraphSONLegacyReader implements GraphReader {
final Map<String,Object> edgeProperties = edgeData.containsKey(GraphSONTokens.PROPERTIES) ?
(Map<String, Object>) edgeData.get(GraphSONTokens.PROPERTIES) : Collections.EMPTY_MAP;
- final DetachedEdge edge = new DetachedEdge(edgeData.get(GraphSONTokensTP2._ID),
- edgeData.get(GraphSONTokensTP2._LABEL).toString(),
+ final DetachedEdge edge = new DetachedEdge(edgeData.get(LegacyGraphSONTokens._ID),
+ edgeData.get(LegacyGraphSONTokens._LABEL).toString(),
edgeProperties,
- Pair.with(edgeData.get(GraphSONTokensTP2._OUT_V), null),
- Pair.with(edgeData.get(GraphSONTokensTP2._IN_V), null));
+ Pair.with(edgeData.get(LegacyGraphSONTokens._OUT_V), null),
+ Pair.with(edgeData.get(LegacyGraphSONTokens._IN_V), null));
return edgeAttachMethod.apply(edge);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3776675f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
index f10d040..b80ba4a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
@@ -106,9 +106,9 @@ public class GraphSONLegacyWriter {
jg.writeStartObject();
- jg.writeStringField(GraphSONTokensTP2.MODE, mode.toString());
+ jg.writeStringField(LegacyGraphSONTokens.MODE, mode.toString());
- jg.writeArrayFieldStart(GraphSONTokensTP2.VERTICES);
+ jg.writeArrayFieldStart(LegacyGraphSONTokens.VERTICES);
final Iterable<Vertex> vertices = vertices(normalize);
for (Vertex v : vertices) {
@@ -117,7 +117,7 @@ public class GraphSONLegacyWriter {
jg.writeEndArray();
- jg.writeArrayFieldStart(GraphSONTokensTP2.EDGES);
+ jg.writeArrayFieldStart(LegacyGraphSONTokens.EDGES);
final Iterable<Edge> edges = edges(normalize);
for (Edge e : edges) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3776675f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokensTP2.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokensTP2.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokensTP2.java
deleted file mode 100644
index d5cbf26..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTokensTP2.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.io.graphson;
-
-public final class GraphSONTokensTP2 {
-
- private GraphSONTokensTP2() {}
-
- public static final String _ID = "_id";
- public static final String _LABEL = "_label";
- public static final String _TYPE = "_type";
- public static final String _OUT_V = "_outV";
- public static final String _IN_V = "_inV";
- public static final String _OUT_E = "_outE";
- public static final String _IN_E = "_inE";
- public static final String VALUE = "value";
- //public static final String TYPE = "type";
- public static final String TYPE_LIST = "list";
- public static final String TYPE_STRING = "string";
- public static final String TYPE_DOUBLE = "double";
- public static final String TYPE_INTEGER = "integer";
- public static final String TYPE_FLOAT = "float";
- public static final String TYPE_MAP = "map";
- public static final String TYPE_BOOLEAN = "boolean";
- public static final String TYPE_LONG = "long";
- public static final String TYPE_SHORT = "short";
- public static final String TYPE_BYTE = "byte";
- public static final String TYPE_UNKNOWN = "unknown";
-
- public static final String VERTICES = "vertices";
- public static final String EDGES = "edges";
- public static final String MODE = "mode";
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3776675f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
index d727068..9886686 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONReader.java
@@ -26,7 +26,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -80,13 +79,13 @@ public final class LegacyGraphSONReader implements GraphReader {
while (parser.nextToken() != JsonToken.END_OBJECT) {
final String fieldName = parser.getCurrentName() == null ? "" : parser.getCurrentName();
switch (fieldName) {
- case GraphSONTokensTP2.MODE:
+ case LegacyGraphSONTokens.MODE:
parser.nextToken();
final String mode = parser.getText();
if (!mode.equals("EXTENDED"))
throw new IllegalStateException("The legacy GraphSON must be generated with GraphSONMode.EXTENDED");
break;
- case GraphSONTokensTP2.VERTICES:
+ case LegacyGraphSONTokens.VERTICES:
parser.nextToken();
while (parser.nextToken() != JsonToken.END_ARRAY) {
final JsonNode node = parser.readValueAsTree();
@@ -96,12 +95,12 @@ public final class LegacyGraphSONReader implements GraphReader {
graphToWriteTo.tx().commit();
}
break;
- case GraphSONTokensTP2.EDGES:
+ case LegacyGraphSONTokens.EDGES:
parser.nextToken();
while (parser.nextToken() != JsonToken.END_ARRAY) {
final JsonNode node = parser.readValueAsTree();
- final Vertex inV = cache.get(LegacyGraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokensTP2._IN_V)));
- final Vertex outV = cache.get(LegacyGraphSONUtility.getTypedValueFromJsonNode(node.get(GraphSONTokensTP2._OUT_V)));
+ final Vertex inV = cache.get(LegacyGraphSONUtility.getTypedValueFromJsonNode(node.get(LegacyGraphSONTokens._IN_V)));
+ final Vertex outV = cache.get(LegacyGraphSONUtility.getTypedValueFromJsonNode(node.get(LegacyGraphSONTokens._OUT_V)));
graphson.edgeFromJson(node, outV, inV);
if (supportsTx && counter.incrementAndGet() % batchSize == 0)
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3776675f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java
new file mode 100644
index 0000000..d27bf02
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.io.graphson;
+
+public final class LegacyGraphSONTokens {
+
+ private LegacyGraphSONTokens() {}
+
+ public static final String _ID = "_id";
+ public static final String _LABEL = "_label";
+ public static final String _TYPE = "_type";
+ public static final String _OUT_V = "_outV";
+ public static final String _IN_V = "_inV";
+ public static final String _OUT_E = "_outE";
+ public static final String _IN_E = "_inE";
+ public static final String VALUE = "value";
+ //public static final String TYPE = "type";
+ public static final String TYPE_LIST = "list";
+ public static final String TYPE_STRING = "string";
+ public static final String TYPE_DOUBLE = "double";
+ public static final String TYPE_INTEGER = "integer";
+ public static final String TYPE_FLOAT = "float";
+ public static final String TYPE_MAP = "map";
+ public static final String TYPE_BOOLEAN = "boolean";
+ public static final String TYPE_LONG = "long";
+ public static final String TYPE_SHORT = "short";
+ public static final String TYPE_BYTE = "byte";
+ public static final String TYPE_UNKNOWN = "unknown";
+
+ public static final String VERTICES = "vertices";
+ public static final String EDGES = "edges";
+ public static final String MODE = "mode";
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3776675f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java
index 0f18d05..3efc39a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java
@@ -47,7 +47,7 @@ public final class LegacyGraphSONUtility {
public Vertex vertexFromJson(final JsonNode json) throws IOException {
final Map<String, Object> props = readProperties(json);
- final Object vertexId = getTypedValueFromJsonNode(json.get(GraphSONTokensTP2._ID));
+ final Object vertexId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
final Vertex v = vertexFeatures.willAllowId(vertexId) ? g.addVertex(T.id, vertexId) : g.addVertex();
cache.put(vertexId, v);
@@ -61,8 +61,8 @@ public final class LegacyGraphSONUtility {
public Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in) throws IOException {
final Map<String, Object> props = LegacyGraphSONUtility.readProperties(json);
- final Object edgeId = getTypedValueFromJsonNode(json.get(GraphSONTokensTP2._ID));
- final JsonNode nodeLabel = json.get(GraphSONTokensTP2._LABEL);
+ final Object edgeId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
+ final JsonNode nodeLabel = json.get(LegacyGraphSONTokens._LABEL);
final String label = nodeLabel == null ? EMPTY_STRING : nodeLabel.textValue();
final Edge e = edgeFeatures.willAllowId(edgeId) ? out.addEdge(label, in, T.id, edgeId) : out.addEdge(label, in) ;
@@ -94,36 +94,36 @@ public final class LegacyGraphSONUtility {
}
public static boolean isReservedKey(final String key) {
- return key.equals(GraphSONTokensTP2._ID) || key.equals(GraphSONTokensTP2._TYPE) || key.equals(GraphSONTokensTP2._LABEL)
- || key.equals(GraphSONTokensTP2._OUT_V) || key.equals(GraphSONTokensTP2._IN_V)
- || key.equals(GraphSONTokensTP2._IN_E) || key.equals(GraphSONTokensTP2._OUT_E);
+ return key.equals(LegacyGraphSONTokens._ID) || key.equals(LegacyGraphSONTokens._TYPE) || key.equals(LegacyGraphSONTokens._LABEL)
+ || key.equals(LegacyGraphSONTokens._OUT_V) || key.equals(LegacyGraphSONTokens._IN_V)
+ || key.equals(LegacyGraphSONTokens._IN_E) || key.equals(LegacyGraphSONTokens._OUT_E);
}
private static Object readProperty(final JsonNode node) {
final Object propertyValue;
- if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_UNKNOWN)) {
+ if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_UNKNOWN)) {
propertyValue = null;
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_BOOLEAN)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).booleanValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_FLOAT)) {
- propertyValue = Float.parseFloat(node.get(GraphSONTokensTP2.VALUE).asText());
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_BYTE)) {
- propertyValue = Byte.parseByte(node.get(GraphSONTokensTP2.VALUE).asText());
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_SHORT)) {
- propertyValue = Short.parseShort(node.get(GraphSONTokensTP2.VALUE).asText());
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_DOUBLE)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).doubleValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_INTEGER)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).intValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_LONG)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).longValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_STRING)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).textValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_LIST)) {
- propertyValue = readProperties(node.get(GraphSONTokensTP2.VALUE).elements());
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_MAP)) {
- propertyValue = readProperties(node.get(GraphSONTokensTP2.VALUE));
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BOOLEAN)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).booleanValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_FLOAT)) {
+ propertyValue = Float.parseFloat(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BYTE)) {
+ propertyValue = Byte.parseByte(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_SHORT)) {
+ propertyValue = Short.parseShort(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_DOUBLE)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).doubleValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_INTEGER)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).intValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LONG)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).longValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_STRING)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).textValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LIST)) {
+ propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE).elements());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_MAP)) {
+ propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE));
} else {
propertyValue = node.textValue();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3776675f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
index eed2a7a..c2056cd 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
@@ -143,13 +143,13 @@ public class TP2GraphSONUtility {
this.factory = factory;
this.hasEmbeddedTypes = mode == GraphSONMode.EXTENDED;
- this.includeReservedVertexId = includeReservedKey(mode, GraphSONTokensTP2._ID, vertexPropertyKeys, this.vertexPropertiesRule);
- this.includeReservedEdgeId = includeReservedKey(mode, GraphSONTokensTP2._ID, edgePropertyKeys, this.edgePropertiesRule);
- this.includeReservedVertexType = includeReservedKey(mode, GraphSONTokensTP2._TYPE, vertexPropertyKeys, this.vertexPropertiesRule);
- this.includeReservedEdgeType = includeReservedKey(mode, GraphSONTokensTP2._TYPE, edgePropertyKeys, this.edgePropertiesRule);
- this.includeReservedEdgeLabel = includeReservedKey(mode, GraphSONTokensTP2._LABEL, edgePropertyKeys, this.edgePropertiesRule);
- this.includeReservedEdgeOutV = includeReservedKey(mode, GraphSONTokensTP2._OUT_V, edgePropertyKeys, this.edgePropertiesRule);
- this.includeReservedEdgeInV = includeReservedKey(mode, GraphSONTokensTP2._IN_V, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedVertexId = includeReservedKey(mode, LegacyGraphSONTokens._ID, vertexPropertyKeys, this.vertexPropertiesRule);
+ this.includeReservedEdgeId = includeReservedKey(mode, LegacyGraphSONTokens._ID, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedVertexType = includeReservedKey(mode, LegacyGraphSONTokens._TYPE, vertexPropertyKeys, this.vertexPropertiesRule);
+ this.includeReservedEdgeType = includeReservedKey(mode, LegacyGraphSONTokens._TYPE, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedEdgeLabel = includeReservedKey(mode, LegacyGraphSONTokens._LABEL, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedEdgeOutV = includeReservedKey(mode, LegacyGraphSONTokens._OUT_V, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedEdgeInV = includeReservedKey(mode, LegacyGraphSONTokens._IN_V, edgePropertyKeys, this.edgePropertiesRule);
}
/**
@@ -183,7 +183,7 @@ public class TP2GraphSONUtility {
public Vertex vertexFromJson(final JsonNode json) throws IOException {
final Map<String, Object> props = readProperties(json, true, this.hasEmbeddedTypes);
- final Object vertexId = getTypedValueFromJsonNode(json.get(GraphSONTokensTP2._ID));
+ final Object vertexId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
final Vertex v = factory.createVertex(vertexId);
for (Map.Entry<String, Object> entry : props.entrySet()) {
@@ -227,8 +227,8 @@ public class TP2GraphSONUtility {
public Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in) throws IOException {
final Map<String, Object> props = TP2GraphSONUtility.readProperties(json, true, this.hasEmbeddedTypes);
- final Object edgeId = getTypedValueFromJsonNode(json.get(GraphSONTokensTP2._ID));
- final JsonNode nodeLabel = json.get(GraphSONTokensTP2._LABEL);
+ final Object edgeId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
+ final JsonNode nodeLabel = json.get(LegacyGraphSONTokens._LABEL);
// assigned an empty string edge label in cases where one does not exist. this gets around the requirement
// that blueprints graphs have a non-null label while ensuring that GraphSON can stay flexible in parsing
@@ -283,31 +283,31 @@ public class TP2GraphSONUtility {
final Edge edge = (Edge) element;
if (this.includeReservedEdgeId) {
- putObject(jsonElement, GraphSONTokensTP2._ID, element.id());
+ putObject(jsonElement, LegacyGraphSONTokens._ID, element.id());
}
if (this.includeReservedEdgeType) {
- jsonElement.put(GraphSONTokensTP2._TYPE, GraphSONTokens.EDGE);
+ jsonElement.put(LegacyGraphSONTokens._TYPE, GraphSONTokens.EDGE);
}
if (this.includeReservedEdgeOutV) {
- putObject(jsonElement, GraphSONTokensTP2._OUT_V, edge.outVertex().id());
+ putObject(jsonElement, LegacyGraphSONTokens._OUT_V, edge.outVertex().id());
}
if (this.includeReservedEdgeInV) {
- putObject(jsonElement, GraphSONTokensTP2._IN_V, edge.inVertex().id());
+ putObject(jsonElement, LegacyGraphSONTokens._IN_V, edge.inVertex().id());
}
if (this.includeReservedEdgeLabel) {
- jsonElement.put(GraphSONTokensTP2._LABEL, edge.label());
+ jsonElement.put(LegacyGraphSONTokens._LABEL, edge.label());
}
} else if (element instanceof Vertex) {
if (this.includeReservedVertexId) {
- putObject(jsonElement, GraphSONTokensTP2._ID, element.id());
+ putObject(jsonElement, LegacyGraphSONTokens._ID, element.id());
}
if (this.includeReservedVertexType) {
- jsonElement.put(GraphSONTokensTP2._TYPE, GraphSONTokens.VERTEX);
+ jsonElement.put(LegacyGraphSONTokens._TYPE, GraphSONTokens.VERTEX);
}
}
@@ -519,36 +519,36 @@ public class TP2GraphSONUtility {
}
private static boolean isReservedKey(final String key) {
- return key.equals(GraphSONTokensTP2._ID) || key.equals(GraphSONTokensTP2._TYPE) || key.equals(GraphSONTokensTP2._LABEL)
- || key.equals(GraphSONTokensTP2._OUT_V) || key.equals(GraphSONTokensTP2._IN_V);
+ return key.equals(LegacyGraphSONTokens._ID) || key.equals(LegacyGraphSONTokens._TYPE) || key.equals(LegacyGraphSONTokens._LABEL)
+ || key.equals(LegacyGraphSONTokens._OUT_V) || key.equals(LegacyGraphSONTokens._IN_V);
}
private static Object readProperty(final JsonNode node, final boolean hasEmbeddedTypes) {
final Object propertyValue;
if (hasEmbeddedTypes) {
- if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_UNKNOWN)) {
+ if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_UNKNOWN)) {
propertyValue = null;
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_BOOLEAN)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).booleanValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_FLOAT)) {
- propertyValue = Float.parseFloat(node.get(GraphSONTokensTP2.VALUE).asText());
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_BYTE)) {
- propertyValue = Byte.parseByte(node.get(GraphSONTokensTP2.VALUE).asText());
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_SHORT)) {
- propertyValue = Short.parseShort(node.get(GraphSONTokensTP2.VALUE).asText());
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_DOUBLE)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).doubleValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_INTEGER)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).intValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_LONG)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).longValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_STRING)) {
- propertyValue = node.get(GraphSONTokensTP2.VALUE).textValue();
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_LIST)) {
- propertyValue = readProperties(node.get(GraphSONTokensTP2.VALUE).elements(), hasEmbeddedTypes);
- } else if (node.get(GraphSONTokensTP2._TYPE).textValue().equals(GraphSONTokensTP2.TYPE_MAP)) {
- propertyValue = readProperties(node.get(GraphSONTokensTP2.VALUE), false, hasEmbeddedTypes);
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BOOLEAN)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).booleanValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_FLOAT)) {
+ propertyValue = Float.parseFloat(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BYTE)) {
+ propertyValue = Byte.parseByte(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_SHORT)) {
+ propertyValue = Short.parseShort(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_DOUBLE)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).doubleValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_INTEGER)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).intValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LONG)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).longValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_STRING)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).textValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LIST)) {
+ propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE).elements(), hasEmbeddedTypes);
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_MAP)) {
+ propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE), false, hasEmbeddedTypes);
} else {
propertyValue = node.textValue();
}
@@ -757,7 +757,7 @@ public class TP2GraphSONUtility {
ObjectNode valueAndType = jsonNodeFactory.objectNode();
valueAndType.put(GraphSONTokens.TYPE, type);
- if (type.equals(GraphSONTokensTP2.TYPE_LIST)) {
+ if (type.equals(LegacyGraphSONTokens.TYPE_LIST)) {
// values of lists must be accumulated as ObjectNode objects under the value key.
// will return as a ArrayNode. called recursively to traverse the entire
@@ -772,7 +772,7 @@ public class TP2GraphSONUtility {
addObject(valueArray, getValue(getTypedValueFromJsonNode(list.get(ix)), includeType));
}
- } else if (type.equals(GraphSONTokensTP2.TYPE_MAP)) {
+ } else if (type.equals(LegacyGraphSONTokens.TYPE_MAP)) {
// maps are converted to a ObjectNode. called recursively to traverse
// the entire object graph within the map.
@@ -845,27 +845,27 @@ public class TP2GraphSONUtility {
}
private static String determineType(final Object value) {
- String type = GraphSONTokensTP2.TYPE_STRING;
+ String type = LegacyGraphSONTokens.TYPE_STRING;
if (value == null) {
- type = GraphSONTokensTP2.TYPE_UNKNOWN;
+ type = LegacyGraphSONTokens.TYPE_UNKNOWN;
} else if (value.getClass() == Double.class) {
- type = GraphSONTokensTP2.TYPE_DOUBLE;
+ type = LegacyGraphSONTokens.TYPE_DOUBLE;
} else if (value.getClass() == Float.class) {
- type = GraphSONTokensTP2.TYPE_FLOAT;
+ type = LegacyGraphSONTokens.TYPE_FLOAT;
} else if (value.getClass() == Byte.class) {
- type = GraphSONTokensTP2.TYPE_BYTE;
+ type = LegacyGraphSONTokens.TYPE_BYTE;
} else if (value.getClass() == Short.class) {
- type = GraphSONTokensTP2.TYPE_SHORT;
+ type = LegacyGraphSONTokens.TYPE_SHORT;
} else if (value.getClass() == Integer.class) {
- type = GraphSONTokensTP2.TYPE_INTEGER;
+ type = LegacyGraphSONTokens.TYPE_INTEGER;
} else if (value.getClass() == Long.class) {
- type = GraphSONTokensTP2.TYPE_LONG;
+ type = LegacyGraphSONTokens.TYPE_LONG;
} else if (value.getClass() == Boolean.class) {
- type = GraphSONTokensTP2.TYPE_BOOLEAN;
+ type = LegacyGraphSONTokens.TYPE_BOOLEAN;
} else if (value instanceof ArrayNode) {
- type = GraphSONTokensTP2.TYPE_LIST;
+ type = LegacyGraphSONTokens.TYPE_LIST;
} else if (value instanceof ObjectNode) {
- type = GraphSONTokensTP2.TYPE_MAP;
+ type = LegacyGraphSONTokens.TYPE_MAP;
}
return type;
[4/6] incubator-tinkerpop git commit: Renamed class for consistency
with TP3.
Posted by sp...@apache.org.
Renamed class for consistency with TP3.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/641af9be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/641af9be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/641af9be
Branch: refs/heads/tp30-legson
Commit: 641af9be89aac98e8970e9f2679434c8cca6349d
Parents: 73234bd
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Aug 13 16:12:22 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Aug 13 16:12:22 2015 -0400
----------------------------------------------------------------------
.../BlueprintsLegacyGraphSONUtility.java | 873 +++++++++++++++++++
.../io/graphson/GraphSONLegacyReader.java | 2 +-
.../io/graphson/GraphSONLegacyWriter.java | 4 +-
.../graphson/HadoopLegacyGraphSONUtility.java | 12 +-
.../io/graphson/TP2GraphSONUtility.java | 873 -------------------
5 files changed, 882 insertions(+), 882 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/641af9be/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java
new file mode 100644
index 0000000..35c331f
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java
@@ -0,0 +1,873 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.io.graphson;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.MappingJsonFactory;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.ElementPropertyConfig.ElementPropertiesRule;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.codehaus.jettison.json.JSONTokener;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Array;
+import java.util.*;
+
+//import com.tinkerpop.blueprints.Direction;
+//import com.tinkerpop.blueprints.Element;
+
+/**
+ * Helps write individual graph elements to TinkerPop JSON format known as GraphSON.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class BlueprintsLegacyGraphSONUtility {
+
+ /**
+ * Modes of operation of the GraphSONUtility.
+ *
+ * @author Stephen Mallette
+ */
+ public enum GraphSONMode {
+ /**
+ * COMPACT constructs GraphSON on the assumption that all property keys
+ * are fair game for exclusion including _type, _inV, _outV, _label and _id.
+ * It is possible to write GraphSON that cannot be read back into Graph,
+ * if some or all of these keys are excluded.
+ */
+ COMPACT,
+
+ /**
+ * NORMAL includes the _type field and JSON data typing.
+ */
+ NORMAL,
+
+ /**
+ * EXTENDED includes the _type field and explicit data typing.
+ */
+ EXTENDED
+ }
+
+ /**
+ * A factory responsible for creating graph elements. Abstracts the way that graph elements are created. In
+ * most cases a Graph is responsible for element creation, but there are cases where more control over
+ * how vertices and edges are constructed.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+ public interface ElementFactory<V extends Vertex, E extends Edge> {
+ /**
+ * Creates a new Edge instance.
+ */
+ E createEdge(final Object id, final V out, final V in, final String label);
+
+ /**
+ * Creates a new Vertex instance.
+ */
+ V createVertex(final Object id);
+ }
+
+ private static final JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
+ private static final JsonFactory jsonFactory = new MappingJsonFactory();
+ private static final String EMPTY_STRING = "";
+
+ private static final ObjectMapper mapper = new ObjectMapper();
+
+ private final GraphSONMode mode;
+ private final List<String> vertexPropertyKeys;
+ private final List<String> edgePropertyKeys;
+ private final ElementFactory factory;
+ private final boolean hasEmbeddedTypes;
+ private final ElementPropertiesRule vertexPropertiesRule;
+ private final ElementPropertiesRule edgePropertiesRule;
+ private final boolean normalized;
+
+ private final boolean includeReservedVertexId;
+ private final boolean includeReservedEdgeId;
+ private final boolean includeReservedVertexType;
+ private final boolean includeReservedEdgeType;
+ private final boolean includeReservedEdgeLabel;
+ private final boolean includeReservedEdgeOutV;
+ private final boolean includeReservedEdgeInV;
+
+ /**
+ * A GraphSONUtiltiy that includes all properties of vertices and edges.
+ */
+ public BlueprintsLegacyGraphSONUtility(final GraphSONMode mode, final ElementFactory factory) {
+ this(mode, factory, ElementPropertyConfig.AllProperties);
+ }
+
+ /**
+ * A GraphSONUtility that includes the specified properties.
+ */
+ public BlueprintsLegacyGraphSONUtility(final GraphSONMode mode, final ElementFactory factory,
+ final Set<String> vertexPropertyKeys, final Set<String> edgePropertyKeys) {
+ this(mode, factory, ElementPropertyConfig.includeProperties(vertexPropertyKeys, edgePropertyKeys));
+ }
+
+ public BlueprintsLegacyGraphSONUtility(final GraphSONMode mode, final ElementFactory factory,
+ final ElementPropertyConfig config) {
+ this.vertexPropertyKeys = config.getVertexPropertyKeys();
+ this.edgePropertyKeys = config.getEdgePropertyKeys();
+ this.vertexPropertiesRule = config.getVertexPropertiesRule();
+ this.edgePropertiesRule = config.getEdgePropertiesRule();
+ this.normalized = config.isNormalized();
+
+ this.mode = mode;
+ this.factory = factory;
+ this.hasEmbeddedTypes = mode == GraphSONMode.EXTENDED;
+
+ this.includeReservedVertexId = includeReservedKey(mode, LegacyGraphSONTokens._ID, vertexPropertyKeys, this.vertexPropertiesRule);
+ this.includeReservedEdgeId = includeReservedKey(mode, LegacyGraphSONTokens._ID, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedVertexType = includeReservedKey(mode, LegacyGraphSONTokens._TYPE, vertexPropertyKeys, this.vertexPropertiesRule);
+ this.includeReservedEdgeType = includeReservedKey(mode, LegacyGraphSONTokens._TYPE, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedEdgeLabel = includeReservedKey(mode, LegacyGraphSONTokens._LABEL, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedEdgeOutV = includeReservedKey(mode, LegacyGraphSONTokens._OUT_V, edgePropertyKeys, this.edgePropertiesRule);
+ this.includeReservedEdgeInV = includeReservedKey(mode, LegacyGraphSONTokens._IN_V, edgePropertyKeys, this.edgePropertiesRule);
+ }
+
+ /**
+ * Creates a vertex from GraphSON using settings supplied in the constructor.
+ */
+ public Vertex vertexFromJson(final JSONObject json) throws IOException {
+ return this.vertexFromJson(json.toString());
+ }
+
+ /**
+ * Creates a vertex from GraphSON using settings supplied in the constructor.
+ */
+ public Vertex vertexFromJson(final String json) throws IOException {
+ final JsonParser jp = jsonFactory.createParser(json);
+ final JsonNode node = jp.readValueAsTree();
+ return this.vertexFromJson(node);
+ }
+
+ /**
+ * Creates a vertex from GraphSON using settings supplied in the constructor.
+ */
+ public Vertex vertexFromJson(final InputStream json) throws IOException {
+ final JsonParser jp = jsonFactory.createParser(json);
+ final JsonNode node = jp.readValueAsTree();
+ return this.vertexFromJson(node);
+ }
+
+ /**
+ * Creates a vertex from GraphSON using settings supplied in the constructor.
+ */
+ public Vertex vertexFromJson(final JsonNode json) throws IOException {
+ final Map<String, Object> props = readProperties(json, true, this.hasEmbeddedTypes);
+
+ final Object vertexId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
+ final Vertex v = factory.createVertex(vertexId);
+
+ for (Map.Entry<String, Object> entry : props.entrySet()) {
+ //if (this.vertexPropertyKeys == null || vertexPropertyKeys.contains(entry.getKey())) {
+ if (includeKey(entry.getKey(), vertexPropertyKeys, this.vertexPropertiesRule)) {
+ v.property(entry.getKey(), entry.getValue());
+ }
+ }
+
+ return v;
+ }
+
+ /**
+ * Creates an edge from GraphSON using settings supplied in the constructor.
+ */
+ public Edge edgeFromJson(final JSONObject json, final Vertex out, final Vertex in) throws IOException {
+ return this.edgeFromJson(json.toString(), out, in);
+ }
+
+ /**
+ * Creates an edge from GraphSON using settings supplied in the constructor.
+ */
+ public Edge edgeFromJson(final String json, final Vertex out, final Vertex in) throws IOException {
+ final JsonParser jp = jsonFactory.createParser(json);
+ final JsonNode node = jp.readValueAsTree();
+ return this.edgeFromJson(node, out, in);
+ }
+
+ /**
+ * Creates an edge from GraphSON using settings supplied in the constructor.
+ */
+ public Edge edgeFromJson(final InputStream json, final Vertex out, final Vertex in) throws IOException {
+ final JsonParser jp = jsonFactory.createParser(json);
+ final JsonNode node = jp.readValueAsTree();
+ return this.edgeFromJson(node, out, in);
+ }
+
+ /**
+ * Creates an edge from GraphSON using settings supplied in the constructor.
+ */
+ public Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in) throws IOException {
+ final Map<String, Object> props = BlueprintsLegacyGraphSONUtility.readProperties(json, true, this.hasEmbeddedTypes);
+
+ final Object edgeId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
+ final JsonNode nodeLabel = json.get(LegacyGraphSONTokens._LABEL);
+
+ // assigned an empty string edge label in cases where one does not exist. this gets around the requirement
+ // that blueprints graphs have a non-null label while ensuring that GraphSON can stay flexible in parsing
+ // partial bits from the JSON. Not sure if there is any gotchas developing out of this.
+ final String label = nodeLabel == null ? EMPTY_STRING : nodeLabel.textValue();
+
+ final Edge e = factory.createEdge(edgeId, out, in, label);
+
+ for (Map.Entry<String, Object> entry : props.entrySet()) {
+ // if (this.edgePropertyKeys == null || this.edgePropertyKeys.contains(entry.getKey())) {
+ if (includeKey(entry.getKey(), edgePropertyKeys, this.edgePropertiesRule)) {
+ e.property(entry.getKey(), entry.getValue());
+ }
+ }
+
+ return e;
+ }
+
+ /**
+ * Creates GraphSON for a single graph element.
+ */
+ public JSONObject jsonFromElement(final Element element) throws JSONException {
+ final ObjectNode objectNode = this.objectNodeFromElement(element);
+
+ try {
+ return new JSONObject(new JSONTokener(mapper.writeValueAsString(objectNode)));
+ } catch (IOException ioe) {
+ // repackage this as a JSONException...seems sensible as the caller will only know about
+ // the jettison object not being created
+ throw new JSONException(ioe);
+ }
+ }
+
+ /**
+ * Creates GraphSON for a single graph element.
+ */
+ public ObjectNode objectNodeFromElement(final Element element) {
+ final boolean isEdge = element instanceof Edge;
+ final boolean showTypes = mode == GraphSONMode.EXTENDED;
+ final List<String> propertyKeys = isEdge ? this.edgePropertyKeys : this.vertexPropertyKeys;
+ final ElementPropertiesRule elementPropertyConfig = isEdge ? this.edgePropertiesRule : this.vertexPropertiesRule;
+
+ final ObjectNode jsonElement = createJSONMap(createPropertyMap(element, propertyKeys, elementPropertyConfig, normalized), propertyKeys, showTypes);
+
+ //if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) {
+ // putObject(jsonElement, GraphSONTokensTP2._ID, element.id());
+ //}
+
+ // it's important to keep the order of these straight. check Edge first and then Vertex because there
+ // are graph implementations that have Edge extend from Vertex
+ if (isEdge) { //element instanceof Edge) {
+ final Edge edge = (Edge) element;
+
+ if (this.includeReservedEdgeId) {
+ putObject(jsonElement, LegacyGraphSONTokens._ID, element.id());
+ }
+
+ if (this.includeReservedEdgeType) {
+ jsonElement.put(LegacyGraphSONTokens._TYPE, GraphSONTokens.EDGE);
+ }
+
+ if (this.includeReservedEdgeOutV) {
+ putObject(jsonElement, LegacyGraphSONTokens._OUT_V, edge.outVertex().id());
+ }
+
+ if (this.includeReservedEdgeInV) {
+ putObject(jsonElement, LegacyGraphSONTokens._IN_V, edge.inVertex().id());
+ }
+
+ if (this.includeReservedEdgeLabel) {
+ jsonElement.put(LegacyGraphSONTokens._LABEL, edge.label());
+ }
+ } else if (element instanceof Vertex) {
+ if (this.includeReservedVertexId) {
+ putObject(jsonElement, LegacyGraphSONTokens._ID, element.id());
+ }
+
+ if (this.includeReservedVertexType) {
+ jsonElement.put(LegacyGraphSONTokens._TYPE, GraphSONTokens.VERTEX);
+ }
+ }
+
+ return jsonElement;
+ }
+
+ /**
+ * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format.
+ *
+ * @param json a single vertex in GraphSON format as Jettison JSONObject
+ * @param factory the factory responsible for constructing graph elements
+ * @param mode the mode of the GraphSON
+ * @param propertyKeys a list of keys to include on reading of element properties
+ */
+ public static Vertex vertexFromJson(final JSONObject json, final ElementFactory factory, final GraphSONMode mode,
+ final Set<String> propertyKeys) throws IOException {
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, factory, propertyKeys, null);
+ return graphson.vertexFromJson(json);
+ }
+
+ /**
+ * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format.
+ *
+ * @param json a single vertex in GraphSON format as a String.
+ * @param factory the factory responsible for constructing graph elements
+ * @param mode the mode of the GraphSON
+ * @param propertyKeys a list of keys to include on reading of element properties
+ */
+ public static Vertex vertexFromJson(final String json, final ElementFactory factory, final GraphSONMode mode,
+ final Set<String> propertyKeys) throws IOException {
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, factory, propertyKeys, null);
+ return graphson.vertexFromJson(json);
+ }
+
+ /**
+ * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format.
+ *
+ * @param json a single vertex in GraphSON format as an InputStream.
+ * @param factory the factory responsible for constructing graph elements
+ * @param mode the mode of the GraphSON
+ * @param propertyKeys a list of keys to include on reading of element properties
+ */
+ public static Vertex vertexFromJson(final InputStream json, final ElementFactory factory, final GraphSONMode mode,
+ final Set<String> propertyKeys) throws IOException {
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, factory, propertyKeys, null);
+ return graphson.vertexFromJson(json);
+ }
+
+ /**
+ * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format.
+ *
+ * @param json a single vertex in GraphSON format as Jackson JsonNode
+ * @param factory the factory responsible for constructing graph elements
+ * @param mode the mode of the GraphSON
+ * @param propertyKeys a list of keys to include on reading of element properties
+ */
+ public static Vertex vertexFromJson(final JsonNode json, final ElementFactory factory, final GraphSONMode mode,
+ final Set<String> propertyKeys) throws IOException {
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, factory, propertyKeys, null);
+ return graphson.vertexFromJson(json);
+ }
+
+ /**
+ * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format.
+ *
+ * @param json a single edge in GraphSON format as a Jettison JSONObject
+ * @param factory the factory responsible for constructing graph elements
+ * @param mode the mode of the GraphSON
+ * @param propertyKeys a list of keys to include when reading of element properties
+ */
+ public static Edge edgeFromJson(final JSONObject json, final Vertex out, final Vertex in,
+ final ElementFactory factory, final GraphSONMode mode,
+ final Set<String> propertyKeys) throws IOException {
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, factory, null, propertyKeys);
+ return graphson.edgeFromJson(json, out, in);
+ }
+
+ /**
+ * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format.
+ *
+ * @param json a single edge in GraphSON format as a String
+ * @param factory the factory responsible for constructing graph elements
+ * @param mode the mode of the GraphSON
+ * @param propertyKeys a list of keys to include when reading of element properties
+ */
+ public static Edge edgeFromJson(final String json, final Vertex out, final Vertex in,
+ final ElementFactory factory, final GraphSONMode mode,
+ final Set<String> propertyKeys) throws IOException {
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, factory, null, propertyKeys);
+ return graphson.edgeFromJson(json, out, in);
+ }
+
+ /**
+ * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format.
+ *
+ * @param json a single edge in GraphSON format as an InputStream
+ * @param factory the factory responsible for constructing graph elements
+ * @param mode the mode of the GraphSON
+ * @param propertyKeys a list of keys to include when reading of element properties
+ */
+ public static Edge edgeFromJson(final InputStream json, final Vertex out, final Vertex in,
+ final ElementFactory factory, final GraphSONMode mode,
+ final Set<String> propertyKeys) throws IOException {
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, factory, null, propertyKeys);
+ return graphson.edgeFromJson(json, out, in);
+ }
+
+ /**
+ * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format.
+ *
+ * @param json a single edge in GraphSON format as a Jackson JsonNode
+ * @param factory the factory responsible for constructing graph elements
+ * @param mode the mode of the GraphSON
+ * @param propertyKeys a list of keys to include when reading of element properties
+ */
+ public static Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in,
+ final ElementFactory factory, final GraphSONMode mode,
+ final Set<String> propertyKeys) throws IOException {
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, factory, null, propertyKeys);
+ return graphson.edgeFromJson(json, out, in);
+ }
+
+ /**
+ * Creates a Jettison JSONObject from a graph element.
+ *
+ * @param element the graph element to convert to JSON.
+ * @param propertyKeys The property keys at the root of the element to serialize. If null, then all keys are serialized.
+ * @param mode the type of GraphSON to be generated.
+ */
+ public static JSONObject jsonFromElement(final Element element, final Set<String> propertyKeys,
+ final GraphSONMode mode) throws JSONException {
+ ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
+ final BlueprintsLegacyGraphSONUtility graphson = element instanceof Edge ? new BlueprintsLegacyGraphSONUtility(mode, factory, null, propertyKeys)
+ : new BlueprintsLegacyGraphSONUtility(mode, factory, propertyKeys, null);
+ return graphson.jsonFromElement(element);
+ }
+
+ /**
+ * Creates a Jackson ObjectNode from a graph element.
+ *
+ * @param element the graph element to convert to JSON.
+ * @param propertyKeys The property keys at the root of the element to serialize. If null, then all keys are serialized.
+ * @param mode The type of GraphSON to generate.
+ */
+ public static ObjectNode objectNodeFromElement(final Element element, final Set<String> propertyKeys, final GraphSONMode mode) {
+ ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
+ final BlueprintsLegacyGraphSONUtility graphson = element instanceof Edge ? new BlueprintsLegacyGraphSONUtility(mode, factory, null, propertyKeys)
+ : new BlueprintsLegacyGraphSONUtility(mode, factory, propertyKeys, null);
+ return graphson.objectNodeFromElement(element);
+ }
+
+ private static ObjectNode objectNodeFromElement(final Element element, final List<String> propertyKeys, final GraphSONMode mode) {
+ ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
+ Set<String> propKeySet = (propertyKeys!=null)? new HashSet<String>(propertyKeys) : null;
+ final BlueprintsLegacyGraphSONUtility graphson = element instanceof Edge ? new BlueprintsLegacyGraphSONUtility(mode, factory, null, propKeySet)
+ : new BlueprintsLegacyGraphSONUtility(mode, factory, propKeySet, null);
+ return graphson.objectNodeFromElement(element);
+ }
+
+ static Map<String, Object> readProperties(final JsonNode node, final boolean ignoreReservedKeys, final boolean hasEmbeddedTypes) {
+ final Map<String, Object> map = new HashMap<String, Object>();
+
+ final Iterator<Map.Entry<String, JsonNode>> iterator = node.fields();
+ while (iterator.hasNext()) {
+ final Map.Entry<String, JsonNode> entry = iterator.next();
+
+ if (!ignoreReservedKeys || !isReservedKey(entry.getKey())) {
+ // it generally shouldn't be as such but graphson containing null values can't be shoved into
+ // element property keys or it will result in error
+ final Object o = readProperty(entry.getValue(), hasEmbeddedTypes);
+ if (o != null) {
+ map.put(entry.getKey(), o);
+ }
+ }
+ }
+
+ return map;
+ }
+
+ private static boolean includeReservedKey(final GraphSONMode mode, final String key,
+ final List<String> propertyKeys,
+ final ElementPropertiesRule rule) {
+ // the key is always included in modes other than compact. if it is compact, then validate that the
+ // key is in the property key list
+ return mode != GraphSONMode.COMPACT || includeKey(key, propertyKeys, rule);
+ }
+
+ private static boolean includeKey(final String key, final List<String> propertyKeys,
+ final ElementPropertiesRule rule) {
+ if (propertyKeys == null) {
+ // when null always include the key and shortcut this piece
+ return true;
+ }
+
+ // default the key situation. if it's included then it should be explicitly defined in the
+ // property keys list to be included or the reverse otherwise
+ boolean keySituation = rule == ElementPropertiesRule.INCLUDE;
+
+ switch (rule) {
+ case INCLUDE:
+ keySituation = propertyKeys.contains(key);
+ break;
+ case EXCLUDE:
+ keySituation = !propertyKeys.contains(key);
+ break;
+ }
+
+ return keySituation;
+ }
+
+ private static boolean isReservedKey(final String key) {
+ return key.equals(LegacyGraphSONTokens._ID) || key.equals(LegacyGraphSONTokens._TYPE) || key.equals(LegacyGraphSONTokens._LABEL)
+ || key.equals(LegacyGraphSONTokens._OUT_V) || key.equals(LegacyGraphSONTokens._IN_V);
+ }
+
+ private static Object readProperty(final JsonNode node, final boolean hasEmbeddedTypes) {
+ final Object propertyValue;
+
+ if (hasEmbeddedTypes) {
+ if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_UNKNOWN)) {
+ propertyValue = null;
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BOOLEAN)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).booleanValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_FLOAT)) {
+ propertyValue = Float.parseFloat(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BYTE)) {
+ propertyValue = Byte.parseByte(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_SHORT)) {
+ propertyValue = Short.parseShort(node.get(LegacyGraphSONTokens.VALUE).asText());
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_DOUBLE)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).doubleValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_INTEGER)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).intValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LONG)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).longValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_STRING)) {
+ propertyValue = node.get(LegacyGraphSONTokens.VALUE).textValue();
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LIST)) {
+ propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE).elements(), hasEmbeddedTypes);
+ } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_MAP)) {
+ propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE), false, hasEmbeddedTypes);
+ } else {
+ propertyValue = node.textValue();
+ }
+ } else {
+ if (node.isNull()) {
+ propertyValue = null;
+ } else if (node.isBoolean()) {
+ propertyValue = node.booleanValue();
+ } else if (node.isDouble()) {
+ propertyValue = node.doubleValue();
+ } else if (node.isInt()) {
+ propertyValue = node.intValue();
+ } else if (node.isLong()) {
+ propertyValue = node.longValue();
+ } else if (node.isTextual()) {
+ propertyValue = node.textValue();
+ } else if (node.isArray()) {
+ propertyValue = readProperties(node.elements(), hasEmbeddedTypes);
+ } else if (node.isObject()) {
+ propertyValue = readProperties(node, false, hasEmbeddedTypes);
+ } else {
+ propertyValue = node.textValue();
+ }
+ }
+
+ return propertyValue;
+ }
+
+ private static List readProperties(final Iterator<JsonNode> listOfNodes, final boolean hasEmbeddedTypes) {
+ final List array = new ArrayList();
+
+ while (listOfNodes.hasNext()) {
+ array.add(readProperty(listOfNodes.next(), hasEmbeddedTypes));
+ }
+
+ return array;
+ }
+
+ private static ArrayNode createJSONList(final List list, final List<String> propertyKeys, final boolean showTypes) {
+ final ArrayNode jsonList = jsonNodeFactory.arrayNode();
+ for (Object item : list) {
+ if (item instanceof Element) {
+ jsonList.add(objectNodeFromElement((Element) item, propertyKeys,
+ showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL));
+ } else if (item instanceof List) {
+ jsonList.add(createJSONList((List) item, propertyKeys, showTypes));
+ } else if (item instanceof Map) {
+ jsonList.add(createJSONMap((Map) item, propertyKeys, showTypes));
+ } else if (item != null && item.getClass().isArray()) {
+ jsonList.add(createJSONList(convertArrayToList(item), propertyKeys, showTypes));
+ } else {
+ addObject(jsonList, item);
+ }
+ }
+ return jsonList;
+ }
+
+ private static ObjectNode createJSONMap(final Map map, final List<String> propertyKeys, final boolean showTypes) {
+ final ObjectNode jsonMap = jsonNodeFactory.objectNode();
+ for (Object key : map.keySet()) {
+ Object value = map.get(key);
+ if (value != null) {
+ if (value instanceof List) {
+ value = createJSONList((List) value, propertyKeys, showTypes);
+ } else if (value instanceof Iterable){
+ value = createJSONList(getList((Iterable) value), propertyKeys, showTypes);
+ } else if (value instanceof Iterator){
+ value = createJSONList(getList((Iterator) value), propertyKeys, showTypes);
+ } else if (value instanceof Map) {
+ value = createJSONMap((Map) value, propertyKeys, showTypes);
+ } else if (value instanceof Element) {
+ value = objectNodeFromElement((Element) value, propertyKeys,
+ showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL);
+ } else if (value.getClass().isArray()) {
+ value = createJSONList(convertArrayToList(value), propertyKeys, showTypes);
+ }
+ }
+
+ putObject(jsonMap, key.toString(), getValue(value, showTypes));
+ }
+ return jsonMap;
+
+ }
+
+ private static List getList(final Iterable value) {
+ return getList(value.iterator());
+ }
+
+ private static List getList(final Iterator value) {
+ final List result = new ArrayList();
+ while (value.hasNext()) {
+ result.add(value.next());
+ }
+ return result;
+ }
+
+ private static void addObject(final ArrayNode jsonList, final Object value) {
+ if (value == null) {
+ jsonList.add((JsonNode) null);
+ } else if (value.getClass() == Boolean.class) {
+ jsonList.add((Boolean) value);
+ } else if (value.getClass() == Long.class) {
+ jsonList.add((Long) value);
+ } else if (value.getClass() == Integer.class) {
+ jsonList.add((Integer) value);
+ } else if (value.getClass() == Float.class) {
+ jsonList.add((Float) value);
+ } else if (value.getClass() == Double.class) {
+ jsonList.add((Double) value);
+ } else if (value.getClass() == Byte.class) {
+ jsonList.add((Byte) value);
+ } else if (value.getClass() == Short.class) {
+ jsonList.add((Short) value);
+ } else if (value.getClass() == String.class) {
+ jsonList.add((String) value);
+ } else if (value instanceof ObjectNode) {
+ jsonList.add((ObjectNode) value);
+ } else if (value instanceof ArrayNode) {
+ jsonList.add((ArrayNode) value);
+ } else {
+ jsonList.add(value.toString());
+ }
+ }
+
+ private static void putObject(final ObjectNode jsonMap, final String key, final Object value) {
+ if (value == null) {
+ jsonMap.put(key, (JsonNode) null);
+ } else if (value.getClass() == Boolean.class) {
+ jsonMap.put(key, (Boolean) value);
+ } else if (value.getClass() == Long.class) {
+ jsonMap.put(key, (Long) value);
+ } else if (value.getClass() == Integer.class) {
+ jsonMap.put(key, (Integer) value);
+ } else if (value.getClass() == Float.class) {
+ jsonMap.put(key, (Float) value);
+ } else if (value.getClass() == Double.class) {
+ jsonMap.put(key, (Double) value);
+ } else if (value.getClass() == Short.class) {
+ jsonMap.put(key, (Short) value);
+ } else if (value.getClass() == Byte.class) {
+ jsonMap.put(key, (Byte) value);
+ } else if (value.getClass() == String.class) {
+ jsonMap.put(key, (String) value);
+ } else if (value instanceof ObjectNode) {
+ jsonMap.put(key, (ObjectNode) value);
+ } else if (value instanceof ArrayNode) {
+ jsonMap.put(key, (ArrayNode) value);
+ } else {
+ jsonMap.put(key, value.toString());
+ }
+ }
+
+ private static Map createPropertyMap(final Element element, final List<String> propertyKeys,
+ final ElementPropertiesRule rule, final boolean normalized) {
+ final Map map = new HashMap<String, Object>();
+ final List<String> propertyKeyList;
+ if (normalized) {
+ final List<String> sorted = new ArrayList<String>(element.keys());
+ Collections.sort(sorted);
+ propertyKeyList = sorted;
+ } else
+ propertyKeyList = new ArrayList<String>(element.keys());
+
+ if (propertyKeys == null) {
+ for (String key : propertyKeyList) {
+ final Object valToPutInMap = element.property(key).value();
+ if (valToPutInMap != null) {
+ map.put(key, valToPutInMap);
+ }
+ }
+ } else {
+ if (rule == ElementPropertiesRule.INCLUDE) {
+ for (String key : propertyKeys) {
+ final Object valToPutInMap = element.property(key).value();
+ if (valToPutInMap != null) {
+ map.put(key, valToPutInMap);
+ }
+ }
+ } else {
+ for (String key : propertyKeyList) {
+ if (!propertyKeys.contains(key)) {
+ final Object valToPutInMap = element.property(key).value();
+ if (valToPutInMap != null) {
+ map.put(key, valToPutInMap);
+ }
+ }
+ }
+ }
+ }
+
+ return map;
+ }
+
+ private static Object getValue(Object value, final boolean includeType) {
+
+ Object returnValue = value;
+
+ // if the includeType is set to true then show the data types of the properties
+ if (includeType) {
+
+ // type will be one of: map, list, string, long, int, double, float.
+ // in the event of a complex object it will call a toString and store as a
+ // string
+ String type = determineType(value);
+
+ ObjectNode valueAndType = jsonNodeFactory.objectNode();
+ valueAndType.put(GraphSONTokens.TYPE, type);
+
+ if (type.equals(LegacyGraphSONTokens.TYPE_LIST)) {
+
+ // values of lists must be accumulated as ObjectNode objects under the value key.
+ // will return as a ArrayNode. called recursively to traverse the entire
+ // object graph of each item in the array.
+ ArrayNode list = (ArrayNode) value;
+
+ // there is a set of values that must be accumulated as an array under a key
+ ArrayNode valueArray = valueAndType.putArray(GraphSONTokens.VALUE);
+ for (int ix = 0; ix < list.size(); ix++) {
+ // the value of each item in the array is a node object from an ArrayNode...must
+ // get the value of it.
+ addObject(valueArray, getValue(getTypedValueFromJsonNode(list.get(ix)), includeType));
+ }
+
+ } else if (type.equals(LegacyGraphSONTokens.TYPE_MAP)) {
+
+ // maps are converted to a ObjectNode. called recursively to traverse
+ // the entire object graph within the map.
+ ObjectNode convertedMap = jsonNodeFactory.objectNode();
+ ObjectNode jsonObject = (ObjectNode) value;
+ Iterator keyIterator = jsonObject.fieldNames();
+ while (keyIterator.hasNext()) {
+ Object key = keyIterator.next();
+
+ // no need to getValue() here as this is already a ObjectNode and should have type info
+ convertedMap.put(key.toString(), jsonObject.get(key.toString()));
+ }
+
+ valueAndType.put(GraphSONTokens.VALUE, convertedMap);
+ } else {
+
+ // this must be a primitive value or a complex object. if a complex
+ // object it will be handled by a call to toString and stored as a
+ // string value
+ putObject(valueAndType, GraphSONTokens.VALUE, value);
+ }
+
+ // this goes back as a JSONObject with data type and value
+ returnValue = valueAndType;
+ }
+
+ return returnValue;
+ }
+
+ static Object getTypedValueFromJsonNode(JsonNode node) {
+ Object theValue = null;
+
+ if (node != null && !node.isNull()) {
+ if (node.isBoolean()) {
+ theValue = node.booleanValue();
+ } else if (node.isDouble()) {
+ theValue = node.doubleValue();
+ } else if (node.isFloatingPointNumber()) {
+ theValue = node.floatValue();
+ } else if (node.isInt()) {
+ theValue = node.intValue();
+ } else if (node.isLong()) {
+ theValue = node.longValue();
+ } else if (node.isTextual()) {
+ theValue = node.textValue();
+ } else if (node.isArray()) {
+ // this is an array so just send it back so that it can be
+ // reprocessed to its primitive components
+ theValue = node;
+ } else if (node.isObject()) {
+ // this is an object so just send it back so that it can be
+ // reprocessed to its primitive components
+ theValue = node;
+ } else {
+ theValue = node.textValue();
+ }
+ }
+
+ return theValue;
+ }
+
+ private static List convertArrayToList(final Object value) {
+ final ArrayList<Object> list = new ArrayList<Object>();
+ int arrlength = Array.getLength(value);
+ for (int i = 0; i < arrlength; i++) {
+ Object object = Array.get(value, i);
+ list.add(object);
+ }
+ return list;
+ }
+
+ private static String determineType(final Object value) {
+ String type = LegacyGraphSONTokens.TYPE_STRING;
+ if (value == null) {
+ type = LegacyGraphSONTokens.TYPE_UNKNOWN;
+ } else if (value.getClass() == Double.class) {
+ type = LegacyGraphSONTokens.TYPE_DOUBLE;
+ } else if (value.getClass() == Float.class) {
+ type = LegacyGraphSONTokens.TYPE_FLOAT;
+ } else if (value.getClass() == Byte.class) {
+ type = LegacyGraphSONTokens.TYPE_BYTE;
+ } else if (value.getClass() == Short.class) {
+ type = LegacyGraphSONTokens.TYPE_SHORT;
+ } else if (value.getClass() == Integer.class) {
+ type = LegacyGraphSONTokens.TYPE_INTEGER;
+ } else if (value.getClass() == Long.class) {
+ type = LegacyGraphSONTokens.TYPE_LONG;
+ } else if (value.getClass() == Boolean.class) {
+ type = LegacyGraphSONTokens.TYPE_BOOLEAN;
+ } else if (value instanceof ArrayNode) {
+ type = LegacyGraphSONTokens.TYPE_LIST;
+ } else if (value instanceof ObjectNode) {
+ type = LegacyGraphSONTokens.TYPE_MAP;
+ }
+
+ return type;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/641af9be/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java
index f48ebae..42fae3c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyReader.java
@@ -155,7 +155,7 @@ public final class GraphSONLegacyReader implements GraphReader {
final JsonNode node = parser.readValueAsTree();
//final Map<String, Object> vertexData = LegacyGraphSONUtility.readProperties(node);
- final Map<String, Object> vertexData = TP2GraphSONUtility.readProperties(node, false, false);
+ final Map<String, Object> vertexData = BlueprintsLegacyGraphSONUtility.readProperties(node, false, false);
//starGraph.addVertex(T.id, vertexData.get(GraphSONTokensTP2._ID), T.label, vertexData.get(GraphSONTokensTP2._LABEL));
starGraph.addVertex(T.id, vertexData.get(LegacyGraphSONTokens._ID)); //
for (Map.Entry<String, Object> p : vertexData.entrySet()) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/641af9be/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
index 3737ff9..c1a7982 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
@@ -25,7 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.TP2GraphSONUtility.GraphSONMode;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.BlueprintsLegacyGraphSONUtility.GraphSONMode;
import org.codehaus.jettison.json.JSONException;
import java.io.*;
@@ -101,7 +101,7 @@ public class GraphSONLegacyWriter {
// don't let the JsonGenerator close the underlying stream...leave that to the client passing in the stream
jg.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, null,
+ final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(mode, null,
ElementPropertyConfig.includeProperties(vertexPropertyKeys, edgePropertyKeys, normalize));
jg.writeStartObject();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/641af9be/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java
index 264d320..d53a797 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java
@@ -22,8 +22,8 @@ import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.TP2GraphSONUtility.ElementFactory;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.TP2GraphSONUtility.GraphSONMode;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.BlueprintsLegacyGraphSONUtility.ElementFactory;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.BlueprintsLegacyGraphSONUtility.GraphSONMode;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
import org.codehaus.jettison.json.JSONArray;
@@ -57,7 +57,7 @@ public class HadoopLegacyGraphSONUtility {
private static final ElementFactory elementFactory = new MyElementFactory();
- private static final TP2GraphSONUtility graphson = new TP2GraphSONUtility(GraphSONMode.COMPACT, elementFactory,
+ private static final BlueprintsLegacyGraphSONUtility graphson = new BlueprintsLegacyGraphSONUtility(GraphSONMode.COMPACT, elementFactory,
ElementPropertyConfig.excludeProperties(VERTEX_IGNORE, EDGE_IGNORE));
public static List<Vertex> fromJSON(final InputStream in) throws IOException {
@@ -111,7 +111,7 @@ public class HadoopLegacyGraphSONUtility {
public static JSONObject toJSON(final Vertex vertex) throws IOException {
try {
//final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, getElementPropertyKeys(vertex, false), GraphSONMode.COMPACT);
- final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, null, GraphSONMode.COMPACT);
+ final JSONObject object = BlueprintsLegacyGraphSONUtility.jsonFromElement(vertex, null, GraphSONMode.COMPACT);
// force the ID to long. with blueprints, most implementations will send back a long, but
// some like TinkerGraph will return a string. the same is done for edges below
@@ -123,7 +123,7 @@ public class HadoopLegacyGraphSONUtility {
final JSONArray outEdgesArray = new JSONArray();
for (final Edge outEdge : edges) {
//final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, getElementPropertyKeys(outEdge, true), GraphSONMode.COMPACT);
- final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, null, GraphSONMode.COMPACT);
+ final JSONObject edgeObject = BlueprintsLegacyGraphSONUtility.jsonFromElement(outEdge, null, GraphSONMode.COMPACT);
outEdgesArray.put(edgeObject);
}
object.put(LegacyGraphSONTokens._OUT_E, outEdgesArray);
@@ -134,7 +134,7 @@ public class HadoopLegacyGraphSONUtility {
final JSONArray inEdgesArray = new JSONArray();
for (final Edge inEdge : edges) {
//final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, getElementPropertyKeys(inEdge, false), GraphSONMode.COMPACT);
- final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, null, GraphSONMode.COMPACT);
+ final JSONObject edgeObject = BlueprintsLegacyGraphSONUtility.jsonFromElement(inEdge, null, GraphSONMode.COMPACT);
inEdgesArray.put(edgeObject);
}
object.put(LegacyGraphSONTokens._IN_E, inEdgesArray);
[3/6] incubator-tinkerpop git commit: Renamed class for consistency
with TP3.
Posted by sp...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/641af9be/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
deleted file mode 100644
index e8beb85..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
+++ /dev/null
@@ -1,873 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.io.graphson;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.MappingJsonFactory;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.ElementPropertyConfig.ElementPropertiesRule;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-import org.codehaus.jettison.json.JSONTokener;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Array;
-import java.util.*;
-
-//import com.tinkerpop.blueprints.Direction;
-//import com.tinkerpop.blueprints.Element;
-
-/**
- * Helps write individual graph elements to TinkerPop JSON format known as GraphSON.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class TP2GraphSONUtility {
-
- /**
- * Modes of operation of the GraphSONUtility.
- *
- * @author Stephen Mallette
- */
- public enum GraphSONMode {
- /**
- * COMPACT constructs GraphSON on the assumption that all property keys
- * are fair game for exclusion including _type, _inV, _outV, _label and _id.
- * It is possible to write GraphSON that cannot be read back into Graph,
- * if some or all of these keys are excluded.
- */
- COMPACT,
-
- /**
- * NORMAL includes the _type field and JSON data typing.
- */
- NORMAL,
-
- /**
- * EXTENDED includes the _type field and explicit data typing.
- */
- EXTENDED
- }
-
- /**
- * A factory responsible for creating graph elements. Abstracts the way that graph elements are created. In
- * most cases a Graph is responsible for element creation, but there are cases where more control over
- * how vertices and edges are constructed.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
- public interface ElementFactory<V extends Vertex, E extends Edge> {
- /**
- * Creates a new Edge instance.
- */
- E createEdge(final Object id, final V out, final V in, final String label);
-
- /**
- * Creates a new Vertex instance.
- */
- V createVertex(final Object id);
- }
-
- private static final JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
- private static final JsonFactory jsonFactory = new MappingJsonFactory();
- private static final String EMPTY_STRING = "";
-
- private static final ObjectMapper mapper = new ObjectMapper();
-
- private final GraphSONMode mode;
- private final List<String> vertexPropertyKeys;
- private final List<String> edgePropertyKeys;
- private final ElementFactory factory;
- private final boolean hasEmbeddedTypes;
- private final ElementPropertiesRule vertexPropertiesRule;
- private final ElementPropertiesRule edgePropertiesRule;
- private final boolean normalized;
-
- private final boolean includeReservedVertexId;
- private final boolean includeReservedEdgeId;
- private final boolean includeReservedVertexType;
- private final boolean includeReservedEdgeType;
- private final boolean includeReservedEdgeLabel;
- private final boolean includeReservedEdgeOutV;
- private final boolean includeReservedEdgeInV;
-
- /**
- * A GraphSONUtiltiy that includes all properties of vertices and edges.
- */
- public TP2GraphSONUtility(final GraphSONMode mode, final ElementFactory factory) {
- this(mode, factory, ElementPropertyConfig.AllProperties);
- }
-
- /**
- * A GraphSONUtility that includes the specified properties.
- */
- public TP2GraphSONUtility(final GraphSONMode mode, final ElementFactory factory,
- final Set<String> vertexPropertyKeys, final Set<String> edgePropertyKeys) {
- this(mode, factory, ElementPropertyConfig.includeProperties(vertexPropertyKeys, edgePropertyKeys));
- }
-
- public TP2GraphSONUtility(final GraphSONMode mode, final ElementFactory factory,
- final ElementPropertyConfig config) {
- this.vertexPropertyKeys = config.getVertexPropertyKeys();
- this.edgePropertyKeys = config.getEdgePropertyKeys();
- this.vertexPropertiesRule = config.getVertexPropertiesRule();
- this.edgePropertiesRule = config.getEdgePropertiesRule();
- this.normalized = config.isNormalized();
-
- this.mode = mode;
- this.factory = factory;
- this.hasEmbeddedTypes = mode == GraphSONMode.EXTENDED;
-
- this.includeReservedVertexId = includeReservedKey(mode, LegacyGraphSONTokens._ID, vertexPropertyKeys, this.vertexPropertiesRule);
- this.includeReservedEdgeId = includeReservedKey(mode, LegacyGraphSONTokens._ID, edgePropertyKeys, this.edgePropertiesRule);
- this.includeReservedVertexType = includeReservedKey(mode, LegacyGraphSONTokens._TYPE, vertexPropertyKeys, this.vertexPropertiesRule);
- this.includeReservedEdgeType = includeReservedKey(mode, LegacyGraphSONTokens._TYPE, edgePropertyKeys, this.edgePropertiesRule);
- this.includeReservedEdgeLabel = includeReservedKey(mode, LegacyGraphSONTokens._LABEL, edgePropertyKeys, this.edgePropertiesRule);
- this.includeReservedEdgeOutV = includeReservedKey(mode, LegacyGraphSONTokens._OUT_V, edgePropertyKeys, this.edgePropertiesRule);
- this.includeReservedEdgeInV = includeReservedKey(mode, LegacyGraphSONTokens._IN_V, edgePropertyKeys, this.edgePropertiesRule);
- }
-
- /**
- * Creates a vertex from GraphSON using settings supplied in the constructor.
- */
- public Vertex vertexFromJson(final JSONObject json) throws IOException {
- return this.vertexFromJson(json.toString());
- }
-
- /**
- * Creates a vertex from GraphSON using settings supplied in the constructor.
- */
- public Vertex vertexFromJson(final String json) throws IOException {
- final JsonParser jp = jsonFactory.createParser(json);
- final JsonNode node = jp.readValueAsTree();
- return this.vertexFromJson(node);
- }
-
- /**
- * Creates a vertex from GraphSON using settings supplied in the constructor.
- */
- public Vertex vertexFromJson(final InputStream json) throws IOException {
- final JsonParser jp = jsonFactory.createParser(json);
- final JsonNode node = jp.readValueAsTree();
- return this.vertexFromJson(node);
- }
-
- /**
- * Creates a vertex from GraphSON using settings supplied in the constructor.
- */
- public Vertex vertexFromJson(final JsonNode json) throws IOException {
- final Map<String, Object> props = readProperties(json, true, this.hasEmbeddedTypes);
-
- final Object vertexId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
- final Vertex v = factory.createVertex(vertexId);
-
- for (Map.Entry<String, Object> entry : props.entrySet()) {
- //if (this.vertexPropertyKeys == null || vertexPropertyKeys.contains(entry.getKey())) {
- if (includeKey(entry.getKey(), vertexPropertyKeys, this.vertexPropertiesRule)) {
- v.property(entry.getKey(), entry.getValue());
- }
- }
-
- return v;
- }
-
- /**
- * Creates an edge from GraphSON using settings supplied in the constructor.
- */
- public Edge edgeFromJson(final JSONObject json, final Vertex out, final Vertex in) throws IOException {
- return this.edgeFromJson(json.toString(), out, in);
- }
-
- /**
- * Creates an edge from GraphSON using settings supplied in the constructor.
- */
- public Edge edgeFromJson(final String json, final Vertex out, final Vertex in) throws IOException {
- final JsonParser jp = jsonFactory.createParser(json);
- final JsonNode node = jp.readValueAsTree();
- return this.edgeFromJson(node, out, in);
- }
-
- /**
- * Creates an edge from GraphSON using settings supplied in the constructor.
- */
- public Edge edgeFromJson(final InputStream json, final Vertex out, final Vertex in) throws IOException {
- final JsonParser jp = jsonFactory.createParser(json);
- final JsonNode node = jp.readValueAsTree();
- return this.edgeFromJson(node, out, in);
- }
-
- /**
- * Creates an edge from GraphSON using settings supplied in the constructor.
- */
- public Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in) throws IOException {
- final Map<String, Object> props = TP2GraphSONUtility.readProperties(json, true, this.hasEmbeddedTypes);
-
- final Object edgeId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
- final JsonNode nodeLabel = json.get(LegacyGraphSONTokens._LABEL);
-
- // assigned an empty string edge label in cases where one does not exist. this gets around the requirement
- // that blueprints graphs have a non-null label while ensuring that GraphSON can stay flexible in parsing
- // partial bits from the JSON. Not sure if there is any gotchas developing out of this.
- final String label = nodeLabel == null ? EMPTY_STRING : nodeLabel.textValue();
-
- final Edge e = factory.createEdge(edgeId, out, in, label);
-
- for (Map.Entry<String, Object> entry : props.entrySet()) {
- // if (this.edgePropertyKeys == null || this.edgePropertyKeys.contains(entry.getKey())) {
- if (includeKey(entry.getKey(), edgePropertyKeys, this.edgePropertiesRule)) {
- e.property(entry.getKey(), entry.getValue());
- }
- }
-
- return e;
- }
-
- /**
- * Creates GraphSON for a single graph element.
- */
- public JSONObject jsonFromElement(final Element element) throws JSONException {
- final ObjectNode objectNode = this.objectNodeFromElement(element);
-
- try {
- return new JSONObject(new JSONTokener(mapper.writeValueAsString(objectNode)));
- } catch (IOException ioe) {
- // repackage this as a JSONException...seems sensible as the caller will only know about
- // the jettison object not being created
- throw new JSONException(ioe);
- }
- }
-
- /**
- * Creates GraphSON for a single graph element.
- */
- public ObjectNode objectNodeFromElement(final Element element) {
- final boolean isEdge = element instanceof Edge;
- final boolean showTypes = mode == GraphSONMode.EXTENDED;
- final List<String> propertyKeys = isEdge ? this.edgePropertyKeys : this.vertexPropertyKeys;
- final ElementPropertiesRule elementPropertyConfig = isEdge ? this.edgePropertiesRule : this.vertexPropertiesRule;
-
- final ObjectNode jsonElement = createJSONMap(createPropertyMap(element, propertyKeys, elementPropertyConfig, normalized), propertyKeys, showTypes);
-
- //if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) {
- // putObject(jsonElement, GraphSONTokensTP2._ID, element.id());
- //}
-
- // it's important to keep the order of these straight. check Edge first and then Vertex because there
- // are graph implementations that have Edge extend from Vertex
- if (isEdge) { //element instanceof Edge) {
- final Edge edge = (Edge) element;
-
- if (this.includeReservedEdgeId) {
- putObject(jsonElement, LegacyGraphSONTokens._ID, element.id());
- }
-
- if (this.includeReservedEdgeType) {
- jsonElement.put(LegacyGraphSONTokens._TYPE, GraphSONTokens.EDGE);
- }
-
- if (this.includeReservedEdgeOutV) {
- putObject(jsonElement, LegacyGraphSONTokens._OUT_V, edge.outVertex().id());
- }
-
- if (this.includeReservedEdgeInV) {
- putObject(jsonElement, LegacyGraphSONTokens._IN_V, edge.inVertex().id());
- }
-
- if (this.includeReservedEdgeLabel) {
- jsonElement.put(LegacyGraphSONTokens._LABEL, edge.label());
- }
- } else if (element instanceof Vertex) {
- if (this.includeReservedVertexId) {
- putObject(jsonElement, LegacyGraphSONTokens._ID, element.id());
- }
-
- if (this.includeReservedVertexType) {
- jsonElement.put(LegacyGraphSONTokens._TYPE, GraphSONTokens.VERTEX);
- }
- }
-
- return jsonElement;
- }
-
- /**
- * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format.
- *
- * @param json a single vertex in GraphSON format as Jettison JSONObject
- * @param factory the factory responsible for constructing graph elements
- * @param mode the mode of the GraphSON
- * @param propertyKeys a list of keys to include on reading of element properties
- */
- public static Vertex vertexFromJson(final JSONObject json, final ElementFactory factory, final GraphSONMode mode,
- final Set<String> propertyKeys) throws IOException {
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, factory, propertyKeys, null);
- return graphson.vertexFromJson(json);
- }
-
- /**
- * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format.
- *
- * @param json a single vertex in GraphSON format as a String.
- * @param factory the factory responsible for constructing graph elements
- * @param mode the mode of the GraphSON
- * @param propertyKeys a list of keys to include on reading of element properties
- */
- public static Vertex vertexFromJson(final String json, final ElementFactory factory, final GraphSONMode mode,
- final Set<String> propertyKeys) throws IOException {
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, factory, propertyKeys, null);
- return graphson.vertexFromJson(json);
- }
-
- /**
- * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format.
- *
- * @param json a single vertex in GraphSON format as an InputStream.
- * @param factory the factory responsible for constructing graph elements
- * @param mode the mode of the GraphSON
- * @param propertyKeys a list of keys to include on reading of element properties
- */
- public static Vertex vertexFromJson(final InputStream json, final ElementFactory factory, final GraphSONMode mode,
- final Set<String> propertyKeys) throws IOException {
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, factory, propertyKeys, null);
- return graphson.vertexFromJson(json);
- }
-
- /**
- * Reads an individual Vertex from JSON. The vertex must match the accepted GraphSON format.
- *
- * @param json a single vertex in GraphSON format as Jackson JsonNode
- * @param factory the factory responsible for constructing graph elements
- * @param mode the mode of the GraphSON
- * @param propertyKeys a list of keys to include on reading of element properties
- */
- public static Vertex vertexFromJson(final JsonNode json, final ElementFactory factory, final GraphSONMode mode,
- final Set<String> propertyKeys) throws IOException {
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, factory, propertyKeys, null);
- return graphson.vertexFromJson(json);
- }
-
- /**
- * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format.
- *
- * @param json a single edge in GraphSON format as a Jettison JSONObject
- * @param factory the factory responsible for constructing graph elements
- * @param mode the mode of the GraphSON
- * @param propertyKeys a list of keys to include when reading of element properties
- */
- public static Edge edgeFromJson(final JSONObject json, final Vertex out, final Vertex in,
- final ElementFactory factory, final GraphSONMode mode,
- final Set<String> propertyKeys) throws IOException {
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, factory, null, propertyKeys);
- return graphson.edgeFromJson(json, out, in);
- }
-
- /**
- * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format.
- *
- * @param json a single edge in GraphSON format as a String
- * @param factory the factory responsible for constructing graph elements
- * @param mode the mode of the GraphSON
- * @param propertyKeys a list of keys to include when reading of element properties
- */
- public static Edge edgeFromJson(final String json, final Vertex out, final Vertex in,
- final ElementFactory factory, final GraphSONMode mode,
- final Set<String> propertyKeys) throws IOException {
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, factory, null, propertyKeys);
- return graphson.edgeFromJson(json, out, in);
- }
-
- /**
- * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format.
- *
- * @param json a single edge in GraphSON format as an InputStream
- * @param factory the factory responsible for constructing graph elements
- * @param mode the mode of the GraphSON
- * @param propertyKeys a list of keys to include when reading of element properties
- */
- public static Edge edgeFromJson(final InputStream json, final Vertex out, final Vertex in,
- final ElementFactory factory, final GraphSONMode mode,
- final Set<String> propertyKeys) throws IOException {
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, factory, null, propertyKeys);
- return graphson.edgeFromJson(json, out, in);
- }
-
- /**
- * Reads an individual Edge from JSON. The edge must match the accepted GraphSON format.
- *
- * @param json a single edge in GraphSON format as a Jackson JsonNode
- * @param factory the factory responsible for constructing graph elements
- * @param mode the mode of the GraphSON
- * @param propertyKeys a list of keys to include when reading of element properties
- */
- public static Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in,
- final ElementFactory factory, final GraphSONMode mode,
- final Set<String> propertyKeys) throws IOException {
- final TP2GraphSONUtility graphson = new TP2GraphSONUtility(mode, factory, null, propertyKeys);
- return graphson.edgeFromJson(json, out, in);
- }
-
- /**
- * Creates a Jettison JSONObject from a graph element.
- *
- * @param element the graph element to convert to JSON.
- * @param propertyKeys The property keys at the root of the element to serialize. If null, then all keys are serialized.
- * @param mode the type of GraphSON to be generated.
- */
- public static JSONObject jsonFromElement(final Element element, final Set<String> propertyKeys,
- final GraphSONMode mode) throws JSONException {
- ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
- final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propertyKeys)
- : new TP2GraphSONUtility(mode, factory, propertyKeys, null);
- return graphson.jsonFromElement(element);
- }
-
- /**
- * Creates a Jackson ObjectNode from a graph element.
- *
- * @param element the graph element to convert to JSON.
- * @param propertyKeys The property keys at the root of the element to serialize. If null, then all keys are serialized.
- * @param mode The type of GraphSON to generate.
- */
- public static ObjectNode objectNodeFromElement(final Element element, final Set<String> propertyKeys, final GraphSONMode mode) {
- ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
- final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propertyKeys)
- : new TP2GraphSONUtility(mode, factory, propertyKeys, null);
- return graphson.objectNodeFromElement(element);
- }
-
- private static ObjectNode objectNodeFromElement(final Element element, final List<String> propertyKeys, final GraphSONMode mode) {
- ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
- Set<String> propKeySet = (propertyKeys!=null)? new HashSet<String>(propertyKeys) : null;
- final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propKeySet)
- : new TP2GraphSONUtility(mode, factory, propKeySet, null);
- return graphson.objectNodeFromElement(element);
- }
-
- static Map<String, Object> readProperties(final JsonNode node, final boolean ignoreReservedKeys, final boolean hasEmbeddedTypes) {
- final Map<String, Object> map = new HashMap<String, Object>();
-
- final Iterator<Map.Entry<String, JsonNode>> iterator = node.fields();
- while (iterator.hasNext()) {
- final Map.Entry<String, JsonNode> entry = iterator.next();
-
- if (!ignoreReservedKeys || !isReservedKey(entry.getKey())) {
- // it generally shouldn't be as such but graphson containing null values can't be shoved into
- // element property keys or it will result in error
- final Object o = readProperty(entry.getValue(), hasEmbeddedTypes);
- if (o != null) {
- map.put(entry.getKey(), o);
- }
- }
- }
-
- return map;
- }
-
- private static boolean includeReservedKey(final GraphSONMode mode, final String key,
- final List<String> propertyKeys,
- final ElementPropertiesRule rule) {
- // the key is always included in modes other than compact. if it is compact, then validate that the
- // key is in the property key list
- return mode != GraphSONMode.COMPACT || includeKey(key, propertyKeys, rule);
- }
-
- private static boolean includeKey(final String key, final List<String> propertyKeys,
- final ElementPropertiesRule rule) {
- if (propertyKeys == null) {
- // when null always include the key and shortcut this piece
- return true;
- }
-
- // default the key situation. if it's included then it should be explicitly defined in the
- // property keys list to be included or the reverse otherwise
- boolean keySituation = rule == ElementPropertiesRule.INCLUDE;
-
- switch (rule) {
- case INCLUDE:
- keySituation = propertyKeys.contains(key);
- break;
- case EXCLUDE:
- keySituation = !propertyKeys.contains(key);
- break;
- }
-
- return keySituation;
- }
-
- private static boolean isReservedKey(final String key) {
- return key.equals(LegacyGraphSONTokens._ID) || key.equals(LegacyGraphSONTokens._TYPE) || key.equals(LegacyGraphSONTokens._LABEL)
- || key.equals(LegacyGraphSONTokens._OUT_V) || key.equals(LegacyGraphSONTokens._IN_V);
- }
-
- private static Object readProperty(final JsonNode node, final boolean hasEmbeddedTypes) {
- final Object propertyValue;
-
- if (hasEmbeddedTypes) {
- if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_UNKNOWN)) {
- propertyValue = null;
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BOOLEAN)) {
- propertyValue = node.get(LegacyGraphSONTokens.VALUE).booleanValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_FLOAT)) {
- propertyValue = Float.parseFloat(node.get(LegacyGraphSONTokens.VALUE).asText());
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BYTE)) {
- propertyValue = Byte.parseByte(node.get(LegacyGraphSONTokens.VALUE).asText());
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_SHORT)) {
- propertyValue = Short.parseShort(node.get(LegacyGraphSONTokens.VALUE).asText());
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_DOUBLE)) {
- propertyValue = node.get(LegacyGraphSONTokens.VALUE).doubleValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_INTEGER)) {
- propertyValue = node.get(LegacyGraphSONTokens.VALUE).intValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LONG)) {
- propertyValue = node.get(LegacyGraphSONTokens.VALUE).longValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_STRING)) {
- propertyValue = node.get(LegacyGraphSONTokens.VALUE).textValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LIST)) {
- propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE).elements(), hasEmbeddedTypes);
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_MAP)) {
- propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE), false, hasEmbeddedTypes);
- } else {
- propertyValue = node.textValue();
- }
- } else {
- if (node.isNull()) {
- propertyValue = null;
- } else if (node.isBoolean()) {
- propertyValue = node.booleanValue();
- } else if (node.isDouble()) {
- propertyValue = node.doubleValue();
- } else if (node.isInt()) {
- propertyValue = node.intValue();
- } else if (node.isLong()) {
- propertyValue = node.longValue();
- } else if (node.isTextual()) {
- propertyValue = node.textValue();
- } else if (node.isArray()) {
- propertyValue = readProperties(node.elements(), hasEmbeddedTypes);
- } else if (node.isObject()) {
- propertyValue = readProperties(node, false, hasEmbeddedTypes);
- } else {
- propertyValue = node.textValue();
- }
- }
-
- return propertyValue;
- }
-
- private static List readProperties(final Iterator<JsonNode> listOfNodes, final boolean hasEmbeddedTypes) {
- final List array = new ArrayList();
-
- while (listOfNodes.hasNext()) {
- array.add(readProperty(listOfNodes.next(), hasEmbeddedTypes));
- }
-
- return array;
- }
-
- private static ArrayNode createJSONList(final List list, final List<String> propertyKeys, final boolean showTypes) {
- final ArrayNode jsonList = jsonNodeFactory.arrayNode();
- for (Object item : list) {
- if (item instanceof Element) {
- jsonList.add(objectNodeFromElement((Element) item, propertyKeys,
- showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL));
- } else if (item instanceof List) {
- jsonList.add(createJSONList((List) item, propertyKeys, showTypes));
- } else if (item instanceof Map) {
- jsonList.add(createJSONMap((Map) item, propertyKeys, showTypes));
- } else if (item != null && item.getClass().isArray()) {
- jsonList.add(createJSONList(convertArrayToList(item), propertyKeys, showTypes));
- } else {
- addObject(jsonList, item);
- }
- }
- return jsonList;
- }
-
- private static ObjectNode createJSONMap(final Map map, final List<String> propertyKeys, final boolean showTypes) {
- final ObjectNode jsonMap = jsonNodeFactory.objectNode();
- for (Object key : map.keySet()) {
- Object value = map.get(key);
- if (value != null) {
- if (value instanceof List) {
- value = createJSONList((List) value, propertyKeys, showTypes);
- } else if (value instanceof Iterable){
- value = createJSONList(getList((Iterable) value), propertyKeys, showTypes);
- } else if (value instanceof Iterator){
- value = createJSONList(getList((Iterator) value), propertyKeys, showTypes);
- } else if (value instanceof Map) {
- value = createJSONMap((Map) value, propertyKeys, showTypes);
- } else if (value instanceof Element) {
- value = objectNodeFromElement((Element) value, propertyKeys,
- showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL);
- } else if (value.getClass().isArray()) {
- value = createJSONList(convertArrayToList(value), propertyKeys, showTypes);
- }
- }
-
- putObject(jsonMap, key.toString(), getValue(value, showTypes));
- }
- return jsonMap;
-
- }
-
- private static List getList(final Iterable value) {
- return getList(value.iterator());
- }
-
- private static List getList(final Iterator value) {
- final List result = new ArrayList();
- while (value.hasNext()) {
- result.add(value.next());
- }
- return result;
- }
-
- private static void addObject(final ArrayNode jsonList, final Object value) {
- if (value == null) {
- jsonList.add((JsonNode) null);
- } else if (value.getClass() == Boolean.class) {
- jsonList.add((Boolean) value);
- } else if (value.getClass() == Long.class) {
- jsonList.add((Long) value);
- } else if (value.getClass() == Integer.class) {
- jsonList.add((Integer) value);
- } else if (value.getClass() == Float.class) {
- jsonList.add((Float) value);
- } else if (value.getClass() == Double.class) {
- jsonList.add((Double) value);
- } else if (value.getClass() == Byte.class) {
- jsonList.add((Byte) value);
- } else if (value.getClass() == Short.class) {
- jsonList.add((Short) value);
- } else if (value.getClass() == String.class) {
- jsonList.add((String) value);
- } else if (value instanceof ObjectNode) {
- jsonList.add((ObjectNode) value);
- } else if (value instanceof ArrayNode) {
- jsonList.add((ArrayNode) value);
- } else {
- jsonList.add(value.toString());
- }
- }
-
- private static void putObject(final ObjectNode jsonMap, final String key, final Object value) {
- if (value == null) {
- jsonMap.put(key, (JsonNode) null);
- } else if (value.getClass() == Boolean.class) {
- jsonMap.put(key, (Boolean) value);
- } else if (value.getClass() == Long.class) {
- jsonMap.put(key, (Long) value);
- } else if (value.getClass() == Integer.class) {
- jsonMap.put(key, (Integer) value);
- } else if (value.getClass() == Float.class) {
- jsonMap.put(key, (Float) value);
- } else if (value.getClass() == Double.class) {
- jsonMap.put(key, (Double) value);
- } else if (value.getClass() == Short.class) {
- jsonMap.put(key, (Short) value);
- } else if (value.getClass() == Byte.class) {
- jsonMap.put(key, (Byte) value);
- } else if (value.getClass() == String.class) {
- jsonMap.put(key, (String) value);
- } else if (value instanceof ObjectNode) {
- jsonMap.put(key, (ObjectNode) value);
- } else if (value instanceof ArrayNode) {
- jsonMap.put(key, (ArrayNode) value);
- } else {
- jsonMap.put(key, value.toString());
- }
- }
-
- private static Map createPropertyMap(final Element element, final List<String> propertyKeys,
- final ElementPropertiesRule rule, final boolean normalized) {
- final Map map = new HashMap<String, Object>();
- final List<String> propertyKeyList;
- if (normalized) {
- final List<String> sorted = new ArrayList<String>(element.keys());
- Collections.sort(sorted);
- propertyKeyList = sorted;
- } else
- propertyKeyList = new ArrayList<String>(element.keys());
-
- if (propertyKeys == null) {
- for (String key : propertyKeyList) {
- final Object valToPutInMap = element.property(key).value();
- if (valToPutInMap != null) {
- map.put(key, valToPutInMap);
- }
- }
- } else {
- if (rule == ElementPropertiesRule.INCLUDE) {
- for (String key : propertyKeys) {
- final Object valToPutInMap = element.property(key).value();
- if (valToPutInMap != null) {
- map.put(key, valToPutInMap);
- }
- }
- } else {
- for (String key : propertyKeyList) {
- if (!propertyKeys.contains(key)) {
- final Object valToPutInMap = element.property(key).value();
- if (valToPutInMap != null) {
- map.put(key, valToPutInMap);
- }
- }
- }
- }
- }
-
- return map;
- }
-
- private static Object getValue(Object value, final boolean includeType) {
-
- Object returnValue = value;
-
- // if the includeType is set to true then show the data types of the properties
- if (includeType) {
-
- // type will be one of: map, list, string, long, int, double, float.
- // in the event of a complex object it will call a toString and store as a
- // string
- String type = determineType(value);
-
- ObjectNode valueAndType = jsonNodeFactory.objectNode();
- valueAndType.put(GraphSONTokens.TYPE, type);
-
- if (type.equals(LegacyGraphSONTokens.TYPE_LIST)) {
-
- // values of lists must be accumulated as ObjectNode objects under the value key.
- // will return as a ArrayNode. called recursively to traverse the entire
- // object graph of each item in the array.
- ArrayNode list = (ArrayNode) value;
-
- // there is a set of values that must be accumulated as an array under a key
- ArrayNode valueArray = valueAndType.putArray(GraphSONTokens.VALUE);
- for (int ix = 0; ix < list.size(); ix++) {
- // the value of each item in the array is a node object from an ArrayNode...must
- // get the value of it.
- addObject(valueArray, getValue(getTypedValueFromJsonNode(list.get(ix)), includeType));
- }
-
- } else if (type.equals(LegacyGraphSONTokens.TYPE_MAP)) {
-
- // maps are converted to a ObjectNode. called recursively to traverse
- // the entire object graph within the map.
- ObjectNode convertedMap = jsonNodeFactory.objectNode();
- ObjectNode jsonObject = (ObjectNode) value;
- Iterator keyIterator = jsonObject.fieldNames();
- while (keyIterator.hasNext()) {
- Object key = keyIterator.next();
-
- // no need to getValue() here as this is already a ObjectNode and should have type info
- convertedMap.put(key.toString(), jsonObject.get(key.toString()));
- }
-
- valueAndType.put(GraphSONTokens.VALUE, convertedMap);
- } else {
-
- // this must be a primitive value or a complex object. if a complex
- // object it will be handled by a call to toString and stored as a
- // string value
- putObject(valueAndType, GraphSONTokens.VALUE, value);
- }
-
- // this goes back as a JSONObject with data type and value
- returnValue = valueAndType;
- }
-
- return returnValue;
- }
-
- static Object getTypedValueFromJsonNode(JsonNode node) {
- Object theValue = null;
-
- if (node != null && !node.isNull()) {
- if (node.isBoolean()) {
- theValue = node.booleanValue();
- } else if (node.isDouble()) {
- theValue = node.doubleValue();
- } else if (node.isFloatingPointNumber()) {
- theValue = node.floatValue();
- } else if (node.isInt()) {
- theValue = node.intValue();
- } else if (node.isLong()) {
- theValue = node.longValue();
- } else if (node.isTextual()) {
- theValue = node.textValue();
- } else if (node.isArray()) {
- // this is an array so just send it back so that it can be
- // reprocessed to its primitive components
- theValue = node;
- } else if (node.isObject()) {
- // this is an object so just send it back so that it can be
- // reprocessed to its primitive components
- theValue = node;
- } else {
- theValue = node.textValue();
- }
- }
-
- return theValue;
- }
-
- private static List convertArrayToList(final Object value) {
- final ArrayList<Object> list = new ArrayList<Object>();
- int arrlength = Array.getLength(value);
- for (int i = 0; i < arrlength; i++) {
- Object object = Array.get(value, i);
- list.add(object);
- }
- return list;
- }
-
- private static String determineType(final Object value) {
- String type = LegacyGraphSONTokens.TYPE_STRING;
- if (value == null) {
- type = LegacyGraphSONTokens.TYPE_UNKNOWN;
- } else if (value.getClass() == Double.class) {
- type = LegacyGraphSONTokens.TYPE_DOUBLE;
- } else if (value.getClass() == Float.class) {
- type = LegacyGraphSONTokens.TYPE_FLOAT;
- } else if (value.getClass() == Byte.class) {
- type = LegacyGraphSONTokens.TYPE_BYTE;
- } else if (value.getClass() == Short.class) {
- type = LegacyGraphSONTokens.TYPE_SHORT;
- } else if (value.getClass() == Integer.class) {
- type = LegacyGraphSONTokens.TYPE_INTEGER;
- } else if (value.getClass() == Long.class) {
- type = LegacyGraphSONTokens.TYPE_LONG;
- } else if (value.getClass() == Boolean.class) {
- type = LegacyGraphSONTokens.TYPE_BOOLEAN;
- } else if (value instanceof ArrayNode) {
- type = LegacyGraphSONTokens.TYPE_LIST;
- } else if (value instanceof ObjectNode) {
- type = LegacyGraphSONTokens.TYPE_MAP;
- }
-
- return type;
- }
-}
\ No newline at end of file
[5/6] incubator-tinkerpop git commit: Factor out duplicate method.
Posted by sp...@apache.org.
Factor out duplicate method.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/e1dc37de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/e1dc37de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/e1dc37de
Branch: refs/heads/tp30-legson
Commit: e1dc37de23ed93558d648ec9b101775bb96bf407
Parents: 641af9b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Aug 13 16:14:22 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Aug 13 16:14:22 2015 -0400
----------------------------------------------------------------------
.../BlueprintsLegacyGraphSONUtility.java | 50 +++++---------------
1 file changed, 11 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e1dc37de/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java
index 35c331f..d5aed97 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/BlueprintsLegacyGraphSONUtility.java
@@ -37,10 +37,14 @@ import org.codehaus.jettison.json.JSONTokener;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array;
-import java.util.*;
-
-//import com.tinkerpop.blueprints.Direction;
-//import com.tinkerpop.blueprints.Element;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Helps write individual graph elements to TinkerPop JSON format known as GraphSON.
@@ -183,7 +187,7 @@ public class BlueprintsLegacyGraphSONUtility {
public Vertex vertexFromJson(final JsonNode json) throws IOException {
final Map<String, Object> props = readProperties(json, true, this.hasEmbeddedTypes);
- final Object vertexId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
+ final Object vertexId = LegacyGraphSONUtility.getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
final Vertex v = factory.createVertex(vertexId);
for (Map.Entry<String, Object> entry : props.entrySet()) {
@@ -227,7 +231,7 @@ public class BlueprintsLegacyGraphSONUtility {
public Edge edgeFromJson(final JsonNode json, final Vertex out, final Vertex in) throws IOException {
final Map<String, Object> props = BlueprintsLegacyGraphSONUtility.readProperties(json, true, this.hasEmbeddedTypes);
- final Object edgeId = getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
+ final Object edgeId = LegacyGraphSONUtility.getTypedValueFromJsonNode(json.get(LegacyGraphSONTokens._ID));
final JsonNode nodeLabel = json.get(LegacyGraphSONTokens._LABEL);
// assigned an empty string edge label in cases where one does not exist. this gets around the requirement
@@ -769,7 +773,7 @@ public class BlueprintsLegacyGraphSONUtility {
for (int ix = 0; ix < list.size(); ix++) {
// the value of each item in the array is a node object from an ArrayNode...must
// get the value of it.
- addObject(valueArray, getValue(getTypedValueFromJsonNode(list.get(ix)), includeType));
+ addObject(valueArray, getValue(LegacyGraphSONUtility.getTypedValueFromJsonNode(list.get(ix)), includeType));
}
} else if (type.equals(LegacyGraphSONTokens.TYPE_MAP)) {
@@ -802,38 +806,6 @@ public class BlueprintsLegacyGraphSONUtility {
return returnValue;
}
- static Object getTypedValueFromJsonNode(JsonNode node) {
- Object theValue = null;
-
- if (node != null && !node.isNull()) {
- if (node.isBoolean()) {
- theValue = node.booleanValue();
- } else if (node.isDouble()) {
- theValue = node.doubleValue();
- } else if (node.isFloatingPointNumber()) {
- theValue = node.floatValue();
- } else if (node.isInt()) {
- theValue = node.intValue();
- } else if (node.isLong()) {
- theValue = node.longValue();
- } else if (node.isTextual()) {
- theValue = node.textValue();
- } else if (node.isArray()) {
- // this is an array so just send it back so that it can be
- // reprocessed to its primitive components
- theValue = node;
- } else if (node.isObject()) {
- // this is an object so just send it back so that it can be
- // reprocessed to its primitive components
- theValue = node;
- } else {
- theValue = node.textValue();
- }
- }
-
- return theValue;
- }
-
private static List convertArrayToList(final Object value) {
final ArrayList<Object> list = new ArrayList<Object>();
int arrlength = Array.getLength(value);
[2/6] incubator-tinkerpop git commit: Renamed class to be more
consistent with TP3.
Posted by sp...@apache.org.
Renamed class to be more consistent with TP3.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/73234bd6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/73234bd6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/73234bd6
Branch: refs/heads/tp30-legson
Commit: 73234bd6658162f4edf17e74dc8cd9e61cbd646a
Parents: 3776675
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Aug 13 16:09:50 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Aug 13 16:09:50 2015 -0400
----------------------------------------------------------------------
.../io/graphson/FaunusGraphSONUtility.java | 194 -------------------
.../io/graphson/GraphSONLegacyWriter.java | 2 +-
.../graphson/HadoopLegacyGraphSONUtility.java | 194 +++++++++++++++++++
.../io/graphson/TP2GraphSONUtility.java | 6 +-
4 files changed, 198 insertions(+), 198 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/73234bd6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
deleted file mode 100644
index 37f5a69..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/FaunusGraphSONUtility.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tinkerpop.gremlin.structure.io.graphson;
-
-import org.apache.tinkerpop.gremlin.structure.Direction;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Element;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.TP2GraphSONUtility.ElementFactory;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.TP2GraphSONUtility.GraphSONMode;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
-import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-import org.codehaus.jettison.json.JSONTokener;
-import org.javatuples.Pair;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.*;
-
-import static org.apache.tinkerpop.gremlin.structure.Direction.IN;
-import static org.apache.tinkerpop.gremlin.structure.Direction.OUT;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @author Edi Bice
- */
-public class FaunusGraphSONUtility {
-
- //private static final String _OUT_E = "_outE";
- //private static final String _IN_E = "_inE";
- private static final String EMPTY_STRING = "";
-
- private static final Set<String> VERTEX_IGNORE = new HashSet<String>(Arrays.asList(LegacyGraphSONTokens._TYPE, LegacyGraphSONTokens._OUT_E, LegacyGraphSONTokens._IN_E));
- private static final Set<String> EDGE_IGNORE = new HashSet<String>(Arrays.asList(LegacyGraphSONTokens._TYPE, LegacyGraphSONTokens._OUT_V, LegacyGraphSONTokens._IN_V));
-
- private static final ElementFactory elementFactory = new MyElementFactory();
-
- private static final TP2GraphSONUtility graphson = new TP2GraphSONUtility(GraphSONMode.COMPACT, elementFactory,
- ElementPropertyConfig.excludeProperties(VERTEX_IGNORE, EDGE_IGNORE));
-
- public static List<Vertex> fromJSON(final InputStream in) throws IOException {
- final List<Vertex> vertices = new LinkedList<Vertex>();
- final BufferedReader bfs = new BufferedReader(new InputStreamReader(in));
- String line = "";
- while ((line = bfs.readLine()) != null) {
- vertices.add(FaunusGraphSONUtility.fromJSON(line));
- }
- bfs.close();
- return vertices;
-
- }
-
- public static Vertex fromJSON(String line) throws IOException {
- try {
- final JSONObject json = new JSONObject(new JSONTokener(line));
- line = EMPTY_STRING; // clear up some memory
-
- final Vertex vertex = graphson.vertexFromJson(json);
-
- fromJSONEdges(vertex, json.optJSONArray(LegacyGraphSONTokens._OUT_E), OUT);
- json.remove(LegacyGraphSONTokens._OUT_E); // clear up some memory
- fromJSONEdges(vertex, json.optJSONArray(LegacyGraphSONTokens._IN_E), IN);
- json.remove(LegacyGraphSONTokens._IN_E); // clear up some memory
-
- return vertex;
- } catch (Exception e) {
- throw new IOException(e.getMessage(), e);
- }
- }
-
- private static void fromJSONEdges(final Vertex vertex, final JSONArray edges, final Direction direction) throws JSONException, IOException {
- if (null != edges) {
- for (int i = 0; i < edges.length(); i++) {
- final JSONObject jsonEdge = edges.optJSONObject(i);
- Edge edge = null;
- if (direction.equals(Direction.IN)) {
- DetachedVertex outVertex = new DetachedVertex(jsonEdge.optLong(LegacyGraphSONTokens._OUT_V),null,new HashMap<>());
- edge = graphson.edgeFromJson(jsonEdge, outVertex, vertex);
- outVertex.addEdge(jsonEdge.optString(LegacyGraphSONTokens._LABEL), vertex);
- } else if (direction.equals(Direction.OUT)) {
- DetachedVertex inVertex = new DetachedVertex(jsonEdge.optLong(LegacyGraphSONTokens._IN_V),null,new HashMap<>());
- edge = graphson.edgeFromJson(jsonEdge, vertex, inVertex);
- vertex.addEdge(jsonEdge.optString(LegacyGraphSONTokens._LABEL), inVertex);
- }
- }
- }
- }
-
- public static JSONObject toJSON(final Vertex vertex) throws IOException {
- try {
- //final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, getElementPropertyKeys(vertex, false), GraphSONMode.COMPACT);
- final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, null, GraphSONMode.COMPACT);
-
- // force the ID to long. with blueprints, most implementations will send back a long, but
- // some like TinkerGraph will return a string. the same is done for edges below
- object.put(LegacyGraphSONTokens._ID, Long.valueOf(object.remove(LegacyGraphSONTokens._ID).toString()));
-
- List<Edge> edges = new ArrayList<Edge>();
- vertex.edges(OUT).forEachRemaining(edges::add);
- if (!edges.isEmpty()) {
- final JSONArray outEdgesArray = new JSONArray();
- for (final Edge outEdge : edges) {
- //final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, getElementPropertyKeys(outEdge, true), GraphSONMode.COMPACT);
- final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, null, GraphSONMode.COMPACT);
- outEdgesArray.put(edgeObject);
- }
- object.put(LegacyGraphSONTokens._OUT_E, outEdgesArray);
- }
-
- vertex.edges(IN).forEachRemaining(edges::add);
- if (!edges.isEmpty()) {
- final JSONArray inEdgesArray = new JSONArray();
- for (final Edge inEdge : edges) {
- //final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, getElementPropertyKeys(inEdge, false), GraphSONMode.COMPACT);
- final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, null, GraphSONMode.COMPACT);
- inEdgesArray.put(edgeObject);
- }
- object.put(LegacyGraphSONTokens._IN_E, inEdgesArray);
- }
-
- return object;
- } catch (JSONException e) {
- throw new IOException(e);
- }
- }
-
- private static Set<String> getElementPropertyKeys(final Element element, final boolean edgeIn) {
- final Set<String> elementPropertyKeys = new HashSet<String>(element.keys()); // .getPropertyKeys());
- // exclude reserved keys? not really properties?
- /*elementPropertyKeys.add(GraphSONTokens.ID);
- if (element instanceof Edge) {
- if (edgeIn) {
- elementPropertyKeys.add(GraphSONTokens.IN);
- } else {
- elementPropertyKeys.add(GraphSONTokens.OUT);
- }
-
- elementPropertyKeys.add(GraphSONTokens.LABEL);
- }*/
- return elementPropertyKeys;
- }
-
- public static class MyElementFactory implements ElementFactory<Vertex, Edge> {
-
- @Override
- public Edge createEdge(final Object id, final Vertex out, final Vertex in, final String label) {
- Pair<Object, String> outPair = new Pair<Object, String>(out.id(), out.label());
- Pair<Object, String> inPair = new Pair<Object, String>(in.id(), in.label());
- return new DetachedEdge(id, label, Collections.EMPTY_MAP, outPair, inPair);
- }
-
- @Override
- public DetachedVertex createVertex(final Object id) {
- return new DetachedVertex(convertIdentifier(id), null, new HashMap<>());
- }
-
- private long convertIdentifier(final Object id) {
- if (id instanceof Long)
- return (Long) id;
-
- long identifier = -1l;
- if (id != null) {
- try {
- identifier = Long.parseLong(id.toString());
- } catch (final NumberFormatException e) {
- identifier = -1l;
- }
- }
- return identifier;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/73234bd6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
index b80ba4a..3737ff9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONLegacyWriter.java
@@ -138,7 +138,7 @@ public class GraphSONLegacyWriter {
final Iterable<Vertex> vertices = vertices(normalize);
for (Vertex v : vertices) {
try {
- FaunusGraphSONUtility.toJSON(v).write(writer);
+ HadoopLegacyGraphSONUtility.toJSON(v).write(writer);
} catch (JSONException e) {
e.printStackTrace();
throw new IOException(e);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/73234bd6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java
new file mode 100644
index 0000000..264d320
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/HadoopLegacyGraphSONUtility.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.io.graphson;
+
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TP2GraphSONUtility.ElementFactory;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.TP2GraphSONUtility.GraphSONMode;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.codehaus.jettison.json.JSONTokener;
+import org.javatuples.Pair;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.*;
+
+import static org.apache.tinkerpop.gremlin.structure.Direction.IN;
+import static org.apache.tinkerpop.gremlin.structure.Direction.OUT;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ * @author Edi Bice
+ */
+public class HadoopLegacyGraphSONUtility {
+
+ //private static final String _OUT_E = "_outE";
+ //private static final String _IN_E = "_inE";
+ private static final String EMPTY_STRING = "";
+
+ private static final Set<String> VERTEX_IGNORE = new HashSet<String>(Arrays.asList(LegacyGraphSONTokens._TYPE, LegacyGraphSONTokens._OUT_E, LegacyGraphSONTokens._IN_E));
+ private static final Set<String> EDGE_IGNORE = new HashSet<String>(Arrays.asList(LegacyGraphSONTokens._TYPE, LegacyGraphSONTokens._OUT_V, LegacyGraphSONTokens._IN_V));
+
+ private static final ElementFactory elementFactory = new MyElementFactory();
+
+ private static final TP2GraphSONUtility graphson = new TP2GraphSONUtility(GraphSONMode.COMPACT, elementFactory,
+ ElementPropertyConfig.excludeProperties(VERTEX_IGNORE, EDGE_IGNORE));
+
+ public static List<Vertex> fromJSON(final InputStream in) throws IOException {
+ final List<Vertex> vertices = new LinkedList<Vertex>();
+ final BufferedReader bfs = new BufferedReader(new InputStreamReader(in));
+ String line = "";
+ while ((line = bfs.readLine()) != null) {
+ vertices.add(HadoopLegacyGraphSONUtility.fromJSON(line));
+ }
+ bfs.close();
+ return vertices;
+
+ }
+
+ public static Vertex fromJSON(String line) throws IOException {
+ try {
+ final JSONObject json = new JSONObject(new JSONTokener(line));
+ line = EMPTY_STRING; // clear up some memory
+
+ final Vertex vertex = graphson.vertexFromJson(json);
+
+ fromJSONEdges(vertex, json.optJSONArray(LegacyGraphSONTokens._OUT_E), OUT);
+ json.remove(LegacyGraphSONTokens._OUT_E); // clear up some memory
+ fromJSONEdges(vertex, json.optJSONArray(LegacyGraphSONTokens._IN_E), IN);
+ json.remove(LegacyGraphSONTokens._IN_E); // clear up some memory
+
+ return vertex;
+ } catch (Exception e) {
+ throw new IOException(e.getMessage(), e);
+ }
+ }
+
+ private static void fromJSONEdges(final Vertex vertex, final JSONArray edges, final Direction direction) throws JSONException, IOException {
+ if (null != edges) {
+ for (int i = 0; i < edges.length(); i++) {
+ final JSONObject jsonEdge = edges.optJSONObject(i);
+ Edge edge = null;
+ if (direction.equals(Direction.IN)) {
+ DetachedVertex outVertex = new DetachedVertex(jsonEdge.optLong(LegacyGraphSONTokens._OUT_V),null,new HashMap<>());
+ edge = graphson.edgeFromJson(jsonEdge, outVertex, vertex);
+ outVertex.addEdge(jsonEdge.optString(LegacyGraphSONTokens._LABEL), vertex);
+ } else if (direction.equals(Direction.OUT)) {
+ DetachedVertex inVertex = new DetachedVertex(jsonEdge.optLong(LegacyGraphSONTokens._IN_V),null,new HashMap<>());
+ edge = graphson.edgeFromJson(jsonEdge, vertex, inVertex);
+ vertex.addEdge(jsonEdge.optString(LegacyGraphSONTokens._LABEL), inVertex);
+ }
+ }
+ }
+ }
+
+ public static JSONObject toJSON(final Vertex vertex) throws IOException {
+ try {
+ //final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, getElementPropertyKeys(vertex, false), GraphSONMode.COMPACT);
+ final JSONObject object = TP2GraphSONUtility.jsonFromElement(vertex, null, GraphSONMode.COMPACT);
+
+ // force the ID to long. with blueprints, most implementations will send back a long, but
+ // some like TinkerGraph will return a string. the same is done for edges below
+ object.put(LegacyGraphSONTokens._ID, Long.valueOf(object.remove(LegacyGraphSONTokens._ID).toString()));
+
+ List<Edge> edges = new ArrayList<Edge>();
+ vertex.edges(OUT).forEachRemaining(edges::add);
+ if (!edges.isEmpty()) {
+ final JSONArray outEdgesArray = new JSONArray();
+ for (final Edge outEdge : edges) {
+ //final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, getElementPropertyKeys(outEdge, true), GraphSONMode.COMPACT);
+ final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(outEdge, null, GraphSONMode.COMPACT);
+ outEdgesArray.put(edgeObject);
+ }
+ object.put(LegacyGraphSONTokens._OUT_E, outEdgesArray);
+ }
+
+ vertex.edges(IN).forEachRemaining(edges::add);
+ if (!edges.isEmpty()) {
+ final JSONArray inEdgesArray = new JSONArray();
+ for (final Edge inEdge : edges) {
+ //final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, getElementPropertyKeys(inEdge, false), GraphSONMode.COMPACT);
+ final JSONObject edgeObject = TP2GraphSONUtility.jsonFromElement(inEdge, null, GraphSONMode.COMPACT);
+ inEdgesArray.put(edgeObject);
+ }
+ object.put(LegacyGraphSONTokens._IN_E, inEdgesArray);
+ }
+
+ return object;
+ } catch (JSONException e) {
+ throw new IOException(e);
+ }
+ }
+
+ private static Set<String> getElementPropertyKeys(final Element element, final boolean edgeIn) {
+ final Set<String> elementPropertyKeys = new HashSet<String>(element.keys()); // .getPropertyKeys());
+ // exclude reserved keys? not really properties?
+ /*elementPropertyKeys.add(GraphSONTokens.ID);
+ if (element instanceof Edge) {
+ if (edgeIn) {
+ elementPropertyKeys.add(GraphSONTokens.IN);
+ } else {
+ elementPropertyKeys.add(GraphSONTokens.OUT);
+ }
+
+ elementPropertyKeys.add(GraphSONTokens.LABEL);
+ }*/
+ return elementPropertyKeys;
+ }
+
+ public static class MyElementFactory implements ElementFactory<Vertex, Edge> {
+
+ @Override
+ public Edge createEdge(final Object id, final Vertex out, final Vertex in, final String label) {
+ Pair<Object, String> outPair = new Pair<Object, String>(out.id(), out.label());
+ Pair<Object, String> inPair = new Pair<Object, String>(in.id(), in.label());
+ return new DetachedEdge(id, label, Collections.EMPTY_MAP, outPair, inPair);
+ }
+
+ @Override
+ public DetachedVertex createVertex(final Object id) {
+ return new DetachedVertex(convertIdentifier(id), null, new HashMap<>());
+ }
+
+ private long convertIdentifier(final Object id) {
+ if (id instanceof Long)
+ return (Long) id;
+
+ long identifier = -1l;
+ if (id != null) {
+ try {
+ identifier = Long.parseLong(id.toString());
+ } catch (final NumberFormatException e) {
+ identifier = -1l;
+ }
+ }
+ return identifier;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/73234bd6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
index c2056cd..e8beb85 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TP2GraphSONUtility.java
@@ -439,7 +439,7 @@ public class TP2GraphSONUtility {
*/
public static JSONObject jsonFromElement(final Element element, final Set<String> propertyKeys,
final GraphSONMode mode) throws JSONException {
- ElementFactory factory = new FaunusGraphSONUtility.MyElementFactory();
+ ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propertyKeys)
: new TP2GraphSONUtility(mode, factory, propertyKeys, null);
return graphson.jsonFromElement(element);
@@ -453,14 +453,14 @@ public class TP2GraphSONUtility {
* @param mode The type of GraphSON to generate.
*/
public static ObjectNode objectNodeFromElement(final Element element, final Set<String> propertyKeys, final GraphSONMode mode) {
- ElementFactory factory = new FaunusGraphSONUtility.MyElementFactory();
+ ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propertyKeys)
: new TP2GraphSONUtility(mode, factory, propertyKeys, null);
return graphson.objectNodeFromElement(element);
}
private static ObjectNode objectNodeFromElement(final Element element, final List<String> propertyKeys, final GraphSONMode mode) {
- ElementFactory factory = new FaunusGraphSONUtility.MyElementFactory();
+ ElementFactory factory = new HadoopLegacyGraphSONUtility.MyElementFactory();
Set<String> propKeySet = (propertyKeys!=null)? new HashSet<String>(propertyKeys) : null;
final TP2GraphSONUtility graphson = element instanceof Edge ? new TP2GraphSONUtility(mode, factory, null, propKeySet)
: new TP2GraphSONUtility(mode, factory, propKeySet, null);
[6/6] incubator-tinkerpop git commit: Changed the json data typing
key back to what it was.
Posted by sp...@apache.org.
Changed the json data typing key back to what it was.
Tests were not passing for legacy graphson reading prior to this.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/ac258c02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/ac258c02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/ac258c02
Branch: refs/heads/tp30-legson
Commit: ac258c022430cbfe2e19d3e18d09cd85c5c0648b
Parents: e1dc37d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Aug 14 06:56:30 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Aug 14 06:56:30 2015 -0400
----------------------------------------------------------------------
.../io/graphson/LegacyGraphSONTokens.java | 2 +-
.../io/graphson/LegacyGraphSONUtility.java | 22 ++++++++++----------
2 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ac258c02/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java
index d27bf02..3618057 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONTokens.java
@@ -30,7 +30,7 @@ public final class LegacyGraphSONTokens {
public static final String _OUT_E = "_outE";
public static final String _IN_E = "_inE";
public static final String VALUE = "value";
- //public static final String TYPE = "type";
+ public static final String TYPE = "type";
public static final String TYPE_LIST = "list";
public static final String TYPE_STRING = "string";
public static final String TYPE_DOUBLE = "double";
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ac258c02/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java
index 3efc39a..8c97633 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/LegacyGraphSONUtility.java
@@ -102,27 +102,27 @@ public final class LegacyGraphSONUtility {
private static Object readProperty(final JsonNode node) {
final Object propertyValue;
- if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_UNKNOWN)) {
+ if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_UNKNOWN)) {
propertyValue = null;
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BOOLEAN)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BOOLEAN)) {
propertyValue = node.get(LegacyGraphSONTokens.VALUE).booleanValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_FLOAT)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_FLOAT)) {
propertyValue = Float.parseFloat(node.get(LegacyGraphSONTokens.VALUE).asText());
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BYTE)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_BYTE)) {
propertyValue = Byte.parseByte(node.get(LegacyGraphSONTokens.VALUE).asText());
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_SHORT)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_SHORT)) {
propertyValue = Short.parseShort(node.get(LegacyGraphSONTokens.VALUE).asText());
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_DOUBLE)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_DOUBLE)) {
propertyValue = node.get(LegacyGraphSONTokens.VALUE).doubleValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_INTEGER)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_INTEGER)) {
propertyValue = node.get(LegacyGraphSONTokens.VALUE).intValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LONG)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LONG)) {
propertyValue = node.get(LegacyGraphSONTokens.VALUE).longValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_STRING)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_STRING)) {
propertyValue = node.get(LegacyGraphSONTokens.VALUE).textValue();
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LIST)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_LIST)) {
propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE).elements());
- } else if (node.get(LegacyGraphSONTokens._TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_MAP)) {
+ } else if (node.get(LegacyGraphSONTokens.TYPE).textValue().equals(LegacyGraphSONTokens.TYPE_MAP)) {
propertyValue = readProperties(node.get(LegacyGraphSONTokens.VALUE));
} else {
propertyValue = node.textValue();