private String columnVertexToString(VertexiumCypherQueryContext ctx, Vertex vertex) { StringBuilder result = new StringBuilder(); result.append("("); int propertyCount = 0; for (Property property : vertex.getProperties()) { if (property.getName().equals(ctx.getLabelPropertyName())) { result.append(":"); result.append(property.getValue()); } else { propertyCount++; } } if (propertyCount > 0) { if (result.length() > "(".length()) { result.append(" "); } result.append(elementPropertiesToString(ctx, vertex)); } result.append(")"); return result.toString(); }
@Override public Map<Object, Long> getVertexPropertyCountByValue(String propertyName, Authorizations authorizations) { Map<Object, Long> countsByValue = new HashMap<>(); for (Vertex v : getVertices(authorizations)) { for (Property p : v.getProperties()) { if (propertyName.equals(p.getName())) { Object mapKey = p.getValue(); if (mapKey instanceof String) { mapKey = ((String) mapKey).toLowerCase(); } Long currentValue = countsByValue.get(mapKey); if (currentValue == null) { countsByValue.put(mapKey, 1L); } else { countsByValue.put(mapKey, currentValue + 1); } } } } return countsByValue; }
@Override public Map<Object, Long> getVertexPropertyCountByValue(String propertyName, Authorizations authorizations) { Map<Object, Long> countsByValue = new HashMap<>(); for (Vertex v : getVertices(authorizations)) { for (Property p : v.getProperties()) { if (propertyName.equals(p.getName())) { Object mapKey = p.getValue(); if (mapKey instanceof String) { mapKey = ((String) mapKey).toLowerCase(); } Long currentValue = countsByValue.get(mapKey); if (currentValue == null) { countsByValue.put(mapKey, 1L); } else { countsByValue.put(mapKey, currentValue + 1); } } } } return countsByValue; }
public VertexiumUser(Vertex userVertex) { this.userId = userVertex.getId(); for (Property property : userVertex.getProperties()) { this.properties.put(property.getName(), property.getValue()); } }
private void deleteChangeableProperties(Vertex vertex, Authorizations authorizations) { for (Property property : vertex.getProperties()) { if (OntologyProperties.CHANGEABLE_PROPERTY_IRI.contains(property.getName())) { vertex.softDeleteProperty(property.getKey(), property.getName(), authorizations); } } graph.flush(); }
private void publishGlyphIconProperties(Edge hasImageEdge, String workspaceId, Authorizations authorizations) { Vertex entityVertex = hasImageEdge.getVertex(Direction.OUT, authorizations); checkNotNull(entityVertex, "Could not find has image source vertex " + hasImageEdge.getVertexId(Direction.OUT)); ExistingElementMutation elementMutation = entityVertex.prepareMutation(); Iterable<Property> glyphIconProperties = entityVertex.getProperties(VisalloProperties.ENTITY_IMAGE_VERTEX_ID.getPropertyName()); for (Property glyphIconProperty : glyphIconProperties) { if (publishNewProperty(elementMutation, glyphIconProperty, workspaceId)) { elementMutation.save(authorizations); return; } } LOGGER.warn("new has image edge without a glyph icon property being set on vertex %s", entityVertex.getId()); }
@Test public void testAddVertexWithPropertiesWithTwoDifferentVisibilities() { Vertex v = graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", "value1a", VISIBILITY_A) .setProperty("prop1", "value1b", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); Assert.assertEquals(2, count(v.getProperties("prop1"))); graph.flush(); v = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); Assert.assertEquals(2, count(v.getProperties("prop1"))); v = graph.getVertex("v1", AUTHORIZATIONS_A); Assert.assertEquals(1, count(v.getProperties("prop1"))); assertEquals("value1a", v.getPropertyValue("prop1")); v = graph.getVertex("v1", AUTHORIZATIONS_B); Assert.assertEquals(1, count(v.getProperties("prop1"))); assertEquals("value1b", v.getPropertyValue("prop1")); }
@Test public void testAddVertexWithPropertiesWithTwoDifferentVisibilities() { Vertex v = graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", "value1a", VISIBILITY_A) .setProperty("prop1", "value1b", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); Assert.assertEquals(2, count(v.getProperties("prop1"))); graph.flush(); v = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); Assert.assertEquals(2, count(v.getProperties("prop1"))); v = graph.getVertex("v1", AUTHORIZATIONS_A); Assert.assertEquals(1, count(v.getProperties("prop1"))); assertEquals("value1a", v.getPropertyValue("prop1")); v = graph.getVertex("v1", AUTHORIZATIONS_B); Assert.assertEquals(1, count(v.getProperties("prop1"))); assertEquals("value1b", v.getPropertyValue("prop1")); }
@Handle public ClientApiDetectedObjects handle( @Required(name = "graphVertexId") String graphVertexId, @Required(name = "propertyName") String propertyName, @Required(name = "workspaceId") String workspaceId, Authorizations authorizations ) throws Exception { Vertex vertex = graph.getVertex(graphVertexId, authorizations); if (vertex == null) { throw new VisalloResourceNotFoundException(String.format("vertex %s not found", graphVertexId)); } ClientApiDetectedObjects detectedObjects = new ClientApiDetectedObjects(); Iterable<Property> detectedObjectProperties = vertex.getProperties(propertyName); if (detectedObjectProperties == null || IterableUtils.count(detectedObjectProperties) == 0) { throw new VisalloResourceNotFoundException(String.format("property %s not found on vertex %s", propertyName, vertex.getId())); } detectedObjects.addDetectedObjects(ClientApiConverter.toClientApiProperties(detectedObjectProperties, workspaceId)); return detectedObjects; }
@Test public void testConcurrentModificationOfProperties() { Vertex v = graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", "value1", VISIBILITY_A) .setProperty("prop2", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); int i = 0; for (Property p : v.getProperties()) { assertNotNull(p.toString()); if (i == 0) { v.setProperty("prop3", "value3", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); } i++; } }
@Test public void testConcurrentModificationOfProperties() { Vertex v = graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", "value1", VISIBILITY_A) .setProperty("prop2", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); int i = 0; for (Property p : v.getProperties()) { assertNotNull(p.toString()); if (i == 0) { v.setProperty("prop3", "value3", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); } i++; } }
@Test public void testAddRowMultipleTimes() throws Exception { String[] row = new String[]{"John Smith", "3/13/2015", "yes"}; doParse(false, true, 0, row); Iterable<Vertex> vertices = getGraph().getVertices(authorizations); assertEquals("Expected new vertices to be created", 3, Iterables.size(vertices)); List<Vertex> generated = getGenerated(); assertEquals("Should have created 2 entities", 2, generated.size()); Predicate<? super Vertex> hasOneConceptType = vertex -> { List<Property> properties = Lists.newArrayList(vertex.getProperties(VisalloProperties.CONCEPT_TYPE.getPropertyName())); return properties.size() == 1; }; assertTrue("All have one concept type", generated.stream().allMatch(hasOneConceptType)); parserHandler.cleanUpExistingImport(); assertEquals("No linked entities after cleaning", 0, getGenerated().size()); doParse(false, true, 0, row); assertTrue("All have one concept type after reimport", getGenerated().stream().allMatch(hasOneConceptType)); }
@Test public void testElementMutationDoesntChangeObjectUntilSave() { Vertex v = graph.addVertex("v1", VISIBILITY_EMPTY, AUTHORIZATIONS_ALL); v.setProperty("prop1", "value1-1", VISIBILITY_A, AUTHORIZATIONS_ALL); graph.flush(); ElementMutation<Vertex> m = v.prepareMutation() .setProperty("prop1", "value1-2", VISIBILITY_A) .setProperty("prop2", "value2-2", VISIBILITY_A); Assert.assertEquals(1, count(v.getProperties())); assertEquals("value1-1", v.getPropertyValue("prop1")); v = m.save(AUTHORIZATIONS_A_AND_B); Assert.assertEquals(2, count(v.getProperties())); assertEquals("value1-2", v.getPropertyValue("prop1")); assertEquals("value2-2", v.getPropertyValue("prop2")); }
@Test public void testElementMutationDoesntChangeObjectUntilSave() { Vertex v = graph.addVertex("v1", VISIBILITY_EMPTY, AUTHORIZATIONS_ALL); v.setProperty("prop1", "value1-1", VISIBILITY_A, AUTHORIZATIONS_ALL); graph.flush(); ElementMutation<Vertex> m = v.prepareMutation() .setProperty("prop1", "value1-2", VISIBILITY_A) .setProperty("prop2", "value2-2", VISIBILITY_A); Assert.assertEquals(1, count(v.getProperties())); assertEquals("value1-1", v.getPropertyValue("prop1")); v = m.save(AUTHORIZATIONS_A_AND_B); Assert.assertEquals(2, count(v.getProperties())); assertEquals("value1-2", v.getPropertyValue("prop1")); assertEquals("value2-2", v.getPropertyValue("prop2")); }
@Test public void testSoftDeletePropertyWithVisibility() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); org.vertexium.test.util.IterableUtils.assertContains("value1", v1.getPropertyValues("name1")); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).softDeleteProperty("key1", "name1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getPropertyValues("key1", "name1"))); org.vertexium.test.util.IterableUtils.assertContains("value2", graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getPropertyValues("name1")); }
@Test public void testSoftDeletePropertyWithVisibility() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); org.vertexium.test.util.IterableUtils.assertContains("value1", v1.getPropertyValues("name1")); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).softDeleteProperty("key1", "name1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getPropertyValues("key1", "name1"))); org.vertexium.test.util.IterableUtils.assertContains("value2", graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getPropertyValues("name1")); }
@Test public void testSoftDeletePropertyThroughMutationWithVisibility() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); org.vertexium.test.util.IterableUtils.assertContains("value1", v1.getPropertyValues("name1")); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B) .prepareMutation() .softDeleteProperty("key1", "name1", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(1, count(v1.getProperties())); assertEquals(1, count(v1.getPropertyValues("key1", "name1"))); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); }
@Test public void testSoftDeletePropertyThroughMutationWithVisibility() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value1", VISIBILITY_A) .addPropertyValue("key1", "name1", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); org.vertexium.test.util.IterableUtils.assertContains("value1", v1.getPropertyValues("name1")); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B) .prepareMutation() .softDeleteProperty("key1", "name1", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals(1, count(v1.getProperties())); assertEquals(1, count(v1.getPropertyValues("key1", "name1"))); org.vertexium.test.util.IterableUtils.assertContains("value2", v1.getPropertyValues("name1")); }
@Override public void softDeleteVertex(Vertex vertex, Long timestamp, Authorizations authorizations) { if (!((InMemoryVertex) vertex).canRead(authorizations)) { return; } if (timestamp == null) { timestamp = IncreasingTime.currentTimeMillis(); } for (Property property : vertex.getProperties()) { vertex.softDeleteProperty(property.getKey(), property.getName(), property.getVisibility(), authorizations); } List<Edge> edgesToSoftDelete = IterableUtils.toList(vertex.getEdges(Direction.BOTH, authorizations)); for (Edge edgeToSoftDelete : edgesToSoftDelete) { softDeleteEdge(edgeToSoftDelete, timestamp, authorizations); } this.vertices.getTableElement(vertex.getId()).appendSoftDeleteMutation(timestamp); getSearchIndex().deleteElement(this, vertex, authorizations); if (hasEventListeners()) { fireGraphEvent(new SoftDeleteVertexEvent(this, vertex)); } }
private FaunusVertex createFaunusVertexFromRow(AccumuloGraph graph, PeekingIterator<Map.Entry<Key, Value>> row, Authorizations authorizations) { final Vertex v = AccumuloVertexInputFormat.createVertex(graph, row, authorizations); final long vertexId = toFaunusVertexId(v.getId()); FaunusVertex faunusVertex = new FaunusVertex(); faunusVertex.setId(vertexId); faunusVertex.setVertexLabel(v.getId()); faunusVertex.addProperty("vertexiumId", v.getId()); for (Property property : v.getProperties()) { if (property.getValue() instanceof StreamingPropertyValue) { continue; } faunusVertex.addProperty(property.getName(), property.getValue()); } for (EdgeInfo edgeInfo : v.getEdgeInfos(Direction.OUT, authorizations)) { faunusVertex.addEdge(com.tinkerpop.blueprints.Direction.OUT, edgeInfo.getLabel(), toFaunusVertexId(edgeInfo.getVertexId())); } for (EdgeInfo edgeInfo : v.getEdgeInfos(Direction.IN, authorizations)) { faunusVertex.addEdge(com.tinkerpop.blueprints.Direction.IN, edgeInfo.getLabel(), toFaunusVertexId(edgeInfo.getVertexId())); } return faunusVertex; }