use of org.vertexium.mutation.ExtendedDataMutation in project vertexium by visallo.
the class Elasticsearch5SearchIndex method mapExtendedDatasByTableByRow.
private Map<String, Map<String, List<ExtendedDataMutation>>> mapExtendedDatasByTableByRow(Iterable<ExtendedDataMutation> extendedData) {
Map<String, Map<String, List<ExtendedDataMutation>>> results = new HashMap<>();
for (ExtendedDataMutation ed : extendedData) {
Map<String, List<ExtendedDataMutation>> byRow = results.computeIfAbsent(ed.getTableName(), k -> new HashMap<>());
List<ExtendedDataMutation> items = byRow.computeIfAbsent(ed.getRow(), k -> new ArrayList<>());
items.add(ed);
}
return results;
}
use of org.vertexium.mutation.ExtendedDataMutation in project vertexium by visallo.
the class Elasticsearch5SearchIndex method getExtendedDataColumnsAsFields.
private Map<String, Object> getExtendedDataColumnsAsFields(Graph graph, List<ExtendedDataMutation> columns) {
Map<String, Object> fieldsMap = new HashMap<>();
List<ExtendedDataMutation> streamingColumns = new ArrayList<>();
for (ExtendedDataMutation column : columns) {
if (column.getValue() != null && shouldIgnoreType(column.getValue().getClass())) {
continue;
}
if (column.getValue() instanceof StreamingPropertyValue) {
StreamingPropertyValue spv = (StreamingPropertyValue) column.getValue();
if (isStreamingPropertyValueIndexable(graph, column.getColumnName(), spv)) {
streamingColumns.add(column);
}
} else {
addExtendedDataColumnToFieldMap(graph, column, column.getValue(), fieldsMap);
}
}
addStreamingExtendedDataColumnsValuesToMap(graph, streamingColumns, fieldsMap);
return fieldsMap;
}
use of org.vertexium.mutation.ExtendedDataMutation in project vertexium by visallo.
the class Elasticsearch5SearchIndex method addExtendedDataColumnsToIndex.
private IndexInfo addExtendedDataColumnsToIndex(Graph graph, Element element, String tableName, String rowId, List<ExtendedDataMutation> columns) {
try {
String indexName = getExtendedDataIndexName(element, tableName, rowId);
IndexInfo indexInfo = ensureIndexCreatedAndInitialized(graph, indexName);
for (ExtendedDataMutation column : columns) {
addPropertyToIndex(graph, indexInfo, column.getColumnName(), column.getValue(), column.getVisibility());
}
return indexInfo;
} catch (IOException e) {
throw new VertexiumException("Could not add properties to index", e);
}
}
use of org.vertexium.mutation.ExtendedDataMutation in project vertexium by visallo.
the class Elasticsearch5SearchIndex method addExtendedData.
@Override
public void addExtendedData(Graph graph, Iterable<ExtendedDataRow> extendedDatas, Authorizations authorizations) {
Map<ElementType, Map<String, List<ExtendedDataRow>>> rowsByElementTypeAndId = mapExtendedDatasByElementTypeByElementId(extendedDatas);
// prefetch the vertices and edges for performance
Map<String, Vertex> verticesById;
if (rowsByElementTypeAndId.containsKey(ElementType.VERTEX) && !rowsByElementTypeAndId.get(ElementType.VERTEX).isEmpty()) {
Iterable<Vertex> vertices = graph.getVertices(rowsByElementTypeAndId.get(ElementType.VERTEX).keySet(), FetchHints.NONE, authorizations);
verticesById = stream(vertices).collect(Collectors.toMap(Vertex::getId, Function.identity()));
} else {
verticesById = new HashMap<>();
}
Map<String, Edge> edgesById;
if (rowsByElementTypeAndId.containsKey(ElementType.EDGE) && !rowsByElementTypeAndId.get(ElementType.EDGE).isEmpty()) {
edgesById = stream(graph.getEdges(rowsByElementTypeAndId.get(ElementType.EDGE).keySet(), FetchHints.NONE, authorizations)).collect(Collectors.toMap(Edge::getId, Function.identity()));
} else {
edgesById = new HashMap<>();
}
Set<String> missingElements = new HashSet<>();
rowsByElementTypeAndId.forEach((elementType, elements) -> {
elements.forEach((elementId, rows) -> {
Element element = elementType == ElementType.VERTEX ? verticesById.get(elementId) : edgesById.get(elementId);
if (element == null) {
missingElements.add(String.format("%s:%s", elementType == ElementType.VERTEX ? "Vertex" : "Edge", elementId));
return;
}
bulkUpdate(graph, new ConvertingIterable<ExtendedDataRow, UpdateRequest>(rows) {
@Override
protected UpdateRequest convert(ExtendedDataRow row) {
String tableName = (String) row.getPropertyValue(ExtendedDataRow.TABLE_NAME);
String rowId = (String) row.getPropertyValue(ExtendedDataRow.ROW_ID);
List<ExtendedDataMutation> columns = stream(row.getProperties()).map(property -> new ExtendedDataMutation(tableName, rowId, property.getName(), property.getKey(), property.getValue(), property.getTimestamp(), property.getVisibility())).collect(Collectors.toList());
return prepareUpdate(graph, element, tableName, rowId, columns, authorizations).request();
}
});
});
});
if (missingElements.size() > 0) {
throw new VertexiumException("Could not add all extended data, missing elements: " + Joiner.on(", ").join(missingElements));
}
}
Aggregations