private JSONObject metadataItemToJson(Metadata.Entry entry) { JSONObject json = new JSONObject(); json.put("value", objectToJsonString(entry.getValue())); json.put("visibility", entry.getVisibility().getVisibilityString()); return json; }
private JSONObject metadataToJson(Metadata metadata) { JSONObject json = new JSONObject(); for (Metadata.Entry m : metadata.entrySet()) { json.put(m.getKey(), metadataItemToJson(m)); } return json; }
public void add(String key, Object value, Visibility visibility) { entries.put(toMapKey(key, visibility), new Entry(key, value, visibility)); }
assertNotNull(prop1Metadata); assertEquals(1, prop1Metadata.entrySet().size()); assertEquals("metadata1Value", prop1Metadata.getEntry("metadata1", VISIBILITY_A).getValue()); prop1Metadata = prop1.getMetadata(); assertEquals(2, prop1Metadata.entrySet().size()); assertEquals("metadata1Value", prop1Metadata.getEntry("metadata1", VISIBILITY_A).getValue()); assertEquals("metadata2Value", prop1Metadata.getEntry("metadata2", VISIBILITY_A).getValue());
assertNotNull(prop1Metadata); assertEquals(1, prop1Metadata.entrySet().size()); assertEquals("metadata1Value", prop1Metadata.getEntry("metadata1", VISIBILITY_A).getValue()); prop1Metadata = prop1.getMetadata(); assertEquals(2, prop1Metadata.entrySet().size()); assertEquals("metadata1Value", prop1Metadata.getEntry("metadata1", VISIBILITY_A).getValue()); assertEquals("metadata2Value", prop1Metadata.getEntry("metadata2", VISIBILITY_A).getValue());
@Test public void testChangePropertyMetadata() { Metadata prop1Metadata = new Metadata(); 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); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); v1.prepareMutation() .setPropertyMetadata("prop1", "prop1_key1", "valueNew", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); assertEquals("valueNew", v1.getProperty("prop1").getMetadata().getEntry("prop1_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals("valueNew", v1.getProperty("prop1").getMetadata().getEntry("prop1_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); v1.prepareMutation() .setPropertyMetadata("prop2", "prop2_key1", "valueNew", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); assertEquals("valueNew", v1.getProperty("prop2").getMetadata().getEntry("prop2_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals("valueNew", v1.getProperty("prop2").getMetadata().getEntry("prop2_key1", VISIBILITY_EMPTY).getValue()); }
@Test public void testChangePropertyMetadata() { Metadata prop1Metadata = new Metadata(); 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); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); v1.prepareMutation() .setPropertyMetadata("prop1", "prop1_key1", "valueNew", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); assertEquals("valueNew", v1.getProperty("prop1").getMetadata().getEntry("prop1_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals("valueNew", v1.getProperty("prop1").getMetadata().getEntry("prop1_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); v1.prepareMutation() .setPropertyMetadata("prop2", "prop2_key1", "valueNew", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); assertEquals("valueNew", v1.getProperty("prop2").getMetadata().getEntry("prop2_key1", VISIBILITY_EMPTY).getValue()); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals("valueNew", v1.getProperty("prop2").getMetadata().getEntry("prop2_key1", VISIBILITY_EMPTY).getValue()); }
public void update(Property property) { if (property.getHiddenVisibilities() != null) { for (Visibility v : property.getHiddenVisibilities()) { addHiddenVisibility(v); } } setValue(property.getValue()); for (Metadata.Entry m : property.getMetadata().entrySet()) { if (m.getValue() == null) { removeMetadata(m.getKey(), m.getVisibility()); } else { addMetadata(m.getKey(), m.getValue(), m.getVisibility()); } } } }
public void update(Property property) { if (property.getHiddenVisibilities() != null) { for (Visibility v : property.getHiddenVisibilities()) { addHiddenVisibility(v); } } setValue(property.getValue()); for (Metadata.Entry m : property.getMetadata().entrySet()) { if (m.getValue() == null) { removeMetadata(m.getKey(), m.getVisibility()); } else { addMetadata(m.getKey(), m.getValue(), m.getVisibility()); } } } }
public void add(String key, Object value, Visibility visibility) { entries.put(toMapKey(key, visibility), new Entry(key, value, visibility)); }
public Object getValue(String key, Visibility visibility) { Entry entry = getEntry(key, visibility); if (entry == null) { return null; } return entry.getValue(); }
public Object getValue(String key) { Entry entry = getEntry(key); if (entry == null) { return null; } return entry.getValue(); }
public Entry getEntry(String key) { Entry entry = null; for (Map.Entry<String, Entry> e : entries.entrySet()) { if (e.getValue().getKey().equals(key)) { if (entry != null) { throw new SecureGraphException("Multiple matching entries for key: " + key); } entry = e.getValue(); } } return entry; }
public void remove(String key) { for (Map.Entry<String, Entry> e : new ArrayList<Map.Entry<String, Entry>>(entries.entrySet())) { if (e.getValue().getKey().equals(key)) { entries.remove(e.getKey()); } } }
public void addPropertyMetadataToMutation(Mutation m, Property property) { Metadata metadata = property.getMetadata(); for (Metadata.Entry metadataItem : metadata.entrySet()) { Text columnQualifier = getPropertyMetadataColumnQualifier(property, metadataItem.getKey()); ColumnVisibility metadataVisibility = visibilityToAccumuloVisibility(metadataItem.getVisibility()); if (metadataItem.getValue() == null) { m.putDelete(AccumuloElement.CF_PROPERTY_METADATA, columnQualifier, metadataVisibility); } else { Value metadataValue = new Value(valueSerializer.objectToValue(metadataItem.getValue())); m.put(AccumuloElement.CF_PROPERTY_METADATA, columnQualifier, metadataVisibility, metadataValue); } } }
public void addPropertyRemoveToMutation(Mutation m, Property property) { checkNotNull(m, "mutation cannot be null"); checkNotNull(property, "property cannot be null"); Text columnQualifier = getPropertyColumnQualifier(property); ColumnVisibility columnVisibility = visibilityToAccumuloVisibility(property.getVisibility()); m.putDelete(AccumuloElement.CF_PROPERTY, columnQualifier, columnVisibility); for (Metadata.Entry metadataEntry : property.getMetadata().entrySet()) { Text metadataEntryColumnQualifier = getPropertyMetadataColumnQualifier(property, metadataEntry.getKey()); ColumnVisibility metadataEntryVisibility = visibilityToAccumuloVisibility(metadataEntry.getVisibility()); m.putDelete(AccumuloElement.CF_PROPERTY_METADATA, metadataEntryColumnQualifier, metadataEntryVisibility); } }
public boolean containsKey(String key) { for (Map.Entry<String, Entry> e : entries.entrySet()) { if (e.getValue().getKey().equals(key)) { return true; } } return false; }
public void remove(String key) { for (Map.Entry<String, Entry> e : new ArrayList<Map.Entry<String, Entry>>(entries.entrySet())) { if (e.getValue().getKey().equals(key)) { entries.remove(e.getKey()); } } }
public Object getValue(String key, Visibility visibility) { Entry entry = getEntry(key, visibility); if (entry == null) { return null; } return entry.getValue(); }
public Entry getEntry(String key) { Entry entry = null; for (Map.Entry<String, Entry> e : entries.entrySet()) { if (e.getValue().getKey().equals(key)) { if (entry != null) { throw new SecureGraphException("Multiple matching entries for key: " + key); } entry = e.getValue(); } } return entry; }