7
|
1 package models;
|
|
2
|
16
|
3 import org.codehaus.jackson.JsonNode;
|
|
4
|
8
|
5 import scala.reflect.generic.Trees.This;
|
|
6
|
7
|
7 import com.tinkerpop.blueprints.Graph;
|
|
8 import com.tinkerpop.blueprints.Vertex;
|
|
9 import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
|
|
10
|
|
11 public class TPGraph {
|
|
12
|
|
13 private static TPGraph instance = new TPGraph();
|
|
14 private Object claimRootId;
|
|
15 private Object userRootId;
|
|
16
|
13
|
17 /*
|
|
18 * Edge type
|
|
19 */
|
8
|
20 protected final String CHILD = "child";
|
|
21
|
13
|
22
|
7
|
23 private TPGraph() {
|
|
24
|
|
25 }
|
|
26
|
|
27 public static TPGraph getInstance() {
|
|
28 return instance;
|
|
29 }
|
|
30
|
|
31 private Graph graph;
|
|
32 private String path = null;
|
|
33
|
|
34 public void setPath(String path) {
|
|
35 this.path = path;
|
|
36 }
|
|
37
|
|
38 public Graph newGraph() {
|
|
39 if (path == null) {
|
|
40 graph = new TinkerGraph();
|
|
41 } else {
|
|
42 graph = new TinkerGraph(path);
|
|
43
|
|
44 }
|
|
45 return graph;
|
|
46 }
|
|
47
|
|
48 public Graph getGraph() {
|
|
49 return graph;
|
|
50 }
|
|
51
|
8
|
52 public void setClaimRootId(Object id) {
|
|
53 this.claimRootId = id;
|
7
|
54 }
|
|
55
|
8
|
56 public void setUserRootId(Object id) {
|
|
57 this.userRootId = id;
|
7
|
58 }
|
|
59
|
13
|
60 public Object getClaimRootId() {
|
|
61 return claimRootId;
|
|
62 }
|
|
63
|
8
|
64 public Object getUserRootId() {
|
|
65 return userRootId;
|
|
66 }
|
|
67
|
|
68 public Vertex getClaimRootVertex() {
|
13
|
69 return graph.getVertex(claimRootId);
|
7
|
70 }
|
|
71
|
8
|
72 public Vertex getUserRootVertex() {
|
|
73 return graph.getVertex(userRootId);
|
7
|
74 }
|
8
|
75
|
|
76 public void setLabelToRootUser(UserModel user) {
|
|
77 Vertex rootUser = getUserRootVertex();
|
13
|
78 /*
|
|
79 * rootUser ---child---> newUser
|
|
80 */
|
|
81 graph.addEdge(null, rootUser, user.getVertex(), CHILD);
|
|
82 }
|
8
|
83
|
13
|
84 public void setLabelToRootClaim(ClaimModel claim) {
|
|
85 Vertex rootClaim = getClaimRootVertex();
|
8
|
86 /*
|
|
87 * rootUser ---child---> newUser
|
|
88 */
|
16
|
89 graph.addEdge(null, rootClaim, claim.getVertex(), CHILD);
|
8
|
90 }
|
|
91
|
16
|
92 public void setLabelToAuthor(String author, ClaimModel claim) {
|
|
93 Vertex authorVertex = graph.getVertex(author);
|
|
94
|
|
95 /*
|
|
96 * claim ---author---> authorVertex(userVertex)
|
|
97 */
|
|
98 graph.addEdge(null, claim.getVertex(), authorVertex, NodeModel.AUTHOR);
|
|
99
|
|
100 }
|
|
101
|
|
102 public Boolean updateUserVertex(Vertex claim, JsonNode usersJson) {
|
|
103
|
|
104
|
|
105 return true;
|
|
106 }
|
9
|
107
|
7
|
108
|
|
109 public void shutdownGraph() {
|
|
110 graph.shutdown();
|
|
111 }
|
|
112
|
8
|
113
|
|
114
|
|
115
|
7
|
116
|
|
117
|
|
118 }
|