private boolean processDeletion(ProcessingTree<BE> changesTree, List<Notification<?, ?>> ns) { DBG.debugf("Checking for deletion of entity %s", changesTree.cp); Optional<Notification<?, ?>> deleteNotification = ns.stream() .filter(n -> n.getAction() == Action.deleted() && n.getValue() instanceof AbstractElement) .filter(n -> ((AbstractElement<?, ?>) n.getValue()).getPath().equals(changesTree.cp)) .findAny(); if (deleteNotification.isPresent()) { DBG.debugf("Processing deletion of the entity %s", changesTree.cp); //just emit what the caller wanted and don't bother any longer Notification<?, ?> n = deleteNotification.get(); correctedChanges.add(new EntityAndPendingNotifications<BE, AbstractElement<?, ?>>( null, (AbstractElement<?, ?>) n.getValue(), ns)); changesTree.dfsTraversal(pt -> { correctChanges(pt, false); return true; }); DBG.debugf("Done processing deletion of entity %s", changesTree.cp); return true; } DBG.debugf("No delete notifications found for entity %s", changesTree.cp); return false; }
tx.getPreCommit().addNotifications(new EntityAndPendingNotifications<>(be, e, deleted())); };
public static <BE> EntityAndPendingNotifications<BE, Relationship> deleteAssociation(Transaction<BE> tx, Query sourceQuery, SegmentType sourceType, String relationship, BE target) { BE source = getSingle(tx, sourceQuery, sourceType); BE relationshipObject; try { relationshipObject = tx.getRelationship(source, target, relationship); } catch (ElementNotFoundException e) { throw new RelationNotFoundException(sourceType, relationship, Query.filters(sourceQuery), null, e); } RelationshipRules.checkDelete(tx, source, Relationships.Direction.outgoing, relationship, target); Relationship ret = tx.convert(relationshipObject, Relationship.class); tx.delete(relationshipObject); return new EntityAndPendingNotifications<>(relationshipObject, ret, new Notification<>(ret, ret, deleted())); }
@Override public void delete(String id) throws RelationNotFoundException { //TODO this doesn't respect the current position in the graph inTx((tx) -> { try { BE relationshipObject = tx.find(CanonicalPath.of().relationship(id).get()); BE source = tx.getRelationshipSource(relationshipObject); BE target = tx.getRelationshipTarget(relationshipObject); String relationshipName = tx.extractRelationshipName(relationshipObject); RelationshipRules.checkDelete(tx, source, Relationships.Direction.outgoing, relationshipName, target); Relationship r = tx.convert(relationshipObject, Relationship.class); tx.delete(relationshipObject); tx.getPreCommit().addNotifications( new EntityAndPendingNotifications<>(relationshipObject, r, deleted())); return null; } catch (ElementNotFoundException e) { throw new RelationNotFoundException(id, Query.filters(context.select().with(RelationWith.id(id)).get())); } }); } }