public ElementUpdateContext(VisibilityTranslator visibilityTranslator, ElementMutation<T> mutation, User user) { this.visibilityTranslator = visibilityTranslator; this.mutation = mutation; this.user = user; if (mutation instanceof ExistingElementMutation) { element = ((ExistingElementMutation<T>) mutation).getElement(); } else { element = null; } }
@SuppressWarnings("unchecked") public <T extends Element> void saveElement(ExistingElementMutation<T> m) { if (m.getElement() instanceof Edge) { saveEdge((ElementMutation<Edge>) m); } else if (m.getElement() instanceof Vertex) { saveVertex((ElementMutation<Vertex>) m); } else { throw new VertexiumException("unexpected element type: " + m.getElement().getClass().getName()); } }
@SuppressWarnings("unchecked") public <T extends Element> void saveElement(ExistingElementMutation<T> m) { if (m.getElement() instanceof Edge) { saveEdge((ElementMutation<Edge>) m); } else if (m.getElement() instanceof Vertex) { saveVertex((ElementMutation<Vertex>) m); } else { throw new VertexiumException("unexpected element type: " + m.getElement().getClass().getName()); } }
@Override public Iterable<Element> saveElementMutations(Iterable<ElementMutation> mutations, Authorizations authorizations) { List<Element> elements = new ArrayList<>(); for (ElementMutation m : mutations) { if (m instanceof ExistingElementMutation && !m.hasChanges()) { elements.add(((ExistingElementMutation) m).getElement()); continue; } Element element = m.save(authorizations); elements.add(element); } return elements; }
@Override public Iterable<Element> saveElementMutations(Iterable<ElementMutation> mutations, Authorizations authorizations) { List<Element> elements = new ArrayList<>(); for (ElementMutation m : mutations) { if (m instanceof ExistingElementMutation && !m.hasChanges()) { elements.add(((ExistingElementMutation) m).getElement()); continue; } Element element = m.save(authorizations); elements.add(element); } return elements; }
private boolean isEdgeMutation() { if (getMutation() instanceof EdgeMutation) { return true; } if (getMutation() instanceof ExistingElementMutation) { ExistingElementMutation m = (ExistingElementMutation) getMutation(); if (m.getElement() instanceof Edge) { return true; } } return false; } }
private <TElement extends Element> Map<String, Object> getFieldsToSet(Graph graph, ExistingElementMutation<TElement> mutation) { TElement element = mutation.getElement(); Map<String, Object> fieldsToSet = new HashMap<>(); mutation.getProperties().forEach(p -> addExistingValuesToFieldMap(graph, element, p.getName(), p.getVisibility(), fieldsToSet)); mutation.getPropertyDeletes().forEach(p -> addExistingValuesToFieldMap(graph, element, p.getName(), p.getVisibility(), fieldsToSet)); mutation.getPropertySoftDeletes().forEach(p -> addExistingValuesToFieldMap(graph, element, p.getName(), p.getVisibility(), fieldsToSet)); return fieldsToSet; }
private <TElement extends Element> Map<String, Object> getFieldsToSet(Graph graph, ExistingElementMutation<TElement> mutation) { TElement element = mutation.getElement(); Map<String, Object> fieldsToSet = new HashMap<>(); mutation.getProperties().forEach(p -> addExistingValuesToFieldMap(graph, element, p.getName(), p.getVisibility(), fieldsToSet)); mutation.getPropertyDeletes().forEach(p -> addExistingValuesToFieldMap(graph, element, p.getName(), p.getVisibility(), fieldsToSet)); mutation.getPropertySoftDeletes().forEach(p -> addExistingValuesToFieldMap(graph, element, p.getName(), p.getVisibility(), fieldsToSet)); return fieldsToSet; }
@Override public Iterable<Element> saveElementMutations(Iterable<ElementMutation> mutations, Authorizations authorizations) { List<Element> elements = new ArrayList<>(); List<Element> elementsToAddToIndex = new ArrayList<>(); List<ElementAndIterableExtendedDataMutation> extendedDataToIndex = new ArrayList<>(); for (ElementMutation m : mutations) { if (m instanceof ExistingElementMutation && !m.hasChanges()) { elements.add(((ExistingElementMutation) m).getElement()); continue; } IndexHint indexHint = m.getIndexHint(); m.setIndexHint(IndexHint.DO_NOT_INDEX); Element element = m.save(authorizations); elements.add(element); if (indexHint == IndexHint.INDEX) { elementsToAddToIndex.add(element); //noinspection unchecked extendedDataToIndex.add(new ElementAndIterableExtendedDataMutation(element, m.getExtendedData())); } } getSearchIndex().addElements(this, elementsToAddToIndex, authorizations); for (ElementAndIterableExtendedDataMutation ed : extendedDataToIndex) { getSearchIndex().addElementExtendedData(this, ed.element, ed.extendedData, authorizations); } return elements; }
@Override public Iterable<Element> saveElementMutations(Iterable<ElementMutation> mutations, Authorizations authorizations) { List<Element> elements = new ArrayList<>(); List<Element> elementsToAddToIndex = new ArrayList<>(); List<ElementAndIterableExtendedDataMutation> extendedDataToIndex = new ArrayList<>(); for (ElementMutation m : mutations) { if (m instanceof ExistingElementMutation && !m.hasChanges()) { elements.add(((ExistingElementMutation) m).getElement()); continue; } IndexHint indexHint = m.getIndexHint(); m.setIndexHint(IndexHint.DO_NOT_INDEX); Element element = m.save(authorizations); elements.add(element); if (indexHint == IndexHint.INDEX) { elementsToAddToIndex.add(element); //noinspection unchecked extendedDataToIndex.add(new ElementAndIterableExtendedDataMutation(element, m.getExtendedData())); } } getSearchIndex().addElements(this, elementsToAddToIndex, authorizations); for (ElementAndIterableExtendedDataMutation ed : extendedDataToIndex) { getSearchIndex().addElementExtendedData(this, ed.element, ed.extendedData, authorizations); } return elements; }
private <TElement extends Element> UpdateRequestBuilder prepareUpdateForMutation(Graph graph, ExistingElementMutation<TElement> mutation) { TElement element = mutation.getElement(); Map<String, String> fieldVisibilityChanges = getFieldVisibilityChanges(graph, mutation); List<String> fieldsToRemove = getFieldsToRemove(graph, mutation); Map<String, Object> fieldsToSet = getFieldsToSet(graph, mutation); String documentId = getIdStrategy().createElementDocId(element); String indexName = getIndexName(element); IndexInfo indexInfo = ensureIndexCreatedAndInitialized(indexName); return prepareUpdateFieldsOnDocument(indexInfo.getIndexName(), documentId, fieldsToSet, fieldsToRemove, fieldVisibilityChanges); }
private <TElement extends Element> UpdateRequestBuilder prepareUpdateForMutation(Graph graph, ExistingElementMutation<TElement> mutation) { TElement element = mutation.getElement(); Map<String, String> fieldVisibilityChanges = getFieldVisibilityChanges(graph, mutation); List<String> fieldsToRemove = getFieldsToRemove(graph, mutation); Map<String, Object> fieldsToSet = getFieldsToSet(graph, mutation); String documentId = getIdStrategy().createElementDocId(element); String indexName = getIndexName(element); IndexInfo indexInfo = ensureIndexCreatedAndInitialized(indexName); return prepareUpdateFieldsOnDocument(indexInfo.getIndexName(), documentId, fieldsToSet, fieldsToRemove, fieldVisibilityChanges); }
protected <TElement extends Element> void saveExistingElementMutation(ExistingElementMutation<TElement> mutation, Authorizations authorizations) { AccumuloElement element = (AccumuloElement) mutation.getElement(); getGraph().alterEdgeLabel((AccumuloEdge) mutation.getElement(), newEdgeLabel); ElementType elementType = ElementType.getTypeFromElement(mutation.getElement()); getGraph().saveExtendedDataMutations( mutation.getElement(), elementType, mutation.getIndexHint(),
protected <TElement extends Element> void saveExistingElementMutation(ExistingElementMutation<TElement> mutation, Authorizations authorizations) { AccumuloElement element = (AccumuloElement) mutation.getElement(); getGraph().alterEdgeLabel((AccumuloEdge) mutation.getElement(), newEdgeLabel); ElementType elementType = ElementType.getTypeFromElement(mutation.getElement()); getGraph().saveExtendedDataMutations( mutation.getElement(), elementType, mutation.getIndexHint(),
private <TElement extends Element> IndexInfo addMutationPropertiesToIndex(Graph graph, ExistingElementMutation<TElement> mutation) { TElement element = mutation.getElement(); IndexInfo indexInfo = addPropertiesToIndex(graph, element, mutation.getProperties()); mutation.getAlterPropertyVisibilities().stream() .filter(p -> p.getExistingVisibility() != null && !p.getExistingVisibility().equals(p.getVisibility())) .forEach(p -> { PropertyDefinition propertyDefinition = getPropertyDefinition(graph, p.getName()); if (propertyDefinition != null) { try { addPropertyDefinitionToIndex(graph, indexInfo, p.getName(), p.getVisibility(), propertyDefinition); } catch (Exception e) { throw new VertexiumException("Unable to add property to index: " + p, e); } } }); if (mutation.getNewElementVisibility() != null) { try { String newFieldName = addVisibilityToPropertyName(graph, ELEMENT_TYPE_FIELD_NAME, mutation.getNewElementVisibility()); addPropertyToIndex(graph, indexInfo, newFieldName, element.getVisibility(), String.class, false, false, false); } catch (Exception e) { throw new VertexiumException("Unable to add new element type visibility to index", e); } } return indexInfo; }
private <TElement extends Element> IndexInfo addMutationPropertiesToIndex(Graph graph, ExistingElementMutation<TElement> mutation) { TElement element = mutation.getElement(); IndexInfo indexInfo = addPropertiesToIndex(graph, element, mutation.getProperties()); mutation.getAlterPropertyVisibilities().stream() .filter(p -> p.getExistingVisibility() != null && !p.getExistingVisibility().equals(p.getVisibility())) .forEach(p -> { PropertyDefinition propertyDefinition = getPropertyDefinition(graph, p.getName()); if (propertyDefinition != null) { try { addPropertyDefinitionToIndex(graph, indexInfo, p.getName(), p.getVisibility(), propertyDefinition); } catch (Exception e) { throw new VertexiumException("Unable to add property to index: " + p, e); } } }); if (mutation.getNewElementVisibility() != null) { try { String newFieldName = addVisibilityToPropertyName(graph, ELEMENT_TYPE_FIELD_NAME, mutation.getNewElementVisibility()); addPropertyToIndex(graph, indexInfo, newFieldName, element.getVisibility(), String.class, false, false, false); } catch (Exception e) { throw new VertexiumException("Unable to add new element type visibility to index", e); } } return indexInfo; }
@Override public <TElement extends Element> void updateElement(Graph graph, ExistingElementMutation<TElement> mutation, Authorizations authorizations) { TElement element = mutation.getElement();
@Override public <TElement extends Element> void updateElement(Graph graph, ExistingElementMutation<TElement> mutation, Authorizations authorizations) { TElement element = mutation.getElement();