Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientVertex#getEdges()
The following examples show how to use
com.tinkerpop.blueprints.impls.orient.OrientVertex#getEdges() .
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 |
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 2
Source File: AbstractProductRule.java From light with Apache License 2.0 | 6 votes |
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 3
Source File: AbstractCommentRule.java From light with Apache License 2.0 | 6 votes |
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 4
Source File: BranchRule.java From light with Apache License 2.0 | 6 votes |
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 5
Source File: AbstractPostRule.java From light with Apache License 2.0 | 6 votes |
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 6
Source File: AbstractPostRule.java From light with Apache License 2.0 | 6 votes |
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 7
Source File: BranchRule.java From light with Apache License 2.0 | 6 votes |
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: AbstractUserRule.java From light with Apache License 2.0 | 6 votes |
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 9
Source File: AbstractUserRule.java From light with Apache License 2.0 | 6 votes |
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 10
Source File: UnlinkVertexCommand.java From Orienteer with Apache License 2.0 | 5 votes |
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); } }
Example 11
Source File: AbstractCommentRule.java From light with Apache License 2.0 | 5 votes |
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 12
Source File: DownUserRule.java From light with Apache License 2.0 | 4 votes |
public boolean execute (Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>)objects[0]; Map<String, Object> data = (Map<String, Object>)inputMap.get("data"); Map<String, Object> userMap = (Map<String, Object>) inputMap.get("user"); String error = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { String voteUserId = (String)userMap.get("userId"); String userRid = (String)data.get("@rid"); OrientVertex user = (OrientVertex)DbService.getVertexByRid(graph, userRid); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", voteUserId); if(user == null || voteUser == null) { error = "User or vote user cannot be found"; inputMap.put("responseCode", 404); } else { // check if this VoteUserId has down voted user before. boolean voted = false; for (Edge edge : voteUser.getEdges(user, Direction.OUT, "DownVote")) { if(edge.getVertex(Direction.IN).equals(user)) voted = true; } if(voted) { error = "You have down vote the user already"; inputMap.put("responseCode", 400); } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("userId", user.getProperty("userId")); eventData.put("voteUserId", voteUserId); eventData.put("updateDate", new java.util.Date()); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if(error != null) { inputMap.put("result", error); return false; } else { return true; } }
Example 13
Source File: BranchRule.java From light with Apache License 2.0 | 4 votes |
public boolean downBranch (String branchType, Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>) objects[0]; Map<String, Object> data = (Map<String, Object>) inputMap.get("data"); String rid = (String) data.get("@rid"); String host = (String) data.get("host"); String error = null; Map<String, Object> user = (Map<String, Object>) inputMap.get("user"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex branch = (OrientVertex)DbService.getVertexByRid(graph, rid); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", user.get("userId")); if(branch == null) { error = "@rid " + rid + " cannot be found"; inputMap.put("responseCode", 404); } else { // TODO check if the current user has down voted the branch before. boolean voted = false; for (Edge edge : voteUser.getEdges(branch, Direction.OUT, "DownVote")) { if(edge.getVertex(Direction.IN).equals(branch)) voted = true; } if(voted) { error = "You have down voted the " + branchType + " already"; inputMap.put("responseCode", 400); } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("host", host); eventData.put("categoryId", branch.getProperty("categoryId")); eventData.put("updateUserId", user.get("userId")); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if(error != null) { inputMap.put("result", error); return false; } else { // update the branch tree as one of branch has changed. Map<String, Object> branchMap = ServiceLocator.getInstance().getMemoryImage("branchMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)branchMap.get("treeCache"); if(cache != null) { cache.remove(host + branchType); } return true; } }
Example 14
Source File: UpUserRule.java From light with Apache License 2.0 | 4 votes |
public boolean execute (Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>)objects[0]; Map<String, Object> data = (Map<String, Object>)inputMap.get("data"); Map<String, Object> userMap = (Map<String, Object>) inputMap.get("user"); String error = null; String voteUserId = (String)userMap.get("userId"); String userRid = (String)data.get("@rid"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex user = (OrientVertex)DbService.getVertexByRid(graph, userRid); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", voteUserId); if(user == null || voteUser == null) { error = "User or vote user cannot be found"; inputMap.put("responseCode", 404); } else { // check if this VoteUserId has down voted user before. boolean voted = false; for (Edge edge : voteUser.getEdges(user, Direction.OUT, "UpVote")) { if(edge.getVertex(Direction.IN).equals(user)) voted = true; } if(voted) { error = "You have up vote the user already"; inputMap.put("responseCode", 400); } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("userId", user.getProperty("userId")); eventData.put("voteUserId", voteUserId); eventData.put("updateDate", new java.util.Date()); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if(error != null) { inputMap.put("result", error); return false; } else { return true; } }
Example 15
Source File: BranchRule.java From light with Apache License 2.0 | 4 votes |
public boolean upBranch (String branchType, Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>) objects[0]; Map<String, Object> data = (Map<String, Object>) inputMap.get("data"); String rid = (String) data.get("@rid"); String host = (String) data.get("host"); String error = null; Map<String, Object> user = (Map<String, Object>) inputMap.get("user"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex branch = (OrientVertex)DbService.getVertexByRid(graph, rid); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", user.get("userId")); if(branch == null) { error = "@rid " + rid + " cannot be found"; inputMap.put("responseCode", 404); } else { // TODO check if the current user has up voted the branch before. boolean voted = false; for (Edge edge : voteUser.getEdges(branch, Direction.OUT, "UpVote")) { if(edge.getVertex(Direction.IN).equals(branch)) voted = true; } if(voted) { error = "You have up voted the " + branchType + " already"; inputMap.put("responseCode", 400); } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("host", host); eventData.put("categoryId", branch.getProperty("categoryId")); eventData.put("updateUserId", user.get("userId")); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if(error != null) { inputMap.put("result", error); return false; } else { // update the branch tree as one of branch has changed. Map<String, Object> branchMap = ServiceLocator.getInstance().getMemoryImage("branchMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)branchMap.get("treeCache"); if(cache != null) { cache.remove(host + branchType); } return true; } }
Example 16
Source File: UpPostRule.java From light with Apache License 2.0 | 4 votes |
public boolean execute (Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>)objects[0]; Map<String, Object> data = (Map<String, Object>)inputMap.get("data"); Map<String, Object> user = (Map<String, Object>) inputMap.get("user"); String rid = (String)data.get("@rid"); String error = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex post = (OrientVertex)DbService.getVertexByRid(graph, rid); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", user.get("userId")); if(post == null) { error = "@rid " + rid + " cannot be found"; inputMap.put("responseCode", 404); } else { // TODO check if the current user has up voted the post before. boolean voted = false; for (Edge edge : voteUser.getEdges(post, Direction.OUT, "UpVote")) { if(edge.getVertex(Direction.IN).equals(post)) voted = true; } if(voted) { error = "You have up voted the post already"; inputMap.put("responseCode", 400); } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("entityId", post.getProperty("entityId")); eventData.put("updateUserId", user.get("userId")); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if(error != null) { inputMap.put("result", error); return false; } else { return true; } }
Example 17
Source File: DownPostRule.java From light with Apache License 2.0 | 4 votes |
public boolean execute (Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>)objects[0]; Map<String, Object> data = (Map<String, Object>)inputMap.get("data"); Map<String, Object> user = (Map<String, Object>) inputMap.get("user"); String rid = (String)data.get("@rid"); String error = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex post = (OrientVertex) DbService.getVertexByRid(graph, rid); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", user.get("userId")); if(post == null) { error = "@rid " + rid + " cannot be found"; inputMap.put("responseCode", 404); } else { // TODO check if the current user has down voted the post before. boolean voted = false; for (Edge edge : voteUser.getEdges(post, Direction.OUT, "DownVote")) { if(edge.getVertex(Direction.IN).equals(post)) voted = true; } if(voted) { error = "You have down voted the post already"; inputMap.put("responseCode", 400); } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("entityId", post.getProperty("entityId")); eventData.put("updateUserId", user.get("userId")); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if(error != null) { inputMap.put("result", error); return false; } else { return true; } }
Example 18
Source File: UpProductRule.java From light with Apache License 2.0 | 4 votes |
public boolean execute (Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>)objects[0]; Map<String, Object> data = (Map<String, Object>)inputMap.get("data"); Map<String, Object> user = (Map<String, Object>) inputMap.get("user"); String rid = (String)data.get("@rid"); String error = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex product = (OrientVertex) DbService.getVertexByRid(graph, rid); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", user.get("userId")); if(product == null) { error = "@rid " + rid + " cannot be found"; inputMap.put("responseCode", 404); } else { // TODO check if the current user has up voted the product before. boolean voted = false; for (Edge edge : voteUser.getEdges(product, Direction.OUT, "UpVote")) { if(edge.getVertex(Direction.IN).equals(product)) voted = true; } if(voted) { error = "You have up voted the product already"; inputMap.put("responseCode", 400); } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("entityId", product.getProperty("entityId")); eventData.put("updateUserId", user.get("userId")); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if(error != null) { inputMap.put("result", error); return false; } else { return true; } }
Example 19
Source File: DownProductRule.java From light with Apache License 2.0 | 4 votes |
public boolean execute (Object ...objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>)objects[0]; Map<String, Object> data = (Map<String, Object>)inputMap.get("data"); Map<String, Object> user = (Map<String, Object>) inputMap.get("user"); String rid = (String)data.get("@rid"); String error = null; OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { OrientVertex product = (OrientVertex) DbService.getVertexByRid(graph, rid); OrientVertex voteUser = (OrientVertex)graph.getVertexByKey("User.userId", user.get("userId")); if(product == null) { error = "@rid " + rid + " cannot be found"; inputMap.put("responseCode", 404); } else { boolean voted = false; for (Edge edge : voteUser.getEdges(product, Direction.OUT, "DownVote")) { if(edge.getVertex(Direction.IN).equals(product)) voted = true; } if(voted) { error = "You have down voted the product already"; inputMap.put("responseCode", 400); } else { Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>)eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("entityId", product.getProperty("entityId")); eventData.put("updateUserId", user.get("userId")); } } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if(error != null) { inputMap.put("result", error); return false; } else { return true; } }