@Override public Map<String, List<Property>> apply(final Traverser<Map<String, List<Property>>> mapTraverser) { final Map<String, List<Property>> values = mapTraverser.get(); final Map<String, List<Property>> filtered = new HashMap<>(); // note the final filter that removes the partitionKey from the outgoing Map values.entrySet().forEach(p -> { final List l = p.getValue().stream().filter(property -> { if (property instanceof VertexProperty) { final Iterator<String> itty = ((VertexProperty) property).values(partitionKey); return itty.hasNext() && readPartitions.contains(itty.next()); } else { return true; } }).filter(property -> !property.key().equals(partitionKey)).collect(Collectors.toList()); if (l.size() > 0) filtered.put(p.getKey(), l); }); return filtered; }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(vp.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals(vp.value(), m.get(GraphSONTokens.VALUE)); assertEquals(vp.values("startTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("startTime")); assertEquals(vp.values("endTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("endTime")); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); assertEquals(vp.values("startTime").next(), detached.values("startTime").next()); assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key()); assertEquals(vp.values("endTime").next(), detached.values("endTime").next()); assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithPropertiesAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final VertexProperty<?> vertexProperty = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, vertexProperty); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final VertexProperty<?> detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class); assertNotNull(detached); assertEquals(vertexProperty.label(), detached.label()); assertEquals(vertexProperty.id(), detached.id()); assertEquals(vertexProperty.value(), detached.value()); assertEquals(vertexProperty.values("startTime").next(), detached.values("startTime").next()); assertEquals(vertexProperty.properties("startTime").next().key(), detached.properties("startTime").next().key()); assertEquals(vertexProperty.values("endTime").next(), detached.values("endTime").next()); assertEquals(vertexProperty.properties("endTime").next().key(), detached.properties("endTime").next().key()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); assertEquals(vp.values("startTime").next(), detached.values("startTime").next()); assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key()); assertEquals(vp.values("endTime").next(), detached.values("endTime").next()); assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithPropertiesAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final VertexProperty<?> vertexProperty = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, vertexProperty); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final VertexProperty<?> detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class); assertNotNull(detached); assertEquals(vertexProperty.label(), detached.label()); assertEquals(vertexProperty.id(), detached.id()); assertEquals(vertexProperty.value(), detached.value()); assertEquals(vertexProperty.values("startTime").next(), detached.values("startTime").next()); assertEquals(vertexProperty.properties("startTime").next().key(), detached.properties("startTime").next().key()); assertEquals(vertexProperty.values("endTime").next(), detached.values("endTime").next()); assertEquals(vertexProperty.properties("endTime").next().key(), detached.properties("endTime").next().key()); }
assertEquals(1, IteratorUtils.count(v.property("age").properties("acl"))); assertEquals(1, IteratorUtils.count(v.property("name").properties("acl"))); assertEquals("private", v.property("age").values("acl").next()); assertEquals("public", v.property("name").values("acl").next()); assertVertexEdgeCounts(graph, 1, 0); }); v.property("age").property("changeDate", 2014); tryCommit(graph, g -> { assertEquals("public", v.property("age").values("acl").next()); assertEquals(2014, v.property("age").values("changeDate").next()); assertEquals(1, IteratorUtils.count(v.properties("age"))); assertEquals(2, IteratorUtils.count(v.properties("age").next().properties()));
@Override public Map<String, List<Property>> apply(final Traverser<Map<String, List<Property>>> mapTraverser) { final Map<String, List<Property>> values = mapTraverser.get(); final Map<String, List<Property>> filtered = new HashMap<>(); // note the final filter that removes the partitionKey from the outgoing Map values.entrySet().forEach(p -> { final List l = p.getValue().stream().filter(property -> { if (property instanceof VertexProperty) { final Iterator<String> itty = ((VertexProperty) property).values(partitionKey); return itty.hasNext() && readPartitions.contains(itty.next()); } else { return true; } }).filter(property -> !property.key().equals(partitionKey)).collect(Collectors.toList()); if (l.size() > 0) filtered.put(p.getKey(), l); }); return filtered; }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(vp.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals(vp.value(), m.get(GraphSONTokens.VALUE)); assertEquals(vp.values("startTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("startTime")); assertEquals(vp.values("endTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("endTime")); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); assertEquals(vp.values("startTime").next(), detached.values("startTime").next()); assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key()); assertEquals(vp.values("endTime").next(), detached.values("endTime").next()); assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); assertEquals(vp.values("startTime").next(), detached.values("startTime").next()); assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key()); assertEquals(vp.values("endTime").next(), detached.values("endTime").next()); assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithPropertiesAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final VertexProperty<?> vertexProperty = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, vertexProperty); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final VertexProperty<?> detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class); assertNotNull(detached); assertEquals(vertexProperty.label(), detached.label()); assertEquals(vertexProperty.id(), detached.id()); assertEquals(vertexProperty.value(), detached.value()); assertEquals(vertexProperty.values("startTime").next(), detached.values("startTime").next()); assertEquals(vertexProperty.properties("startTime").next().key(), detached.properties("startTime").next().key()); assertEquals(vertexProperty.values("endTime").next(), detached.values("endTime").next()); assertEquals(vertexProperty.properties("endTime").next().key(), detached.properties("endTime").next().key()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithPropertiesAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final VertexProperty<?> vertexProperty = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, vertexProperty); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final VertexProperty<?> detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class); assertNotNull(detached); assertEquals(vertexProperty.label(), detached.label()); assertEquals(vertexProperty.id(), detached.id()); assertEquals(vertexProperty.value(), detached.value()); assertEquals(vertexProperty.values("startTime").next(), detached.values("startTime").next()); assertEquals(vertexProperty.properties("startTime").next().key(), detached.properties("startTime").next().key()); assertEquals(vertexProperty.values("endTime").next(), detached.values("endTime").next()); assertEquals(vertexProperty.properties("endTime").next().key(), detached.properties("endTime").next().key()); }
assertEquals(1, IteratorUtils.count(v.property("age").properties("acl"))); assertEquals(1, IteratorUtils.count(v.property("name").properties("acl"))); assertEquals("private", v.property("age").values("acl").next()); assertEquals("public", v.property("name").values("acl").next()); assertVertexEdgeCounts(graph, 1, 0); }); v.property("age").property("changeDate", 2014); tryCommit(graph, g -> { assertEquals("public", v.property("age").values("acl").next()); assertEquals(2014, v.property("age").values("changeDate").next()); assertEquals(1, IteratorUtils.count(v.properties("age"))); assertEquals(2, IteratorUtils.count(v.properties("age").next().properties()));