default boolean contains(String key, Visibility visibility) { return getEntry(key, visibility) != null; }
default boolean contains(String key, Visibility visibility) { return getEntry(key, visibility) != null; }
default Object getValue(String key) { Entry entry = getEntry(key); if (entry == null) { return null; } return entry.getValue(); }
default Object getValue(String key) { Entry entry = getEntry(key); if (entry == null) { return null; } return entry.getValue(); }
default Object getValue(String key, Visibility visibility) { Entry entry = getEntry(key, visibility); if (entry == null) { return null; } return entry.getValue(); }
default Object getValue(String key, Visibility visibility) { Entry entry = getEntry(key, visibility); if (entry == null) { return null; } return entry.getValue(); }
public TRaw getMetadataValue(Metadata metadata, TRaw defaultValue) { if (metadata.getEntry(getMetadataKey()) == null) { return defaultValue; } return unwrap(metadata.getValue(getMetadataKey())); }
private String getProductPreviewDataMd5(Vertex productVertex, User user) { Property previewDataUrlProperty = WorkspaceProperties.PRODUCT_PREVIEW_DATA_URL.getProperty(productVertex, user.getUserId()); String md5 = null; if (previewDataUrlProperty != null) { Metadata.Entry entry = previewDataUrlProperty.getMetadata().getEntry("http://visallo.org/product#previewImageMD5"); if (entry != null) { md5 = (String) entry.getValue(); } } return md5; }
private static ClientApiHistoricalPropertyResults.Event generateGenericEvent(HistoricalPropertyValue hpv) { ClientApiHistoricalPropertyResults.Event event = new ClientApiHistoricalPropertyResults.Event(); event.timestamp = hpv.getTimestamp(); event.propertyKey = hpv.getPropertyKey(); event.propertyName = hpv.getPropertyName(); Metadata.Entry modifiedByEntry = (hpv.getMetadata() != null) ? hpv.getMetadata().getEntry(VisalloProperties.MODIFIED_BY.getPropertyName()) : null; event.modifiedBy = ((modifiedByEntry != null) ? toClientApiValue(modifiedByEntry.getValue()).toString() : null); return event; }
assertEquals(2, properties.get(0).getMetadata().entrySet().size()); assertTrue(properties.get(0).getMetadata().containsKey("m1")); assertEquals("m1-value2", properties.get(0).getMetadata().getEntry("m1").getValue()); assertEquals(VISIBILITY_EMPTY, properties.get(0).getMetadata().getEntry("m1").getVisibility()); assertTrue(properties.get(0).getMetadata().containsKey("m2")); assertEquals("m2-value1", properties.get(0).getMetadata().getEntry("m2").getValue()); assertEquals(VISIBILITY_EMPTY, properties.get(0).getMetadata().getEntry("m2").getVisibility());
@Test public void testChangePropertyMetadata() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "valueOld", VISIBILITY_EMPTY); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", prop1Metadata, VISIBILITY_EMPTY) .setProperty("prop2", "value2", null, VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .setPropertyMetadata("prop1", "prop1_key1", "valueNew", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals("valueNew", v1.getProperty("prop1").getMetadata().getEntry("prop1_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); assertEquals("valueNew", v1.getProperty("prop1").getMetadata().getEntry("prop1_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .setPropertyMetadata("prop2", "prop2_key1", "valueNew", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals("valueNew", v1.getProperty("prop2").getMetadata().getEntry("prop2_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); assertEquals("valueNew", v1.getProperty("prop2").getMetadata().getEntry("prop2_key1", VISIBILITY_EMPTY).getValue()); }
@Test public void testChangePropertyMetadata() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "valueOld", VISIBILITY_EMPTY); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", prop1Metadata, VISIBILITY_EMPTY) .setProperty("prop2", "value2", null, VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .setPropertyMetadata("prop1", "prop1_key1", "valueNew", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals("valueNew", v1.getProperty("prop1").getMetadata().getEntry("prop1_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); assertEquals("valueNew", v1.getProperty("prop1").getMetadata().getEntry("prop1_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); v1.prepareMutation() .setPropertyMetadata("prop2", "prop2_key1", "valueNew", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assertEquals("valueNew", v1.getProperty("prop2").getMetadata().getEntry("prop2_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); assertEquals("valueNew", v1.getProperty("prop2").getMetadata().getEntry("prop2_key1", VISIBILITY_EMPTY).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 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 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 testFetchHintsExceptions() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("metadata1", "metadata1Value", VISIBILITY_A); prop1Metadata.add("metadata2", "metadata2Value", VISIBILITY_A); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); FetchHints propertyFetchHints = FetchHints.builder() .setPropertyNamesToInclude("prop2") .build(); Vertex v1WithOnlyProp2 = graph.getVertex("v1", propertyFetchHints, AUTHORIZATIONS_A); assertNotNull(v1WithOnlyProp2.getProperties()); assertThrowsException(() -> v1WithOnlyProp2.getProperty("prop1")); FetchHints propertiesFetchHints = FetchHints.builder() .setIncludeAllProperties(true) .build(); Vertex v1WithAllProperties = graph.getVertex("v1", propertiesFetchHints, AUTHORIZATIONS_A); assertThrowsException(v1WithAllProperties.getProperty("prop1")::getMetadata); FetchHints metadataFetchHints = FetchHints.builder() .setIncludeAllProperties(true) .setMetadataKeysToInclude("metadata1") .build(); Vertex v1WithOnlyMetadata1 = graph.getVertex("v1", metadataFetchHints, AUTHORIZATIONS_A); Property prop1 = v1WithOnlyMetadata1.getProperty("prop1"); assertNotNull(prop1.getMetadata()); assertNotNull(v1WithOnlyMetadata1.getProperty("prop1").getMetadata().getEntry("metadata1")); assertThrowsException(() -> v1WithOnlyMetadata1.getProperty("prop1").getMetadata().getEntry("metadata2")); }