public void updateVisibility(Vertex termMention, Visibility newVisibility, Authorizations authorizations) { Authorizations authorizationsWithTermMention = getAuthorizations(authorizations); Visibility newVisibilityWithTermMention = VisalloVisibility.and(newVisibility, VISIBILITY_STRING); ExistingElementMutation<Vertex> m = termMention.prepareMutation(); m.alterElementVisibility(newVisibilityWithTermMention); for (Property property : termMention.getProperties()) { m.alterPropertyVisibility(property, newVisibilityWithTermMention); } Property refPropertyVisibility = VisalloProperties.TERM_MENTION_REF_PROPERTY_VISIBILITY.getProperty(termMention); if (refPropertyVisibility != null) { VisalloProperties.TERM_MENTION_REF_PROPERTY_VISIBILITY.setProperty( m, newVisibility.getVisibilityString(), refPropertyVisibility.getMetadata(), newVisibilityWithTermMention ); } m.save(authorizationsWithTermMention); for (Edge edge : termMention.getEdges(Direction.BOTH, authorizationsWithTermMention)) { ExistingElementMutation<Edge> edgeMutation = edge.prepareMutation(); edgeMutation.alterElementVisibility(newVisibilityWithTermMention); for (Property property : edge.getProperties()) { edgeMutation.alterPropertyVisibility(property, newVisibilityWithTermMention); } edgeMutation.save(authorizationsWithTermMention); } }
protected <TElement extends Element> void saveExistingElementMutation(ExistingElementMutation<TElement> mutation, Authorizations authorizations) { AccumuloElement element = (AccumuloElement) mutation.getElement(); getGraph().alterPropertyMetadatas(element, mutation.getSetPropertyMetadatas()); getGraph().alterElementPropertyVisibilities(element, mutation.getAlterPropertyVisibilities()); Iterable<PropertyDeleteMutation> propertyDeletes = mutation.getPropertyDeletes(); Iterable<PropertySoftDeleteMutation> propertySoftDeletes = mutation.getPropertySoftDeletes(); Iterable<Property> properties = mutation.getProperties(); if (mutation.getNewElementVisibility() != null) { getGraph().alterElementVisibility(element, mutation.getNewElementVisibility()); getGraph().alterEdgeLabel((AccumuloEdge) mutation.getElement(), newEdgeLabel); if (mutation.getIndexHint() != IndexHint.DO_NOT_INDEX) { getGraph().getSearchIndex().updateElement(graph, mutation, authorizations); ElementType elementType = ElementType.getTypeFromElement(mutation.getElement()); getGraph().saveExtendedDataMutations( mutation.getElement(), elementType, mutation.getIndexHint(), mutation.getExtendedData(), mutation.getExtendedDataDeletes(), authorizations );
private void addTextProperty( TikaTextExtractorGraphPropertyWorkerConfiguration.TextExtractMapping textExtractMapping, ExistingElementMutation<Vertex> m, String propertyKey, StreamingPropertyValue textValue, org.vertexium.Metadata textMetadata, Visibility visibility ) { m.addPropertyValue(propertyKey, textExtractMapping.getExtractedTextPropertyName(), textValue, textMetadata, visibility); }
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; }
public <T extends Element> VisibilityAndElementMutation<T> updateElementVisibilitySource( Element element, SandboxStatus sandboxStatus, String visibilitySource, String workspaceId, Authorizations authorizations ) { Visibility defaultVisibility = visibilityTranslator.getDefaultVisibility(); VisibilityJson visibilityJson = VisalloProperties.VISIBILITY_JSON.getPropertyValue(element); visibilityJson = sandboxStatus != SandboxStatus.PUBLIC ? VisibilityJson.updateVisibilitySourceAndAddWorkspaceId(visibilityJson, visibilitySource, workspaceId) : VisibilityJson.updateVisibilitySource(visibilityJson, visibilitySource); VisalloVisibility visalloVisibility = visibilityTranslator.toVisibility(visibilityJson); Visibility visibility = visalloVisibility.getVisibility(); ExistingElementMutation<T> m = element.<T>prepareMutation().alterElementVisibility(visibility); VisalloProperties.VISIBILITY_JSON.setProperty(m, visibilityJson, defaultVisibility); m.save(authorizations); return new VisibilityAndElementMutation<>(visalloVisibility, m); }
@Test public void testChangeVisibilityOnBadPropertyName() { graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_EMPTY) .setProperty("prop2", "value2", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); try { graph.getVertex("v1", AUTHORIZATIONS_A) .prepareMutation() .alterPropertyVisibility("propBad", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); fail("show throw"); } catch (VertexiumException ex) { assertNotNull(ex); } }
@Test public void testMetadataMutationsOnEdge() { Metadata metadataPropB = Metadata.create(); metadataPropB.add("meta1", "meta1", VISIBILITY_A); Edge edge = graph.prepareEdge("v1", "v2", LABEL_LABEL1, VISIBILITY_A) .setProperty("propBmeta", "propBmeta", metadataPropB, VISIBILITY_A) .save(AUTHORIZATIONS_ALL); graph.flush(); ExistingElementMutation<Edge> m = edge.prepareMutation(); m.setPropertyMetadata("propBmeta", "meta1", "meta2", VISIBILITY_A); edge = m.save(AUTHORIZATIONS_ALL); assertEquals("meta2", edge.getProperty("propBmeta").getMetadata().getEntry("meta1").getValue()); }
@Test public void testMutationChangePropertyVisibilityFollowedByMetadataUsingPropertyObject() { Metadata prop1Metadata = Metadata.create(); prop1Metadata.add("prop1_key1", "valueOld", VISIBILITY_A); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", prop1Metadata, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Vertex v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); Property p1 = v1.getProperty("prop1", VISIBILITY_A); v1.prepareMutation() .alterPropertyVisibility(p1, VISIBILITY_B) .setPropertyMetadata(p1, "prop1_key1", "valueNew", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); v1 = graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A_AND_B); assertEquals("valueNew", v1.getProperty("prop1", VISIBILITY_B).getMetadata().getEntry("prop1_key1", VISIBILITY_B).getValue()); }
m.alterElementVisibility(VISIBILITY_B); for (Property property : v1.getProperties()) { m.alterPropertyVisibility(property, VISIBILITY_B); m.setPropertyMetadata(property, "m1", "m1-value2", VISIBILITY_EMPTY); m.save(AUTHORIZATIONS_ALL); graph.flush();
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; } }
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; }
Vertex vertex = graph.getVertex("v1", fetchHints, AUTHORIZATIONS_A); ExistingElementMutation<Vertex> m = vertex.prepareMutation(); m.setPropertyMetadata("propBmeta", "meta1", "value2", VISIBILITY_A); m.save(AUTHORIZATIONS_ALL); graph.flush(); Metadata newMetadata = Metadata.create(); newMetadata.add("meta1", "value3", VISIBILITY_A); m.setProperty("propBmeta", "propBmeta", newMetadata, VISIBILITY_A); m.save(AUTHORIZATIONS_ALL); graph.flush();
@Test public void testEmptyPropertyMutation() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); v1.prepareMutation().save(AUTHORIZATIONS_ALL); }
m.addPropertyValue(propertyKey, authorPropertyIri, author, data.createPropertyMetadata(getUser()), data.getProperty().getVisibility()); org.vertexium.Metadata titleMetadata = data.createPropertyMetadata(getUser()); VisalloProperties.CONFIDENCE_METADATA.setMetadata(titleMetadata, SYSTEM_ASSIGNED_CONFIDENCE, defaultVisibility); m.addPropertyValue(propertyKey, titlePropertyIri, customImageMetadataJson.get("title").toString(), titleMetadata, data.getProperty().getVisibility()); org.vertexium.Metadata titleMetadata = data.createPropertyMetadata(getUser()); VisalloProperties.CONFIDENCE_METADATA.setMetadata(titleMetadata, SYSTEM_ASSIGNED_CONFIDENCE, defaultVisibility); m.addPropertyValue(propertyKey, titlePropertyIri, title, titleMetadata, data.getProperty().getVisibility()); m.save(getAuthorizations());
@Test public void testSoftDeletePropertyOnEdgeNotIndexed() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A_AND_B); Vertex v2 = graph.addVertex("v2", VISIBILITY_B, AUTHORIZATIONS_A_AND_B); ElementBuilder<Edge> elementBuilder = graph.prepareEdge("e1", v1, v2, LABEL_LABEL1, VISIBILITY_B) .setProperty("prop1", "value1", VISIBILITY_B); elementBuilder.setIndexHint(IndexHint.DO_NOT_INDEX); Edge e1 = elementBuilder.save(AUTHORIZATIONS_A_AND_B); graph.flush(); ExistingElementMutation<Edge> m = e1.prepareMutation(); m.softDeleteProperty("prop1", VISIBILITY_B); m.setIndexHint(IndexHint.DO_NOT_INDEX); m.save(AUTHORIZATIONS_A_AND_B); graph.flush(); e1 = graph.getEdge("e1", AUTHORIZATIONS_A_AND_B); assertEquals(0, IterableUtils.count(e1.getProperties())); }
@Override public <TElement extends Element> void updateElement(Graph graph, ExistingElementMutation<TElement> mutation, Authorizations authorizations) { TElement element = mutation.getElement(); addActionRequestBuilderForFlush(element, updateRequestBuilder); if (mutation.getNewElementVisibility() != null && element.getFetchHints().isIncludeExtendedDataTableNames()) { ImmutableSet<String> extendedDataTableNames = element.getExtendedDataTableNames(); if (extendedDataTableNames != null && !extendedDataTableNames.isEmpty()) { element, element.getExtendedData(tableName), mutation.getOldElementVisibility(), mutation.getNewElementVisibility() ));
private <TElement extends Element> Map<String, String> getFieldVisibilityChanges(Graph graph, ExistingElementMutation<TElement> mutation) { Map<String, String> fieldVisibilityChanges = new HashMap<>(); mutation.getAlterPropertyVisibilities().stream() .filter(p -> p.getExistingVisibility() != null && !p.getExistingVisibility().equals(p.getVisibility())) .forEach(p -> { String oldFieldName = addVisibilityToPropertyName(graph, p.getName(), p.getExistingVisibility()); String newFieldName = addVisibilityToPropertyName(graph, p.getName(), p.getVisibility()); fieldVisibilityChanges.put(oldFieldName, newFieldName); PropertyDefinition propertyDefinition = getPropertyDefinition(graph, p.getName()); if (GeoShape.class.isAssignableFrom(propertyDefinition.getDataType())) { fieldVisibilityChanges.put(oldFieldName + GEO_PROPERTY_NAME_SUFFIX, newFieldName + GEO_PROPERTY_NAME_SUFFIX); if (GeoPoint.class.isAssignableFrom(propertyDefinition.getDataType())) { fieldVisibilityChanges.put(oldFieldName + GEO_POINT_PROPERTY_NAME_SUFFIX, newFieldName + GEO_POINT_PROPERTY_NAME_SUFFIX); } } }); if (mutation.getNewElementVisibility() != null) { String oldFieldName = addVisibilityToPropertyName(graph, ELEMENT_TYPE_FIELD_NAME, mutation.getOldElementVisibility()); String newFieldName = addVisibilityToPropertyName(graph, ELEMENT_TYPE_FIELD_NAME, mutation.getNewElementVisibility()); fieldVisibilityChanges.put(oldFieldName, newFieldName); } return fieldVisibilityChanges; }
} else if (isUpdate && oldVisibilitySource != null && !oldVisibilitySource.equals(newVisibilitySource)) { elementMutation.alterPropertyVisibility(oldProperty, propertyVisibility); elementMutation.addPropertyValue(propertyKey, propertyName, value, propertyMetadata, propertyVisibility);
.alterPropertyVisibility(property, visalloVisibility.getVisibility()) .setPropertyMetadata( property, VisalloProperties.VISIBILITY_JSON.getPropertyName(),
@Override public void internalPublishConcept(Concept concept, User user, String workspaceId) { assert (concept instanceof VertexiumConcept); if (concept.getSandboxStatus() != SandboxStatus.PUBLIC) { Vertex vertex = ((VertexiumConcept) concept).getVertex(); VisibilityJson visibilityJson = VisalloProperties.VISIBILITY_JSON.getPropertyValue(vertex); if (visibilityJson != null && visibilityJson.getWorkspaces().contains(workspaceId)) { visibilityJson = VisibilityJson.removeFromAllWorkspace(visibilityJson); VisalloVisibility visalloVisibility = visibilityTranslator.toVisibility(visibilityJson); try (GraphUpdateContext ctx = graphRepository.beginGraphUpdate(Priority.NORMAL, user, getAuthorizations(workspaceId))) { ctx.update(vertex, new Date(), visibilityJson, null, vertexUpdateCtx -> { ExistingElementMutation<Vertex> mutation = (ExistingElementMutation<Vertex>) vertexUpdateCtx.getMutation(); mutation.alterElementVisibility(visalloVisibility.getVisibility()); }); removeEdge(ctx, workspaceId, vertex.getId()); } } } }