annotate app/models/TPGraph.java @ 16:7cdc9d19834f

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