本文整理汇总了Java中org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens类的典型用法代码示例。如果您正苦于以下问题:Java GraphSONTokens类的具体用法?Java GraphSONTokens怎么用?Java GraphSONTokens使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphSONTokens类属于org.apache.tinkerpop.gremlin.structure.io.graphson包,在下文中一共展示了GraphSONTokens类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldSerializeEdgeProperty
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Test
public void shouldSerializeEdgeProperty() throws Exception {
final Graph g = TinkerGraph.open();
final Vertex v1 = g.addVertex();
final Vertex v2 = g.addVertex();
final Edge e = v1.addEdge("test", v2);
e.property("abc", 123);
final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());
final JsonNode json = mapper.readTree(results);
assertNotNull(json);
assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);
assertNotNull(converted);
assertEquals(1, converted.size());
final JsonNode propertyAsJson = converted.get(0);
assertNotNull(propertyAsJson);
assertEquals(123, propertyAsJson.get(GraphSONTokens.VALUEPROP).get("value").get(GraphSONTokens.VALUEPROP).asInt());
}
示例2: shouldSerializeToJsonMapWithElementForKey
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Test
public void shouldSerializeToJsonMapWithElementForKey() throws Exception {
final TinkerGraph graph = TinkerFactory.createClassic();
final GraphTraversalSource g = graph.traversal();
final Map<Vertex, Integer> map = new HashMap<>();
map.put(g.V().has("name", "marko").next(), 1000);
final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(map).create());
final JsonNode json = mapper.readTree(results);
assertNotNull(json);
assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);
assertNotNull(converted);
// with no embedded types the key (which is a vertex) simply serializes out to an id
// {"result":{"1":1000},"code":200,"requestId":"2d62161b-9544-4f39-af44-62ec49f9a595","type":0}
assertEquals(1000, converted.get("1").get(GraphSONTokens.VALUEPROP).asInt());
}
示例3: serialize
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Override
public void serialize(final TinkerGraph graph, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeFieldName(GraphSONTokens.VERTICES);
jsonGenerator.writeStartArray();
final Iterator<Vertex> vertices = graph.vertices();
while (vertices.hasNext()) {
serializerProvider.defaultSerializeValue(vertices.next(), jsonGenerator);
}
jsonGenerator.writeEndArray();
jsonGenerator.writeFieldName(GraphSONTokens.EDGES);
jsonGenerator.writeStartArray();
final Iterator<Edge> edges = graph.edges();
while (edges.hasNext()) {
serializerProvider.defaultSerializeValue(edges.next(), jsonGenerator);
}
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
示例4: shouldSerializeTraversalMetrics
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Ignore
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
final TraversalMetrics tm = (TraversalMetrics) g.V().both().profile().next();
final String json = mapper.writeValueAsString(tm);
final Map<String, Object> m = mapper.readValue(json, mapTypeReference);
assertTrue(m.containsKey(GraphSONTokens.DURATION));
assertTrue(m.containsKey(GraphSONTokens.METRICS));
final List<Map<String, Object>> metrics = (List<Map<String, Object>>) m.get(GraphSONTokens.METRICS);
assertEquals(2, metrics.size());
final Map<String, Object> metrics0 = metrics.get(0);
assertTrue(metrics0.containsKey(GraphSONTokens.ID));
assertTrue(metrics0.containsKey(GraphSONTokens.NAME));
assertTrue(metrics0.containsKey(GraphSONTokens.COUNTS));
assertTrue(metrics0.containsKey(GraphSONTokens.DURATION));
}
示例5: ser
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
public void ser(final ResponseMessage responseMessage, final JsonGenerator jsonGenerator,
final SerializerProvider serializerProvider,
final TypeSerializer typeSerializer) throws IOException, JsonProcessingException {
jsonGenerator.writeStartObject();
if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
jsonGenerator.writeStringField(SerTokens.TOKEN_REQUEST, responseMessage.getRequestId() != null ? responseMessage.getRequestId().toString() : null);
jsonGenerator.writeObjectFieldStart(SerTokens.TOKEN_STATUS);
if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
jsonGenerator.writeStringField(SerTokens.TOKEN_MESSAGE, responseMessage.getStatus().getMessage());
jsonGenerator.writeNumberField(SerTokens.TOKEN_CODE, responseMessage.getStatus().getCode().getValue());
jsonGenerator.writeObjectField(SerTokens.TOKEN_ATTRIBUTES, responseMessage.getStatus().getAttributes());
jsonGenerator.writeEndObject();
jsonGenerator.writeObjectFieldStart(SerTokens.TOKEN_RESULT);
if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName());
if (null == responseMessage.getResult().getData())
jsonGenerator.writeNullField(SerTokens.TOKEN_DATA);
else
GraphSONUtil.writeWithType(SerTokens.TOKEN_DATA, responseMessage.getResult().getData(), jsonGenerator, serializerProvider, typeSerializer);
jsonGenerator.writeObjectField(SerTokens.TOKEN_META, responseMessage.getResult().getMeta());
jsonGenerator.writeEndObject();
jsonGenerator.writeEndObject();
}
示例6: readStarGraphEdges
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
/**
* A helper function for reading vertex edges from a serialized {@link StarGraph} (i.e. a {@link Map}) generated by
* {@link StarGraphGraphSONSerializer}.
*/
public static void readStarGraphEdges(final Function<Attachable<Edge>, Edge> edgeMaker,
final StarGraph starGraph,
final Map<String, Object> vertexData,
final String direction) throws IOException {
final Map<String, List<Map<String,Object>>> edgeDatas = (Map<String, List<Map<String,Object>>>) vertexData.get(direction);
for (Map.Entry<String, List<Map<String,Object>>> edgeData : edgeDatas.entrySet()) {
for (Map<String,Object> inner : edgeData.getValue()) {
final StarGraph.StarEdge starEdge;
if (direction.equals(GraphSONTokens.OUT_E))
starEdge = (StarGraph.StarEdge) starGraph.getStarVertex().addOutEdge(edgeData.getKey(), starGraph.addVertex(T.id, inner.get(GraphSONTokens.IN)), T.id, inner.get(GraphSONTokens.ID));
else
starEdge = (StarGraph.StarEdge) starGraph.getStarVertex().addInEdge(edgeData.getKey(), starGraph.addVertex(T.id, inner.get(GraphSONTokens.OUT)), T.id, inner.get(GraphSONTokens.ID));
if (inner.containsKey(GraphSONTokens.PROPERTIES)) {
final Map<String, Object> edgePropertyData = (Map<String, Object>) inner.get(GraphSONTokens.PROPERTIES);
for (Map.Entry<String, Object> epd : edgePropertyData.entrySet()) {
starEdge.property(epd.getKey(), epd.getValue());
}
}
if (edgeMaker != null) edgeMaker.apply(starEdge);
}
}
}
示例7: readStarGraphVertex
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
/**
* A helper function for reading a serialized {@link StarGraph} from a {@link Map} generated by
* {@link StarGraphGraphSONSerializer}.
*/
public static StarGraph readStarGraphVertex(final Map<String, Object> vertexData) throws IOException {
final StarGraph starGraph = StarGraph.open();
starGraph.addVertex(T.id, vertexData.get(GraphSONTokens.ID), T.label, vertexData.get(GraphSONTokens.LABEL));
if (vertexData.containsKey(GraphSONTokens.PROPERTIES)) {
final Map<String, List<Map<String, Object>>> properties = (Map<String, List<Map<String, Object>>>) vertexData.get(GraphSONTokens.PROPERTIES);
for (Map.Entry<String, List<Map<String, Object>>> property : properties.entrySet()) {
for (Map<String, Object> p : property.getValue()) {
final StarGraph.StarVertexProperty vp = (StarGraph.StarVertexProperty) starGraph.getStarVertex().property(VertexProperty.Cardinality.list, property.getKey(), p.get(GraphSONTokens.VALUE), T.id, p.get(GraphSONTokens.ID));
if (p.containsKey(GraphSONTokens.PROPERTIES)) {
final Map<String, Object> edgePropertyData = (Map<String, Object>) p.get(GraphSONTokens.PROPERTIES);
for (Map.Entry<String, Object> epd : edgePropertyData.entrySet()) {
vp.property(epd.getKey(), epd.getValue());
}
}
}
}
}
return starGraph;
}
示例8: shouldSerializeDeserialize
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Test
public void shouldSerializeDeserialize() throws Exception {
final GryoMapper mapper = GryoMapper.build().create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
final Map<String,Object> props = new HashMap<>();
final List<Map<String, Object>> propertyNames = new ArrayList<>(1);
final Map<String,Object> propertyName = new HashMap<>();
propertyName.put(GraphSONTokens.ID, "x");
propertyName.put(GraphSONTokens.KEY, "x");
propertyName.put(GraphSONTokens.VALUE, "no-way-this-will-ever-work");
propertyNames.add(propertyName);
props.put("x", propertyNames);
final DetachedVertex v = new DetachedVertex(100, Vertex.DEFAULT_LABEL, props);
kryo.writeClassAndObject(out, v);
try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) {
final Input input = new Input(inputStream);
final DetachedVertex readX = (DetachedVertex) kryo.readClassAndObject(input);
assertEquals("no-way-this-will-ever-work", readX.value("x"));
}
}
}
示例9: should200OnPOSTWithGremlinJsonEndcodedBodyWithTinkerGraphResult
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Test
public void should200OnPOSTWithGremlinJsonEndcodedBodyWithTinkerGraphResult() throws Exception {
final CloseableHttpClient httpclient = HttpClients.createDefault();
final HttpPost httppost = new HttpPost("http://localhost:8182");
httppost.addHeader("Content-Type", "application/json");
httppost.setEntity(new StringEntity("{\"gremlin\":\"org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.createModern()\"}", Consts.UTF_8));
try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("application/json", response.getEntity().getContentType().getValue());
final String json = EntityUtils.toString(response.getEntity());
final JsonNode resultJson = mapper.readTree(json);
final JsonNode data = resultJson.get("result").get("data");
assertEquals(1, data.size());
final List<JsonNode> vertices = data.get(0).findValues(GraphSONTokens.VERTICES);
final List<JsonNode> edges = data.get(0).findValues(GraphSONTokens.EDGES);
assertEquals(6, vertices.get(0).size());
assertEquals(6, edges.get(0).size());
}
}
示例10: shouldSerializeVertex
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertex() throws Exception {
final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
final Vertex v = graph.vertices(convertToVertexId("marko")).next();
final String json = mapper.writeValueAsString(v);
final Map<String, Object> m = mapper.readValue(json, mapTypeReference);
assertEquals(GraphSONTokens.VERTEX, m.get(GraphSONTokens.TYPE));
assertEquals(v.label(), m.get(GraphSONTokens.LABEL));
assertNotNull(m.get(GraphSONTokens.ID));
final Map<String,List<Map<String,Object>>> properties = (Map<String,List<Map<String,Object>>>) m.get(GraphSONTokens.PROPERTIES);
assertEquals(v.value("name").toString(), properties.get("name").get(0).get(GraphSONTokens.VALUE).toString());
assertEquals((Integer) v.value("age"), properties.get("age").get(0).get(GraphSONTokens.VALUE));
assertEquals(1, properties.get("name").size());
assertEquals(1, properties.get("age").size());
assertEquals(2, properties.size());
}
示例11: shouldSerializeTraversalMetrics
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
final TraversalMetrics tm = (TraversalMetrics) g.V().both().profile().next();
final String json = mapper.writeValueAsString(tm);
final Map<String, Object> m = mapper.readValue(json, mapTypeReference);
assertTrue(m.containsKey(GraphSONTokens.DURATION));
assertTrue(m.containsKey(GraphSONTokens.METRICS));
final List<Map<String, Object>> metrics = (List<Map<String, Object>>) m.get(GraphSONTokens.METRICS);
assertEquals(2, metrics.size());
final Map<String, Object> metrics0 = metrics.get(0);
assertTrue(metrics0.containsKey(GraphSONTokens.ID));
assertTrue(metrics0.containsKey(GraphSONTokens.NAME));
assertTrue(metrics0.containsKey(GraphSONTokens.COUNTS));
assertTrue(metrics0.containsKey(GraphSONTokens.DURATION));
}
示例12: readStarGraphEdges
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
/**
* A helper function for reading vertex edges from a serialized {@link org.apache.tinkerpop.gremlin.structure.util.star.StarGraph} (i.e. a {@link java.util.Map}) generated by
* {@link org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV1d0}.
*/
public static void readStarGraphEdges(final Function<Attachable<Edge>, Edge> edgeMaker,
final StarGraph starGraph,
final Map<String, Object> vertexData,
final String direction) throws IOException {
final Map<String, List<Map<String,Object>>> edgeDatas = (Map<String, List<Map<String,Object>>>) vertexData.get(direction);
for (Map.Entry<String, List<Map<String,Object>>> edgeData : edgeDatas.entrySet()) {
for (Map<String,Object> inner : edgeData.getValue()) {
final StarGraph.StarEdge starEdge;
if (direction.equals(GraphSONTokens.OUT_E))
starEdge = (StarGraph.StarEdge) starGraph.getStarVertex().addOutEdge(edgeData.getKey(), starGraph.addVertex(T.id, inner.get(GraphSONTokens.IN)), T.id, inner.get(GraphSONTokens.ID));
else
starEdge = (StarGraph.StarEdge) starGraph.getStarVertex().addInEdge(edgeData.getKey(), starGraph.addVertex(T.id, inner.get(GraphSONTokens.OUT)), T.id, inner.get(GraphSONTokens.ID));
if (inner.containsKey(GraphSONTokens.PROPERTIES)) {
final Map<String, Object> edgePropertyData = (Map<String, Object>) inner.get(GraphSONTokens.PROPERTIES);
for (Map.Entry<String, Object> epd : edgePropertyData.entrySet()) {
starEdge.property(epd.getKey(), epd.getValue());
}
}
if (edgeMaker != null) edgeMaker.apply(starEdge);
}
}
}
示例13: readStarGraphVertex
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
/**
* A helper function for reading a serialized {@link org.apache.tinkerpop.gremlin.structure.util.star.StarGraph} from a {@link java.util.Map} generated by
* {@link org.apache.tinkerpop.gremlin.structure.util.star.StarGraphGraphSONSerializerV1d0}.
*/
public static StarGraph readStarGraphVertex(final Map<String, Object> vertexData) throws IOException {
final StarGraph starGraph = StarGraph.open();
starGraph.addVertex(T.id, vertexData.get(GraphSONTokens.ID), T.label, vertexData.get(GraphSONTokens.LABEL));
if (vertexData.containsKey(GraphSONTokens.PROPERTIES)) {
final Map<String, List<Map<String, Object>>> properties = (Map<String, List<Map<String, Object>>>) vertexData.get(GraphSONTokens.PROPERTIES);
for (Map.Entry<String, List<Map<String, Object>>> property : properties.entrySet()) {
for (Map<String, Object> p : property.getValue()) {
final StarGraph.StarVertexProperty vp = (StarGraph.StarVertexProperty) starGraph.getStarVertex().property(VertexProperty.Cardinality.list, property.getKey(), p.get(GraphSONTokens.VALUE), T.id, p.get(GraphSONTokens.ID));
if (p.containsKey(GraphSONTokens.PROPERTIES)) {
final Map<String, Object> edgePropertyData = (Map<String, Object>) p.get(GraphSONTokens.PROPERTIES);
for (Map.Entry<String, Object> epd : edgePropertyData.entrySet()) {
vp.property(epd.getKey(), epd.getValue());
}
}
}
}
}
return starGraph;
}
示例14: shouldSerializeDeserialize
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Test
public void shouldSerializeDeserialize() throws Exception {
final GryoMapper mapper = builder.get().create();
final Kryo kryo = mapper.createMapper();
try (final OutputStream stream = new ByteArrayOutputStream()) {
final Output out = new Output(stream);
final Map<String,Object> props = new HashMap<>();
final List<Map<String, Object>> propertyNames = new ArrayList<>(1);
final Map<String,Object> propertyName = new HashMap<>();
propertyName.put(GraphSONTokens.ID, "x");
propertyName.put(GraphSONTokens.KEY, "x");
propertyName.put(GraphSONTokens.VALUE, "no-way-this-will-ever-work");
propertyNames.add(propertyName);
props.put("x", propertyNames);
final DetachedVertex v = new DetachedVertex(100, Vertex.DEFAULT_LABEL, props);
kryo.writeClassAndObject(out, v);
try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) {
final Input input = new Input(inputStream);
final DetachedVertex readX = (DetachedVertex) kryo.readClassAndObject(input);
assertEquals("no-way-this-will-ever-work", readX.value("x"));
}
}
}
示例15: should200OnPOSTWithAuthorizationHeader
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens; //导入依赖的package包/类
@Test
public void should200OnPOSTWithAuthorizationHeader() throws Exception {
final CloseableHttpClient httpclient = HttpClients.createDefault();
final HttpPost httppost = new HttpPost(TestClientFactory.createURLString());
httppost.addHeader("Content-Type", "application/json");
httppost.addHeader("Authorization", "Basic " + encoder.encodeToString("stephen:password".getBytes()));
httppost.setEntity(new StringEntity("{\"gremlin\":\"1-1\"}", Consts.UTF_8));
try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals("application/json", response.getEntity().getContentType().getValue());
final String json = EntityUtils.toString(response.getEntity());
final JsonNode node = mapper.readTree(json);
assertEquals(0, node.get("result").get("data").get(GraphSONTokens.VALUEPROP).get(0).get(GraphSONTokens.VALUEPROP).intValue());
}
}