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 void setMetadata(Metadata metadata, TRaw value, Visibility visibility) { metadata.add(getMetadataKey(), wrap(value), visibility); }
@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()); } } }
@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()); } } }
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; } }
@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()); } } } }
@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()); } } } }
private void createVertex(String data, String mimeType) throws UnsupportedEncodingException { VertexBuilder v = getGraph().prepareVertex("v1", visibility); StreamingPropertyValue textValue = new StreamingPropertyValue(new ByteArrayInputStream(data.getBytes("UTF-8")), byte[].class); textValue.searchIndex(false); Metadata metadata = new Metadata(); metadata.add(VisalloProperties.MIME_TYPE.getPropertyName(), mimeType, getVisibilityTranslator().getDefaultVisibility()); VisalloProperties.RAW.setProperty(v, textValue, metadata, visibility); v.save(getGraphAuthorizations()); }
public Metadata createMetadata() { Metadata metadata = new Metadata(); VisalloProperties.MODIFIED_DATE_METADATA.setMetadata(metadata, modifiedDate, DEFAULT_VISIBILITY); VisalloProperties.MODIFIED_BY_METADATA.setMetadata(metadata, modifiedBy.getUserId(), DEFAULT_VISIBILITY); VisalloProperties.VISIBILITY_JSON_METADATA.setMetadata(metadata, visibilityJson, DEFAULT_VISIBILITY); if (confidence != null) { VisalloProperties.CONFIDENCE_METADATA.setMetadata(metadata, confidence, DEFAULT_VISIBILITY); } if (derivedFromProperty != null) { VisalloProperties.DERIVED_FROM_METADATA.setMetadata(metadata, derivedFromProperty, DEFAULT_VISIBILITY); } for (AdditionalMetadataItem additionalMetadataItem : additionalMetadataItems) { metadata.add( additionalMetadataItem.getKey(), additionalMetadataItem.getValue(), additionalMetadataItem.getVisibility() ); } return metadata; }
@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()); }
void alterPropertyMetadatas(AccumuloElement element, List<SetPropertyMetadata> setPropertyMetadatas) { if (setPropertyMetadatas.size() == 0) { return; } String elementRowKey = element.getId(); Mutation m = new Mutation(elementRowKey); for (SetPropertyMetadata apm : setPropertyMetadatas) { Property property = element.getProperty(apm.getPropertyKey(), apm.getPropertyName(), apm.getPropertyVisibility()); if (property == null) { throw new VertexiumException(String.format("Could not find property %s:%s(%s)", apm.getPropertyKey(), apm.getPropertyName(), apm.getPropertyVisibility())); } if (property.getFetchHints().isIncludePropertyAndMetadata(property.getName())) { property.getMetadata().add(apm.getMetadataName(), apm.getNewValue(), apm.getMetadataVisibility()); } elementMutationBuilder.addPropertyMetadataItemToMutation( m, property, apm.getMetadataName(), apm.getNewValue(), apm.getMetadataVisibility() ); } addMutations(element, m); }
@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()); }
void alterPropertyMetadatas(AccumuloElement element, List<SetPropertyMetadata> setPropertyMetadatas) { if (setPropertyMetadatas.size() == 0) { return; } String elementRowKey = element.getId(); Mutation m = new Mutation(elementRowKey); for (SetPropertyMetadata apm : setPropertyMetadatas) { Property property = element.getProperty(apm.getPropertyKey(), apm.getPropertyName(), apm.getPropertyVisibility()); if (property == null) { throw new VertexiumException(String.format("Could not find property %s:%s(%s)", apm.getPropertyKey(), apm.getPropertyName(), apm.getPropertyVisibility())); } if (property.getFetchHints().isIncludePropertyAndMetadata(property.getName())) { property.getMetadata().add(apm.getMetadataName(), apm.getNewValue(), apm.getMetadataVisibility()); } elementMutationBuilder.addPropertyMetadataItemToMutation( m, property, apm.getMetadataName(), apm.getNewValue(), apm.getMetadataVisibility() ); } addMutations(element, m); }
@Test public void testMultipleRaws() throws UnsupportedEncodingException { VertexBuilder v = getGraph().prepareVertex("v1", visibility); StreamingPropertyValue textValue = new StreamingPropertyValue(new ByteArrayInputStream("<html><body>Text1</body></html>".getBytes("UTF-8")), byte[].class); textValue.searchIndex(false); Metadata metadata = new Metadata(); metadata.add(VisalloProperties.MIME_TYPE.getPropertyName(), "text/html", getVisibilityTranslator().getDefaultVisibility()); v.setProperty("http://visallo.org/test#raw1", textValue, metadata, visibility); textValue = new StreamingPropertyValue(new ByteArrayInputStream("<html><body>Text2</body></html>".getBytes("UTF-8")), byte[].class); textValue.searchIndex(false); metadata = new Metadata(); metadata.add(VisalloProperties.MIME_TYPE.getPropertyName(), "text/html", getVisibilityTranslator().getDefaultVisibility()); v.setProperty("http://visallo.org/test#raw2", textValue, metadata, visibility); v.save(getGraphAuthorizations()); Vertex vertex = getGraph().getVertex("v1", getGraphAuthorizations()); run(gpw, createWorkerPrepareData(), vertex); Property text1Property = vertex.getProperty("http://visallo.org/test#text1"); assertTrue(text1Property != null); assertThat(((StreamingPropertyValue) text1Property.getValue()).readToString(), equalTo("Text1")); assertThat(VisalloProperties.TEXT_DESCRIPTION_METADATA.getMetadataValue(text1Property.getMetadata()), equalTo("Text 1")); Property text2Property = vertex.getProperty("http://visallo.org/test#text2"); assertTrue(text2Property != null); assertThat(((StreamingPropertyValue) text2Property.getValue()).readToString(), equalTo("Text2")); assertThat(VisalloProperties.TEXT_DESCRIPTION_METADATA.getMetadataValue(text2Property.getMetadata()), equalTo(null)); }
@Test public void testDifferentKey() throws UnsupportedEncodingException { VertexBuilder v = getGraph().prepareVertex("v1", visibility); StreamingPropertyValue textValue = new StreamingPropertyValue(new ByteArrayInputStream("<html><body>Text1</body></html>".getBytes("UTF-8")), byte[].class); textValue.searchIndex(false); Metadata metadata = new Metadata(); metadata.add(VisalloProperties.MIME_TYPE.getPropertyName(), "text/html", getVisibilityTranslator().getDefaultVisibility()); v.addPropertyValue("key1", "http://visallo.org/test#raw1", textValue, metadata, visibility); v.save(getGraphAuthorizations()); Vertex vertex = getGraph().getVertex("v1", getGraphAuthorizations()); run(gpw, createWorkerPrepareData(), vertex); Property text1Property = vertex.getProperty("key1", "http://visallo.org/test#text1"); assertTrue(text1Property != null); assertThat(((StreamingPropertyValue) text1Property.getValue()).readToString(), equalTo("Text1")); }
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); } }
@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()); }