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; }
public TRaw getMetadataValueOrDefault(Metadata metadata, TRaw defaultValue) { Object value = metadata.getValue(getMetadataKey()); if (value == null) { return defaultValue; } return unwrap(value); }
public TRaw getMetadataValue(Metadata metadata) { return unwrap(metadata.getValue(getMetadataKey())); }
@Override public boolean isHandled(Element element, Property property) { if (property == null) { return false; } if (property.getName().equals(VisalloProperties.RAW.getPropertyName())) { return false; } String mimeType = (String) property.getMetadata().getValue(VisalloProperties.MIME_TYPE.getPropertyName()); return !(mimeType == null || !mimeType.startsWith("text")); } }
/** * Determines if this is a property that should be analyzed by text processing tools. */ protected boolean isTextProperty(Property property) { if (property == null) { return false; } if (property.getName().equals(VisalloProperties.RAW.getPropertyName())) { return false; } String mimeType = (String) property.getMetadata().getValue(VisalloProperties.MIME_TYPE.getPropertyName()); return !(mimeType == null || !mimeType.startsWith("text")); }
public TRaw getMetadataValue(Metadata metadata, TRaw defaultValue) { if (metadata.getEntry(getMetadataKey()) == null) { return defaultValue; } return unwrap(metadata.getValue(getMetadataKey())); }
@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 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)); }
v1 = graph.getVertex("v1", specificPropertiesFetchHints, AUTHORIZATIONS_A); Metadata n1WithoutM2 = v1.getProperty("n1").getMetadata(); assertEquals("m1value", n1WithoutM2.getValue("m1")); assertThrowsException(() -> n1WithoutM2.getValue("m2")); assertEquals("m3value", n1WithoutM2.getValue("m3")); Vertex v1_withMetadata = graph.getVertex("v1", allPropertiesFetchHints, AUTHORIZATIONS_A); Metadata n1 = v1_withMetadata.getProperty("n1").getMetadata(); assertEquals("m1value", n1.getValue("m1")); assertEquals("m2value", n1.getValue("m2")); assertEquals("m3value", n1.getValue("m3"));
v1 = graph.getVertex("v1", specificPropertiesFetchHints, AUTHORIZATIONS_A); Metadata n1WithoutM2 = v1.getProperty("n1").getMetadata(); assertEquals("m1value", n1WithoutM2.getValue("m1")); assertThrowsException(() -> n1WithoutM2.getValue("m2")); assertEquals("m3value", n1WithoutM2.getValue("m3")); Vertex v1_withMetadata = graph.getVertex("v1", allPropertiesFetchHints, AUTHORIZATIONS_A); Metadata n1 = v1_withMetadata.getProperty("n1").getMetadata(); assertEquals("m1value", n1.getValue("m1")); assertEquals("m2value", n1.getValue("m2")); assertEquals("m3value", n1.getValue("m3"));
@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")); }
@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")); }
@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 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)); }
@Override public void execute(InputStream in, GraphPropertyWorkData data) throws Exception { String mimeType = (String) data.getProperty().getMetadata().getValue(VisalloProperties.MIME_TYPE.getPropertyName()); checkNotNull(mimeType, VisalloProperties.MIME_TYPE.getPropertyName() + " is a required metadata field");
assertNotNull(v1Prop1); Assert.assertEquals(1, toList(v1Prop1.getMetadata().entrySet()).size()); assertEquals("value1", v1Prop1.getMetadata().getValue("prop1_key1")); assertNotNull(v1.getProperty("prop2"));
assertNotNull(v1Prop1); Assert.assertEquals(1, toList(v1Prop1.getMetadata().entrySet()).size()); assertEquals("value1", v1Prop1.getMetadata().getValue("prop1_key1")); assertNotNull(v1.getProperty("prop2"));