use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.
the class GraphBackup method propertyToJson.
private JSONObject propertyToJson(Property property) {
JSONObject json = new JSONObject();
json.put("key", property.getKey());
json.put("name", property.getName());
json.put("visibility", property.getVisibility().getVisibilityString());
Object value = property.getValue();
if (!(value instanceof StreamingPropertyValue)) {
json.put("value", objectToJsonString(value));
}
Metadata metadata = property.getMetadata();
if (metadata != null) {
json.put("metadata", metadataToJson(metadata));
}
return json;
}
use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.
the class GraphBackup method saveStreamingProperty.
private void saveStreamingProperty(OutputStream out, Property property) throws IOException {
StreamingPropertyValue spv = (StreamingPropertyValue) property.getValue();
JSONObject json = propertyToJson(property);
json.put("valueType", spv.getValueType().getName());
json.put("searchIndex", spv.isSearchIndex());
json.put("store", spv.isStore());
out.write('D');
out.write(json.toString().getBytes());
out.write('\n');
InputStream in = spv.getInputStream();
byte[] buffer = new byte[10 * 1024];
int read;
while ((read = in.read(buffer)) > 0) {
out.write(Integer.toString(read).getBytes());
out.write('\n');
out.write(buffer, 0, read);
out.write('\n');
}
out.write('0');
out.write('\n');
}
use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.
the class GraphRestore method restoreStreamingPropertyValue.
private void restoreStreamingPropertyValue(InputStream in, Graph graph, JSONObject propertyJson, Element element, Authorizations authorizations) throws ClassNotFoundException, IOException {
String key = propertyJson.getString("key");
String name = propertyJson.getString("name");
Metadata metadata = jsonToPropertyMetadata(propertyJson.optJSONObject("metadata"));
Visibility visibility = new Visibility(propertyJson.getString("visibility"));
Class valueType = Class.forName(propertyJson.getString("valueType"));
InputStream spvin = new StreamingPropertyValueInputStream(in);
StreamingPropertyValue value = StreamingPropertyValue.create(spvin, valueType);
value.searchIndex(propertyJson.optBoolean("searchIndex", false));
value.store(propertyJson.optBoolean("store", true));
element.addPropertyValue(key, name, value, metadata, visibility, authorizations);
}
use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.
the class AccumuloGraphTestBase method addLegacySPVData.
// need to add it manually because the key format changed
private void addLegacySPVData(String vertexId, long timestamp, String propertyKey, String propertyName, String propertyValue) throws MutationsRejectedException {
String dataRowKey = new DataTableRowKey(vertexId, propertyKey, propertyName).getRowKey() + VALUE_SEPARATOR + timestamp;
Mutation addPropertyMutation = new Mutation(vertexId);
byte[] data = propertyValue.getBytes();
StreamingPropertyValue spv = StreamingPropertyValue.create(propertyValue);
StreamingPropertyValueTableRef spvValue = new StreamingPropertyValueTableRef(dataRowKey, spv, data);
Metadata metadata = new Metadata();
Property property = new MutablePropertyImpl(propertyKey, propertyName, spvValue, metadata, timestamp, new HashSet<>(), new Visibility(""), FetchHints.ALL);
Text columnQualifier = KeyHelper.getColumnQualifierFromPropertyColumnQualifier(property, getGraph().getNameSubstitutionStrategy());
addPropertyMutation.put(AccumuloElement.CF_PROPERTY, columnQualifier, new Value(getGraph().getVertexiumSerializer().objectToBytes(spvValue)));
getGraph().getVerticesWriter().addMutation(addPropertyMutation);
Mutation addDataMutation = new Mutation(dataRowKey);
addDataMutation.put(EMPTY_TEXT, EMPTY_TEXT, timestamp - 1000, new Value(data));
getGraph().getDataWriter().addMutation(addDataMutation);
getGraph().flush();
}
use of org.vertexium.property.StreamingPropertyValue in project vertexium by visallo.
the class AccumuloGraphTestBase method testDeleteHistoricalLegacyStreamingPropertyValueData_keysWithCommonPrefix.
@Test
public void testDeleteHistoricalLegacyStreamingPropertyValueData_keysWithCommonPrefix() throws Exception {
String vertexId = "v1";
graph.prepareVertex(vertexId, VISIBILITY_EMPTY).save(AUTHORIZATIONS_EMPTY);
graph.flush();
long timestamp = new Date().getTime();
String propertyKey1 = "prefix";
String propertyKey2 = "prefixSuffix";
String propertyName = "prop1";
String propertyValue = "Hello";
addLegacySPVData(vertexId, timestamp, propertyKey1, propertyName, propertyValue);
addLegacySPVData(vertexId, timestamp, propertyKey2, propertyName, propertyValue);
getGraph().flush();
new DeleteHistoricalLegacyStreamingPropertyValueData(getGraph()).execute(new DeleteHistoricalLegacyStreamingPropertyValueData.Options().setDryRun(false).setVersionsToKeep(1), AUTHORIZATIONS_EMPTY);
// verify we can still retrieve it
Vertex v1 = graph.getVertex(vertexId, AUTHORIZATIONS_EMPTY);
StreamingPropertyValue spv = (StreamingPropertyValue) v1.getPropertyValue(propertyKey1, propertyName);
assertNotNull("spv should not be null", spv);
assertEquals(propertyValue, IOUtils.toString(spv.getInputStream()));
spv = (StreamingPropertyValue) v1.getPropertyValue(propertyKey2, propertyName);
assertNotNull("spv should not be null", spv);
assertEquals(propertyValue, IOUtils.toString(spv.getInputStream()));
}
Aggregations