public static Metadata metadataStringToMap(String metadataString, Visibility visibility) { Metadata metadata = new Metadata(); if (metadataString != null && metadataString.length() > 0) { JSONObject metadataJson = new JSONObject(metadataString); for (Object keyObj : metadataJson.keySet()) { String key = "" + keyObj; metadata.add(key, metadataJson.get(key), visibility); } } return metadata; }
public static Metadata mergeMetadata(Metadata... metadatas) { Metadata mergedMetadata = new Metadata(); for (Metadata metadata : metadatas) { for (Metadata.Entry entry : metadata.entrySet()) { mergedMetadata.add(entry.getKey(), entry.getValue(), entry.getVisibility()); } } return mergedMetadata; } }
public AddPropertyMetadataMutation( long timestamp, String key, String name, Metadata metadata, Visibility visibility) { super(timestamp, key, name, visibility, visibility); this.metadata = Metadata.create(metadata); }
@Override protected void updateMetadata(Property property) { Collection<Metadata.Entry> entries = new ArrayList<>(property.getMetadata().entrySet()); this.metadata.clear(); for (Metadata.Entry metadataEntry : entries) { this.metadata.add(metadataEntry.getKey(), metadataEntry.getValue(), metadataEntry.getVisibility()); } } }
@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 testPropertyHistoricalVersions() { Date time25 = createDate(2015, 4, 6, 16, 15, 0); Date time30 = createDate(2015, 4, 6, 16, 16, 0); Metadata metadata = Metadata.create(); metadata.add("author", "author1", VISIBILITY_A); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("", "age", 25, metadata, time25.getTime(), VISIBILITY_A) .save(AUTHORIZATIONS_A); metadata = Metadata.create(); metadata.add("author", "author2", VISIBILITY_A); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("", "age", 30, metadata, time30.getTime(), VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); List<HistoricalPropertyValue> values = toList(v1.getHistoricalPropertyValues("", "age", VISIBILITY_A, AUTHORIZATIONS_A)); assertEquals(2, values.size()); assertEquals(30, values.get(0).getValue()); assertEquals(time30, new Date(values.get(0).getTimestamp())); assertEquals("author2", values.get(0).getMetadata().getValue("author", VISIBILITY_A)); assertEquals(25, values.get(1).getValue()); assertEquals(time25, new Date(values.get(1).getTimestamp())); assertEquals("author1", values.get(1).getMetadata().getValue("author", VISIBILITY_A)); // make sure we get the correct age when we only ask for one value assertEquals(30, v1.getPropertyValue("", "age")); assertEquals("author2", v1.getProperty("", "age").getMetadata().getValue("author", VISIBILITY_A)); }
@Test public void testChangeVisibilityVertexProperties() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "value1", VISIBILITY_EMPTY); Metadata prop2Metadata = Metadata.create(); prop2Metadata.add("prop2_key1", "value1", VISIBILITY_EMPTY); Property v1Prop1 = v1.getProperty("prop1"); assertNotNull(v1Prop1); Assert.assertEquals(1, toList(v1Prop1.getMetadata().entrySet()).size()); assertEquals("value1", v1Prop1.getMetadata().getValue("prop1_key1")); assertNotNull(v1.getProperty("prop2"));
@Test public void testChangeVertexVisibilityAndAlterPropertyVisibilityAndChangePropertyAtTheSameTime() { Metadata metadata = Metadata.create(); metadata.add("m1", "m1-value1", VISIBILITY_EMPTY); metadata.add("m2", "m2-value1", VISIBILITY_EMPTY); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "age", 25, metadata, VISIBILITY_A) assertEquals("age", properties.get(0).getName()); assertEquals(VISIBILITY_B, properties.get(0).getVisibility()); 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());
private void addPropertyMetadataToKeyValuePairs(List<KeyValuePair> results, Text vertexRowKey, Property property) { Metadata metadata = property.getMetadata(); for (Metadata.Entry metadataItem : metadata.entrySet()) { addPropertyMetadataItemToKeyValuePairs(results, vertexRowKey, property, metadataItem); } }
private void updateProductData(ElementUpdateContext<Vertex> elemCtx, StringVisalloProperty property, JSONObject data) { if (data == null) { return; } Visibility visibility = VISIBILITY.getVisibility(); Metadata metadata = new Metadata(); JSONUtil.streamKeys(data).forEach(key -> { Object valueObject = data.get(key); if (JSONObject.NULL.equals(valueObject)) { property.removeProperty(elemCtx, key, visibility); } else { String value = valueObject.toString(); property.updateProperty(elemCtx, key, value, metadata, visibility); } }); }
@Override protected void updateMetadata(Property property) { this.cachedMetadata = null; if (property instanceof LazyMutableProperty) { this.metadataRef = ((LazyMutableProperty) property).metadataRef; } else { Collection<Metadata.Entry> entries = new ArrayList<>(property.getMetadata().entrySet()); this.metadataRef = null; if (getFetchHints().isIncludePropertyAndMetadata(propertyName)) { for (Metadata.Entry metadataEntry : entries) { getMetadata().add(metadataEntry.getKey(), metadataEntry.getValue(), metadataEntry.getVisibility()); } } } }
public void setMetadata(Metadata metadata, TRaw value, Visibility visibility) { metadata.add(getMetadataKey(), wrap(value), visibility); }
@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)); }
protected void alterElementPropertyMetadata( InMemoryTableElement inMemoryTableElement, List<SetPropertyMetadata> setPropertyMetadatas, Authorizations authorizations ) { for (SetPropertyMetadata spm : setPropertyMetadatas) { Property property = inMemoryTableElement.getProperty( spm.getPropertyKey(), spm.getPropertyName(), spm.getPropertyVisibility(), FetchHints.ALL_INCLUDING_HIDDEN, authorizations ); if (property == null) { throw new VertexiumException("Could not find property " + spm.getPropertyKey() + ":" + spm.getPropertyName()); } Metadata metadata = Metadata.create(property.getMetadata()); metadata.add(spm.getMetadataName(), spm.getNewValue(), spm.getMetadataVisibility()); long newTimestamp = IncreasingTime.currentTimeMillis(); inMemoryTableElement.appendAddPropertyMetadataMutation( property.getKey(), property.getName(), metadata, property.getVisibility(), newTimestamp); } }
default boolean contains(String key, Visibility visibility) { return getEntry(key, visibility) != null; }
private Iterable<Property> getOntologyFiles() { VertexiumConcept rootConcept = (VertexiumConcept) getRootConcept(PUBLIC); checkNotNull(rootConcept, "Could not get root concept"); Vertex rootConceptVertex = rootConcept.getVertex(); checkNotNull(rootConceptVertex, "Could not get root concept vertex"); List<Property> ontologyFiles = Lists.newArrayList(OntologyProperties.ONTOLOGY_FILE.getProperties(rootConceptVertex)); ontologyFiles.sort((ontologyFile1, ontologyFile2) -> { Integer index1 = (Integer) ontologyFile1.getMetadata().getValue("index"); checkNotNull(index1, "Could not find metadata (1) 'index' on " + ontologyFile1); Integer index2 = (Integer) ontologyFile2.getMetadata().getValue("index"); checkNotNull(index2, "Could not find metadata (2) 'index' on " + ontologyFile2); return index1.compareTo(index2); }); return ontologyFiles; }
@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 testPropertyHistoricalVersions() { Date time25 = createDate(2015, 4, 6, 16, 15, 0); Date time30 = createDate(2015, 4, 6, 16, 16, 0); Metadata metadata = Metadata.create(); metadata.add("author", "author1", VISIBILITY_A); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("", "age", 25, metadata, time25.getTime(), VISIBILITY_A) .save(AUTHORIZATIONS_A); metadata = Metadata.create(); metadata.add("author", "author2", VISIBILITY_A); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("", "age", 30, metadata, time30.getTime(), VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A); List<HistoricalPropertyValue> values = toList(v1.getHistoricalPropertyValues("", "age", VISIBILITY_A, AUTHORIZATIONS_A)); assertEquals(2, values.size()); assertEquals(30, values.get(0).getValue()); assertEquals(time30, new Date(values.get(0).getTimestamp())); assertEquals("author2", values.get(0).getMetadata().getValue("author", VISIBILITY_A)); assertEquals(25, values.get(1).getValue()); assertEquals(time25, new Date(values.get(1).getTimestamp())); assertEquals("author1", values.get(1).getMetadata().getValue("author", VISIBILITY_A)); // make sure we get the correct age when we only ask for one value assertEquals(30, v1.getPropertyValue("", "age")); assertEquals("author2", v1.getProperty("", "age").getMetadata().getValue("author", VISIBILITY_A)); }
@Test public void testChangeVisibilityVertexProperties() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "value1", VISIBILITY_EMPTY); Metadata prop2Metadata = Metadata.create(); prop2Metadata.add("prop2_key1", "value1", VISIBILITY_EMPTY); Property v1Prop1 = v1.getProperty("prop1"); assertNotNull(v1Prop1); Assert.assertEquals(1, toList(v1Prop1.getMetadata().entrySet()).size()); assertEquals("value1", v1Prop1.getMetadata().getValue("prop1_key1")); assertNotNull(v1.getProperty("prop2"));