public void alterVisibility(ExistingElementMutation<?> elementMutation, Visibility newVisibility) { elementMutation.alterPropertyVisibility(getPropertyName(), newVisibility); }
public void alterVisibility(ExistingElementMutation<?> elementMutation, String propertyKey, Visibility newVisibility) { elementMutation.alterPropertyVisibility(propertyKey, getPropertyName(), newVisibility); }
.alterPropertyVisibility("prop1_A", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); .alterPropertyVisibility("prop1_A", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush();
public void updateVisibility(Vertex termMention, Visibility newVisibility, Authorizations authorizations) { Authorizations authorizationsWithTermMention = getAuthorizations(authorizations); Visibility newVisibilityWithTermMention = VisalloVisibility.and(newVisibility, VISIBILITY_STRING); ExistingElementMutation<Vertex> m = termMention.prepareMutation(); m.alterElementVisibility(newVisibilityWithTermMention); for (Property property : termMention.getProperties()) { m.alterPropertyVisibility(property, newVisibilityWithTermMention); } Property refPropertyVisibility = VisalloProperties.TERM_MENTION_REF_PROPERTY_VISIBILITY.getProperty(termMention); if (refPropertyVisibility != null) { VisalloProperties.TERM_MENTION_REF_PROPERTY_VISIBILITY.setProperty( m, newVisibility.getVisibilityString(), refPropertyVisibility.getMetadata(), newVisibilityWithTermMention ); } m.save(authorizationsWithTermMention); for (Edge edge : termMention.getEdges(Direction.BOTH, authorizationsWithTermMention)) { ExistingElementMutation<Edge> edgeMutation = edge.prepareMutation(); edgeMutation.alterElementVisibility(newVisibilityWithTermMention); for (Property property : edge.getProperties()) { edgeMutation.alterPropertyVisibility(property, newVisibilityWithTermMention); } edgeMutation.save(authorizationsWithTermMention); } }
@Test public void testChangeVisibilityOnStreamingProperty() throws IOException { String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE)); PropertyValue propSmall = StreamingPropertyValue.create(new ByteArrayInputStream("value1".getBytes()), String.class); PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class); String largePropertyName = "propLarge/\\*!@#$%^&*()[]{}|"; graph.prepareVertex("v1", VISIBILITY_A) .setProperty("propSmall", propSmall, VISIBILITY_A) .setProperty(largePropertyName, propLarge, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Assert.assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties())); graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A) .prepareMutation() .alterPropertyVisibility("propSmall", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Assert.assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties())); graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A) .prepareMutation() .alterPropertyVisibility(largePropertyName, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Assert.assertEquals(0, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties())); Assert.assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); }
@Test public void testChangeVisibilityOnStreamingProperty() throws IOException { String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE)); PropertyValue propSmall = StreamingPropertyValue.create(new ByteArrayInputStream("value1".getBytes()), String.class); PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class); String largePropertyName = "propLarge/\\*!@#$%^&*()[]{}|"; graph.prepareVertex("v1", VISIBILITY_A) .setProperty("propSmall", propSmall, VISIBILITY_A) .setProperty(largePropertyName, propLarge, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Assert.assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties())); graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A) .prepareMutation() .alterPropertyVisibility("propSmall", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Assert.assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties())); graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A) .prepareMutation() .alterPropertyVisibility(largePropertyName, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Assert.assertEquals(0, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties())); Assert.assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties())); }
@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); } }
m.alterElementVisibility(VISIBILITY_B); for (Property property : v1.getProperties()) { m.alterPropertyVisibility(property, VISIBILITY_B); m.setPropertyMetadata(property, "m1", "m1-value2", VISIBILITY_EMPTY);
@Test public void testAlterVisibilityAndSetMetadataInOneMutation() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "metadata1", VISIBILITY_EMPTY); graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); v1.prepareMutation() .alterPropertyVisibility("prop1", VISIBILITY_B) .setPropertyMetadata("prop1", "prop1_key1", "metadata1New", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); assertNotNull(v1.getProperty("prop1")); assertEquals(VISIBILITY_B, v1.getProperty("prop1").getVisibility()); assertEquals("metadata1New", v1.getProperty("prop1").getMetadata().getValue("prop1_key1")); List<HistoricalPropertyValue> historicalPropertyValues = toList(v1.getHistoricalPropertyValues(AUTHORIZATIONS_A_AND_B)); assertEquals(2, historicalPropertyValues.size()); assertEquals("metadata1New", historicalPropertyValues.get(0).getMetadata().getValue("prop1_key1")); assertEquals("metadata1", historicalPropertyValues.get(1).getMetadata().getValue("prop1_key1")); }
m.alterElementVisibility(VISIBILITY_B); for (Property property : v1.getProperties()) { m.alterPropertyVisibility(property, VISIBILITY_B); m.setPropertyMetadata(property, "m1", "m1-value2", VISIBILITY_EMPTY);
.alterPropertyVisibility(property, newVisibility); VisalloProperties.VISIBILITY_JSON_METADATA.setMetadata(m, property, newVisibilityJson, defaultVisibility); T newElement = m.save(authorizations);
@Test public void testAlterVisibilityAndSetMetadataInOneMutation() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "metadata1", VISIBILITY_EMPTY); graph.prepareVertex("v1", VISIBILITY_EMPTY) .setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); v1.prepareMutation() .alterPropertyVisibility("prop1", VISIBILITY_B) .setPropertyMetadata("prop1", "prop1_key1", "metadata1New", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); assertNotNull(v1.getProperty("prop1")); assertEquals(VISIBILITY_B, v1.getProperty("prop1").getVisibility()); assertEquals("metadata1New", v1.getProperty("prop1").getMetadata().getValue("prop1_key1")); List<HistoricalPropertyValue> historicalPropertyValues = toList(v1.getHistoricalPropertyValues(AUTHORIZATIONS_A_AND_B)); assertEquals(2, historicalPropertyValues.size()); assertEquals("metadata1New", historicalPropertyValues.get(0).getMetadata().getValue("prop1_key1")); assertEquals("metadata1", historicalPropertyValues.get(1).getMetadata().getValue("prop1_key1")); }
.alterPropertyVisibility(property, visalloVisibility.getVisibility()) .setPropertyMetadata( property,
@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()); }
@Test public void testAlterPropertyVisibilityOfGeoLocation() { graph.defineProperty("prop1").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("prop2").dataType(GeoPoint.class).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("key1", "prop1", "value1", VISIBILITY_A) .addPropertyValue("key1", "prop2", new GeoPoint(38.9186, -77.2297, "Reston, VA"), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .alterPropertyVisibility(v1.getProperty("key1", "prop1", VISIBILITY_A), VISIBILITY_EMPTY) .alterPropertyVisibility(v1.getProperty("key1", "prop2", VISIBILITY_A), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_EMPTY).has("prop1", "value1").vertices(); assertVertexIdsAnyOrder(vertices, "v1"); assertResultsCount(1, 1, vertices); vertices = graph.query(AUTHORIZATIONS_EMPTY).has("prop2", "reston, va").vertices(); assertVertexIdsAnyOrder(vertices, "v1"); assertResultsCount(1, 1, vertices); QueryResultsIterable<String> vertexIds = graph.query(AUTHORIZATIONS_EMPTY).has("prop2", GeoCompare.WITHIN, new GeoCircle(38.9186, -77.2297, 1)).vertexIds(); assertIdsAnyOrder(vertexIds, "v1"); assertResultsCount(1, 1, vertexIds); vertices = graph.query(AUTHORIZATIONS_EMPTY).has("prop2", GeoCompare.WITHIN, new GeoCircle(38.9186, -77.2297, 1)).vertices(); assertVertexIdsAnyOrder(vertices, "v1"); assertResultsCount(1, 1, vertices); }
@Test public void testAlterPropertyVisibilityOfGeoLocation() { graph.defineProperty("prop1").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("prop2").dataType(GeoPoint.class).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("key1", "prop1", "value1", VISIBILITY_A) .addPropertyValue("key1", "prop2", new GeoPoint(38.9186, -77.2297, "Reston, VA"), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .alterPropertyVisibility(v1.getProperty("key1", "prop1", VISIBILITY_A), VISIBILITY_EMPTY) .alterPropertyVisibility(v1.getProperty("key1", "prop2", VISIBILITY_A), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_EMPTY).has("prop1", "value1").vertices(); assertVertexIdsAnyOrder(vertices, "v1"); assertResultsCount(1, 1, vertices); vertices = graph.query(AUTHORIZATIONS_EMPTY).has("prop2", "reston, va").vertices(); assertVertexIdsAnyOrder(vertices, "v1"); assertResultsCount(1, 1, vertices); QueryResultsIterable<String> vertexIds = graph.query(AUTHORIZATIONS_EMPTY).has("prop2", GeoCompare.WITHIN, new GeoCircle(38.9186, -77.2297, 1)).vertexIds(); assertIdsAnyOrder(vertexIds, "v1"); assertResultsCount(1, 1, vertexIds); vertices = graph.query(AUTHORIZATIONS_EMPTY).has("prop2", GeoCompare.WITHIN, new GeoCircle(38.9186, -77.2297, 1)).vertices(); assertVertexIdsAnyOrder(vertices, "v1"); assertResultsCount(1, 1, vertices); }
@Test public void testAlterPropertyVisibilityOverwritingProperty() { graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("", "prop1", "value1", VISIBILITY_EMPTY) .addPropertyValue("", "prop1", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); long beforeAlterTimestamp = IncreasingTime.currentTimeMillis(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .alterPropertyVisibility(v1.getProperty("", "prop1", VISIBILITY_A), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals(1, count(v1.getProperties())); assertNotNull(v1.getProperty("", "prop1", VISIBILITY_EMPTY)); assertEquals("value2", v1.getProperty("", "prop1", VISIBILITY_EMPTY).getValue()); assertNull(v1.getProperty("", "prop1", VISIBILITY_A)); v1 = graph.getVertex("v1", graph.getDefaultFetchHints(), beforeAlterTimestamp, AUTHORIZATIONS_A); assertEquals(2, count(v1.getProperties())); assertNotNull(v1.getProperty("", "prop1", VISIBILITY_EMPTY)); assertEquals("value1", v1.getProperty("", "prop1", VISIBILITY_EMPTY).getValue()); assertNotNull(v1.getProperty("", "prop1", VISIBILITY_A)); assertEquals("value2", v1.getProperty("", "prop1", VISIBILITY_A).getValue()); }
@Test public void testAlterPropertyVisibilityOverwritingProperty() { graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("", "prop1", "value1", VISIBILITY_EMPTY) .addPropertyValue("", "prop1", "value2", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); long beforeAlterTimestamp = IncreasingTime.currentTimeMillis(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .alterPropertyVisibility(v1.getProperty("", "prop1", VISIBILITY_A), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals(1, count(v1.getProperties())); assertNotNull(v1.getProperty("", "prop1", VISIBILITY_EMPTY)); assertEquals("value2", v1.getProperty("", "prop1", VISIBILITY_EMPTY).getValue()); assertNull(v1.getProperty("", "prop1", VISIBILITY_A)); v1 = graph.getVertex("v1", graph.getDefaultFetchHints(), beforeAlterTimestamp, AUTHORIZATIONS_A); assertEquals(2, count(v1.getProperties())); assertNotNull(v1.getProperty("", "prop1", VISIBILITY_EMPTY)); assertEquals("value1", v1.getProperty("", "prop1", VISIBILITY_EMPTY).getValue()); assertNotNull(v1.getProperty("", "prop1", VISIBILITY_A)); assertEquals("value2", v1.getProperty("", "prop1", VISIBILITY_A).getValue()); }