@Test public void testEmptyPropertyMutation() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v1.prepareMutation().save(AUTHORIZATIONS_ALL); }
@Test public void testEmptyPropertyMutation() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v1.prepareMutation().save(AUTHORIZATIONS_ALL); }
private byte[] createAndSaveCachedImage(Vertex vertex, String propertyKey, String url, int maxWidth, int maxHeight, int jpegQuality, Authorizations authorizations) throws IOException { byte[] imageData = getAndSaveImageData(vertex, url, authorizations); imageData = ImageUtils.resize(imageData, maxWidth, maxHeight, jpegQuality); StreamingPropertyValue value = new StreamingPropertyValue(new ByteArrayInputStream(imageData), byte[].class); value.store(true).searchIndex(false); ExistingElementMutation<Vertex> m = vertex.prepareMutation(); VisalloProperties.CACHED_IMAGE.addPropertyValue(m, propertyKey, value, vertex.getVisibility()); m.save(authorizations); return imageData; }
private byte[] getAndSaveImageData(Vertex vertex, String url, Authorizations authorizations) throws IOException { String propertyKey = getPropertyKey(url, null, null, null); StreamingPropertyValue originalImage = VisalloProperties.CACHED_IMAGE.getPropertyValue(vertex, propertyKey); if (originalImage != null) { return IOUtils.toByteArray(originalImage.getInputStream()); } byte[] imageData = httpRepository.get(url); StreamingPropertyValue value = new StreamingPropertyValue(new ByteArrayInputStream(imageData), byte[].class); value.store(true).searchIndex(false); ExistingElementMutation<Vertex> m = vertex.prepareMutation(); VisalloProperties.CACHED_IMAGE.addPropertyValue(m, propertyKey, value, vertex.getVisibility()); m.save(authorizations); return imageData; }
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 testGraphQueryVertexWithTermsAggregationAlterElementVisibility() { graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "age", 25, VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); v1.prepareMutation() .alterElementVisibility(VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Map<Object, Long> propertyCountByValue = queryGraphQueryWithTermsAggregation("age", ElementType.VERTEX, AUTHORIZATIONS_A_AND_B); assumeTrue("terms aggregation not supported", propertyCountByValue != null); assertEquals(1, propertyCountByValue.size()); propertyCountByValue = queryGraphQueryWithTermsAggregation("age", ElementType.VERTEX, AUTHORIZATIONS_A); assumeTrue("terms aggregation not supported", propertyCountByValue != null); assertEquals(0, propertyCountByValue.size()); propertyCountByValue = queryGraphQueryWithTermsAggregation("age", ElementType.VERTEX, AUTHORIZATIONS_B); assumeTrue("terms aggregation not supported", propertyCountByValue != null); assertEquals(1, propertyCountByValue.size()); }
@Test public void testGraphQueryVertexWithTermsAggregationAlterElementVisibility() { graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "age", 25, VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A_AND_B); v1.prepareMutation() .alterElementVisibility(VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Map<Object, Long> propertyCountByValue = queryGraphQueryWithTermsAggregation("age", ElementType.VERTEX, AUTHORIZATIONS_A_AND_B); assumeTrue("terms aggregation not supported", propertyCountByValue != null); assertEquals(1, propertyCountByValue.size()); propertyCountByValue = queryGraphQueryWithTermsAggregation("age", ElementType.VERTEX, AUTHORIZATIONS_A); assumeTrue("terms aggregation not supported", propertyCountByValue != null); assertEquals(0, propertyCountByValue.size()); propertyCountByValue = queryGraphQueryWithTermsAggregation("age", ElementType.VERTEX, AUTHORIZATIONS_B); assumeTrue("terms aggregation not supported", propertyCountByValue != null); assertEquals(1, propertyCountByValue.size()); }
public <T extends Element> VisibilityAndElementMutation<T> updateElementVisibilitySource( Element element, SandboxStatus sandboxStatus, String visibilitySource, String workspaceId, Authorizations authorizations ) { Visibility defaultVisibility = visibilityTranslator.getDefaultVisibility(); VisibilityJson visibilityJson = VisalloProperties.VISIBILITY_JSON.getPropertyValue(element); visibilityJson = sandboxStatus != SandboxStatus.PUBLIC ? VisibilityJson.updateVisibilitySourceAndAddWorkspaceId(visibilityJson, visibilitySource, workspaceId) : VisibilityJson.updateVisibilitySource(visibilityJson, visibilitySource); VisalloVisibility visalloVisibility = visibilityTranslator.toVisibility(visibilityJson); Visibility visibility = visalloVisibility.getVisibility(); ExistingElementMutation<T> m = element.<T>prepareMutation().alterElementVisibility(visibility); VisalloProperties.VISIBILITY_JSON.setProperty(m, visibilityJson, defaultVisibility); m.save(authorizations); return new VisibilityAndElementMutation<>(visalloVisibility, m); }
@Test public void testChangeVisibilityOnBadPropertyName() { graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_EMPTY) .setProperty("prop2", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); try { graph.getVertex("v1", AUTHORIZATIONS_A) .prepareMutation() .alterPropertyVisibility("propBad", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); fail("show throw"); } catch (VertexiumException ex) { assertNotNull(ex); } }
@Test public void testChangeVisibilityOnBadPropertyName() { graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_EMPTY) .setProperty("prop2", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); try { graph.getVertex("v1", AUTHORIZATIONS_A) .prepareMutation() .alterPropertyVisibility("propBad", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); fail("show throw"); } catch (VertexiumException ex) { assertNotNull(ex); } }
@Test public void testMetadataMutationsOnEdge() { Metadata metadataPropB = Metadata.create(); metadataPropB.add("meta1", "meta1", VISIBILITY_A); Edge edge = graph.prepareEdge("v1", "v2", LABEL_LABEL1, VISIBILITY_A) .setProperty("propBmeta", "propBmeta", metadataPropB, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); graph.flush(); ExistingElementMutation<Edge> m = edge.prepareMutation(); m.setPropertyMetadata("propBmeta", "meta1", "meta2", VISIBILITY_A); edge = m.save(AUTHORIZATIONS_ALL); assertEquals("meta2", edge.getProperty("propBmeta").getMetadata().getEntry("meta1").getValue()); }
@Test public void testMetadataMutationsOnVertex() { Metadata metadataPropB = Metadata.create(); metadataPropB.add("meta1", "meta1", VISIBILITY_A); Vertex vertex = graph.prepareVertex("v1", VISIBILITY_A) .setProperty("propBmeta", "propBmeta", metadataPropB, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); graph.flush(); ExistingElementMutation<Vertex> m = vertex.prepareMutation(); m.setPropertyMetadata("propBmeta", "meta1", "meta2", VISIBILITY_A); vertex = m.save(AUTHORIZATIONS_ALL); assertEquals("meta2", vertex.getProperty("propBmeta").getMetadata().getEntry("meta1").getValue()); }
@Test public void testMetadataMutationsOnEdge() { Metadata metadataPropB = Metadata.create(); metadataPropB.add("meta1", "meta1", VISIBILITY_A); Edge edge = graph.prepareEdge("v1", "v2", LABEL_LABEL1, VISIBILITY_A) .setProperty("propBmeta", "propBmeta", metadataPropB, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); graph.flush(); ExistingElementMutation<Edge> m = edge.prepareMutation(); m.setPropertyMetadata("propBmeta", "meta1", "meta2", VISIBILITY_A); edge = m.save(AUTHORIZATIONS_ALL); assertEquals("meta2", edge.getProperty("propBmeta").getMetadata().getEntry("meta1").getValue()); }
@Test public void testMetadataMutationsOnVertex() { Metadata metadataPropB = Metadata.create(); metadataPropB.add("meta1", "meta1", VISIBILITY_A); Vertex vertex = graph.prepareVertex("v1", VISIBILITY_A) .setProperty("propBmeta", "propBmeta", metadataPropB, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); graph.flush(); ExistingElementMutation<Vertex> m = vertex.prepareMutation(); m.setPropertyMetadata("propBmeta", "meta1", "meta2", VISIBILITY_A); vertex = m.save(AUTHORIZATIONS_ALL); assertEquals("meta2", vertex.getProperty("propBmeta").getMetadata().getEntry("meta1").getValue()); }
@Test public void testSoftDeletePropertyOnEdgeNotIndexed() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_A_AND_B); ElementBuilder<Edge> elementBuilder = graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_B) .setProperty("prop1", "value1", VISIBILITY_B); elementBuilder.setIndexHint(IndexHint.DO_NOT_INDEX); Edge e1 = elementBuilder.save(AUTHORIZATIONS_A_AND_B); graph.flush(); ExistingElementMutation<Edge> m = e1.prepareMutation(); m.softDeleteProperty("prop1", VISIBILITY_B); m.setIndexHint(IndexHint.DO_NOT_INDEX); m.save(AUTHORIZATIONS_A_AND_B); graph.flush(); e1 = graph.getEdge("e1", AUTHORIZATIONS_A_AND_B); assertEquals(0, IterableUtils.count(e1.getProperties())); }
@Test public void testSoftDeletePropertyOnEdgeNotIndexed() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_A_AND_B); ElementBuilder<Edge> elementBuilder = graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_B) .setProperty("prop1", "value1", VISIBILITY_B); elementBuilder.setIndexHint(IndexHint.DO_NOT_INDEX); Edge e1 = elementBuilder.save(AUTHORIZATIONS_A_AND_B); graph.flush(); ExistingElementMutation<Edge> m = e1.prepareMutation(); m.softDeleteProperty("prop1", VISIBILITY_B); m.setIndexHint(IndexHint.DO_NOT_INDEX); m.save(AUTHORIZATIONS_A_AND_B); graph.flush(); e1 = graph.getEdge("e1", AUTHORIZATIONS_A_AND_B); assertEquals(0, IterableUtils.count(e1.getProperties())); }
@Test public void testMetadata() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); ExistingElementMutation<Vertex> m = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B).prepareMutation(); m.setPropertyMetadata(v1.getProperty("prop1", VISIBILITY_A), "metadata1", "metadata-value1aa", VISIBILITY_A); m.setPropertyMetadata(v1.getProperty("prop1", VISIBILITY_A), "metadata1", "metadata-value1ab", VISIBILITY_B); m.setPropertyMetadata(v1.getProperty("prop1", VISIBILITY_B), "metadata1", "metadata-value1bb", VISIBILITY_B); m.save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); Property prop1A = v1.getProperty("prop1", VISIBILITY_A); assertEquals(2, prop1A.getMetadata().entrySet().size()); assertEquals("metadata-value1aa", prop1A.getMetadata().getValue("metadata1", VISIBILITY_A)); assertEquals("metadata-value1ab", prop1A.getMetadata().getValue("metadata1", VISIBILITY_B)); Property prop1B = v1.getProperty("prop1", VISIBILITY_B); assertEquals(1, prop1B.getMetadata().entrySet().size()); assertEquals("metadata-value1bb", prop1B.getMetadata().getValue("metadata1", VISIBILITY_B)); }
@Test public void testMutationChangePropertyVisibilityFollowedByMetadataUsingPropertyObject() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "valueOld", VISIBILITY_A); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); Property p1 = v1.getProperty("prop1", VISIBILITY_A); v1.prepareMutation() .alterPropertyVisibility(p1, VISIBILITY_B) .setPropertyMetadata(p1, "prop1_key1", "valueNew", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); assertEquals("valueNew", v1.getProperty("prop1", VISIBILITY_B).getMetadata().getEntry("prop1_key1", VISIBILITY_B).getValue()); }
@Test public void testMutationChangePropertyVisibilityFollowedByMetadataUsingPropertyObject() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "valueOld", VISIBILITY_A); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); Property p1 = v1.getProperty("prop1", VISIBILITY_A); v1.prepareMutation() .alterPropertyVisibility(p1, VISIBILITY_B) .setPropertyMetadata(p1, "prop1_key1", "valueNew", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); assertEquals("valueNew", v1.getProperty("prop1", VISIBILITY_B).getMetadata().getEntry("prop1_key1", VISIBILITY_B).getValue()); }
@Override public void execute(InputStream in, GraphPropertyWorkData data) throws Exception { String fileName = VisalloProperties.FILE_NAME.getOnlyPropertyValue(data.getElement()); String mimeType = getMimeType(in, fileName); if (mimeType == null) { return; } ExistingElementMutation<Vertex> m = ((Vertex) data.getElement()).prepareMutation(); Metadata mimeTypeMetadata = data.createPropertyMetadata(getUser()); VisalloProperties.MIME_TYPE.addPropertyValue(m, getMultiKey(data.getProperty()), mimeType, mimeTypeMetadata, data.getProperty().getVisibility()); m.setPropertyMetadata(data.getProperty(), VisalloProperties.MIME_TYPE.getPropertyName(), mimeType, getVisibilityTranslator().getDefaultVisibility()); m.save(getAuthorizations()); getGraph().flush(); runPostMimeTypeWorkers(mimeType, data); getWorkQueueRepository().pushGraphPropertyQueue(data.getElement(), data.getProperty(), data.getWorkspaceId(), data.getVisibilitySource(), data.getPriority()); }