Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientGraph#removeEdge()

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientGraph#removeEdge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractProductRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void upVoteProduct(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex product = (OrientVertex) graph.getVertexByKey("Product.entityId", data.get("entityId"));
        if (product != null && updateUser != null) {
            // remove DownVote edge if there is.
            for (Edge edge : updateUser.getEdges(product, Direction.OUT, "DownVote")) {
                if (edge.getVertex(Direction.IN).equals(product)) graph.removeEdge(edge);
            }
            updateUser.addEdge("UpVote", product);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 2
Source File: AbstractProductRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downVoteProduct(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex product = (OrientVertex) graph.getVertexByKey("Product.entityId", data.get("entityId"));
        if (product != null && updateUser != null) {
            // remove UpVote edge if there is.
            for (Edge edge : updateUser.getEdges(product, Direction.OUT, "UpVote")) {
                if (edge.getVertex(Direction.IN).equals(product)) graph.removeEdge(edge);
            }
            updateUser.addEdge("DownVote", product);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 3
Source File: AbstractPostRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void upVotePost(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex post = (OrientVertex) graph.getVertexByKey("Post.entityId", data.get("entityId"));
        if (post != null && updateUser != null) {
            // remove DownVote edge if there is.
            for (Edge edge : updateUser.getEdges(post, Direction.OUT, "DownVote")) {
                if (edge.getVertex(Direction.IN).equals(post)) graph.removeEdge(edge);
            }
            updateUser.addEdge("UpVote", post);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 4
Source File: AbstractPostRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downVotePost(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex updateUser = (OrientVertex) graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex post = (OrientVertex) graph.getVertexByKey("Post.entityId", data.get("entityId"));
        if (post != null && updateUser != null) {
            // remove UpVote edge if there is.
            for (Edge edge : updateUser.getEdges(post, Direction.OUT, "UpVote")) {
                if (edge.getVertex(Direction.IN).equals(post)) graph.removeEdge(edge);
            }
            updateUser.addEdge("DownVote", post);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 5
Source File: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void upVoteUser(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex user = (OrientVertex)graph.getVertexByKey("User.userId", data.get("userId"));
        OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", data.get("voteUserId"));
        if(user != null && voteUser != null) {
            for (Edge edge : voteUser.getEdges(user, Direction.OUT, "DownVote")) {
                if(edge.getVertex(Direction.IN).equals(user)) graph.removeEdge(edge);
            }
            voteUser.addEdge("UpVote", user);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 6
Source File: AbstractUserRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downVoteUser(Map<String, Object> data) {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        OrientVertex user = (OrientVertex)graph.getVertexByKey("User.userId", data.get("userId"));
        OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", data.get("voteUserId"));
        if(user != null && voteUser != null) {
            for (Edge edge : voteUser.getEdges(user, Direction.OUT, "UpVote")) {
                if(edge.getVertex(Direction.IN).equals(user)) graph.removeEdge(edge);
            }
            voteUser.addEdge("DownVote", user);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
}
 
Example 7
Source File: BranchRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void downBranchDb(String branchType, Map<String, Object> data) throws Exception {
    String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1);
    String index = className + ".categoryId";
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex updateUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex branch = (OrientVertex)graph.getVertexByKey(index, data.get("categoryId"));
        if(branch != null && updateUser != null) {
            // remove UpVote edge if there is.
            for (Edge edge : updateUser.getEdges(branch, Direction.OUT, "UpVote")) {
                if(edge.getVertex(Direction.IN).equals(branch)) graph.removeEdge(edge);
            }
            updateUser.addEdge("DownVote", branch);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 8
Source File: BranchRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void upBranchDb(String branchType, Map<String, Object> data) throws Exception {
    String className = branchType.substring(0, 1).toUpperCase() + branchType.substring(1);
    String index = className + ".categoryId";
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        OrientVertex updateUser = (OrientVertex)graph.getVertexByKey("User.userId", data.remove("updateUserId"));
        OrientVertex branch = (OrientVertex)graph.getVertexByKey(index, data.get("categoryId"));
        if(branch != null && updateUser != null) {
            // remove DownVote edge if there is.
            for (Edge edge : updateUser.getEdges(branch, Direction.OUT, "DownVote")) {
                if(edge.getVertex(Direction.IN).equals(branch)) graph.removeEdge(edge);
            }
            updateUser.addEdge("UpVote", branch);
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 9
Source File: AbstractCommentRule.java    From light with Apache License 2.0 6 votes vote down vote up
protected void delComment(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        String commentId = (String)data.get("commentId");
        OrientVertex comment = (OrientVertex)graph.getVertexByKey("Comment.commentId", commentId);
        // remove the edge to this comment
        for (Edge edge : comment.getEdges(Direction.IN)) {
            graph.removeEdge(edge);
        }
        graph.removeVertex(comment);
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 10
Source File: AbstractCommentRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void spmComment(Map<String, Object> data) throws Exception {
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try{
        graph.begin();
        String commentId = (String)data.get("commentId");
        OrientVertex comment = (OrientVertex)graph.getVertexByKey("Comment.commentId", commentId);
        if(comment != null) {
            String userId = (String)data.get("userId");
            OrientVertex user = (OrientVertex)graph.getVertexByKey("User.userId", userId);
            if(user != null) {
                // check if this user has reported spam for this comment.
                boolean reported = false;
                for (Edge edge : user.getEdges(comment, Direction.OUT, "ReportSpam")) {
                    if(edge.getVertex(Direction.IN).equals(comment)) {
                        reported = true;
                        graph.removeEdge(edge);
                    }
                }
                if(!reported) {
                    user.addEdge("ReportSpam", comment);
                }
            }
        }
        graph.commit();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
    } finally {
        graph.shutdown();
    }
}
 
Example 11
Source File: DeleteEdgeCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected void performMultiAction(AjaxRequestTarget target, List<ODocument> objects) {
       OrientGraph tx = orientGraphProvider.get();
       for (ODocument doc : objects) {
           ORID id = doc.getIdentity();
           OrientEdge edge = tx.getEdge(id);
           tx.removeEdge(edge);
       }
       tx.commit();tx.begin();
       sendActionPerformed();
}
 
Example 12
Source File: UnlinkVertexCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void removeEdges(OrientGraph tx, OrientVertex vertex) {
    OrientVertex destination = tx.getVertex(documentModel.getObject().getIdentity());
    Iterable<Edge> edges = vertex.getEdges(destination, Direction.BOTH);
    for(Edge edge : edges) {
        tx.removeEdge(edge);
    }
}