use of org.vertexium.Edge 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