use of org.vertexium.Edge in project vertexium by visallo.
the class Elasticsearch5SearchIndex method buildJsonContentFromExtendedDataMutations.
private XContentBuilder buildJsonContentFromExtendedDataMutations(Graph graph, Element element, String tableName, String rowId, List<ExtendedDataMutation> columns, Authorizations authorizations) throws IOException {
XContentBuilder jsonBuilder;
jsonBuilder = XContentFactory.jsonBuilder().startObject();
String elementTypeString = ElasticsearchDocumentType.getExtendedDataDocumentTypeFromElement(element).getKey();
jsonBuilder.field(ELEMENT_ID_FIELD_NAME, element.getId());
jsonBuilder.field(ELEMENT_TYPE_FIELD_NAME, elementTypeString);
String elementTypeVisibilityPropertyName = addElementTypeVisibilityPropertyToIndex(graph, element);
jsonBuilder.field(elementTypeVisibilityPropertyName, elementTypeString);
getConfig().getScoringStrategy().addFieldsToExtendedDataDocument(this, jsonBuilder, element, null, tableName, rowId, columns, authorizations);
jsonBuilder.field(EXTENDED_DATA_TABLE_NAME_FIELD_NAME, tableName);
jsonBuilder.field(EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME, rowId);
if (element instanceof Edge) {
Edge edge = (Edge) element;
jsonBuilder.field(IN_VERTEX_ID_FIELD_NAME, edge.getVertexId(Direction.IN));
jsonBuilder.field(OUT_VERTEX_ID_FIELD_NAME, edge.getVertexId(Direction.OUT));
jsonBuilder.field(EDGE_LABEL_FIELD_NAME, edge.getLabel());
}
Map<String, Object> fields = getExtendedDataColumnsAsFields(graph, columns);
addFieldsMap(jsonBuilder, fields);
return jsonBuilder;
}
use of org.vertexium.Edge in project vertexium by visallo.
the class Elasticsearch5SearchIndex method buildJsonContentFromElement.
private XContentBuilder buildJsonContentFromElement(Graph graph, Element element, Authorizations authorizations) throws IOException {
XContentBuilder jsonBuilder;
jsonBuilder = XContentFactory.jsonBuilder().startObject();
String elementTypeVisibilityPropertyName = addElementTypeVisibilityPropertyToIndex(graph, element);
jsonBuilder.field(ELEMENT_ID_FIELD_NAME, element.getId());
jsonBuilder.field(ELEMENT_TYPE_FIELD_NAME, getElementTypeValueFromElement(element));
if (element instanceof Vertex) {
jsonBuilder.field(elementTypeVisibilityPropertyName, ElasticsearchDocumentType.VERTEX.getKey());
getConfig().getScoringStrategy().addFieldsToVertexDocument(this, jsonBuilder, (Vertex) element, null, authorizations);
} else if (element instanceof Edge) {
Edge edge = (Edge) element;
jsonBuilder.field(elementTypeVisibilityPropertyName, ElasticsearchDocumentType.EDGE.getKey());
getConfig().getScoringStrategy().addFieldsToEdgeDocument(this, jsonBuilder, edge, null, authorizations);
jsonBuilder.field(IN_VERTEX_ID_FIELD_NAME, edge.getVertexId(Direction.IN));
jsonBuilder.field(OUT_VERTEX_ID_FIELD_NAME, edge.getVertexId(Direction.OUT));
jsonBuilder.field(EDGE_LABEL_FIELD_NAME, edge.getLabel());
} else {
throw new VertexiumException("Unexpected element type " + element.getClass().getName());
}
for (Visibility hiddenVisibility : element.getHiddenVisibilities()) {
String hiddenVisibilityPropertyName = addVisibilityToPropertyName(graph, HIDDEN_VERTEX_FIELD_NAME, hiddenVisibility);
if (!isPropertyInIndex(graph, hiddenVisibilityPropertyName)) {
String indexName = getIndexName(element);
IndexInfo indexInfo = ensureIndexCreatedAndInitialized(graph, indexName);
addPropertyToIndex(graph, indexInfo, hiddenVisibilityPropertyName, hiddenVisibility, Boolean.class, false, false, false);
}
jsonBuilder.field(hiddenVisibilityPropertyName, true);
}
Map<String, Object> fields = getPropertiesAsFields(graph, element.getProperties());
addFieldsMap(jsonBuilder, fields);
jsonBuilder.endObject();
return jsonBuilder;
}
use of org.vertexium.Edge in project vertexium by visallo.
the class Elasticsearch5SearchIndex method addElement.
@SuppressWarnings("unchecked")
@Override
public void addElement(Graph graph, Element element, Authorizations authorizations) {
if (MUTATION_LOGGER.isTraceEnabled()) {
MUTATION_LOGGER.trace("addElement: %s", element.getId());
}
if (!getConfig().isIndexEdges() && element instanceof Edge) {
return;
}
if (flushObjectQueue.containsElementId(element.getId())) {
flushObjectQueue.flush();
}
UpdateRequestBuilder updateRequestBuilder = prepareUpdate(graph, element, authorizations);
addActionRequestBuilderForFlush(element.getId(), updateRequestBuilder);
if (getConfig().isAutoFlush()) {
flush(graph);
}
}
use of org.vertexium.Edge in project vertexium by visallo.
the class LabelsFunction method invoke.
@Override
public Object invoke(VertexiumCypherQueryContext ctx, CypherAstBase[] arguments, ExpressionScope scope) {
CypherAstBase lookup = arguments[0];
Object item = ctx.getExpressionExecutor().executeExpression(ctx, lookup, scope);
if (item == null) {
throw new VertexiumException("Could not find Vertex using " + lookup);
}
if (item instanceof Vertex) {
Vertex vertex = (Vertex) item;
return ctx.getVertexLabels(vertex);
}
if (item instanceof Edge) {
Edge edge = (Edge) item;
return Lists.newArrayList(edge.getLabel());
}
throw new VertexiumCypherTypeErrorException(item, Vertex.class, Edge.class);
}
use of org.vertexium.Edge in project vertexium by visallo.
the class Elasticsearch5SearchIndex method updateElement.
@Override
public <TElement extends Element> void updateElement(Graph graph, ExistingElementMutation<TElement> mutation, Authorizations authorizations) {
TElement element = mutation.getElement();
if (MUTATION_LOGGER.isTraceEnabled()) {
MUTATION_LOGGER.trace("updateElement: %s", element.getId());
}
if (!getConfig().isIndexEdges() && element instanceof Edge) {
return;
}
if (flushObjectQueue.containsElementId(element.getId())) {
flushObjectQueue.flush();
}
UpdateRequestBuilder updateRequestBuilder = prepareUpdateForMutation(graph, mutation);
if (updateRequestBuilder != null) {
IndexInfo indexInfo = addMutationPropertiesToIndex(graph, mutation);
getIndexRefreshTracker().pushChange(indexInfo.getIndexName());
addActionRequestBuilderForFlush(element.getId(), updateRequestBuilder);
if (getConfig().isAutoFlush()) {
flush(graph);
}
}
}
Aggregations