annotate app/models/ClaimModel.java @ 47:9645bfb49603

modified computeAndUpdateStatus
author one
date Thu, 04 Oct 2012 08:55:13 +0900
parents 49aa4ad3008f
children bc35c27966f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
1 package models;
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
2
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
3 import java.util.ArrayList;
36
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
4 import java.util.HashSet;
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
5 import java.util.Iterator;
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
6
16
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
7 import org.codehaus.jackson.JsonNode;
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
8 import org.codehaus.jackson.node.ObjectNode;
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
9
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
10 import play.libs.Json;
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
11
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
12 import com.tinkerpop.blueprints.Direction;
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
13 import com.tinkerpop.blueprints.Edge;
36
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
14 import com.tinkerpop.blueprints.Graph;
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
15 import com.tinkerpop.blueprints.Vertex;
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
16 import com.tinkerpop.gremlin.java.GremlinPipeline;
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
17
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
18 public class ClaimModel extends NodeModel {
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
19
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
20
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
21 public ClaimModel(Vertex vertex) {
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
22 super(vertex);
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
23 }
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
24
47
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
25 public void setClaimProperties(JsonNode toulmin, String type) {
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
26 String title = toulmin.findPath(TITLE).getTextValue();
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
27 String contents = toulmin.findPath(CONTENTS).getTextValue();
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
28 String q = toulmin.findPath(QUALIFIER).getTextValue(); // Qualifier
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
29 String d = toulmin.findPath(DATA).getTextValue(); // Data
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
30 String w = toulmin.findPath(WARRANT).getTextValue(); // Warrant
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
31 String b = toulmin.findPath(BACKING).getTextValue(); // Backing
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
32 String r = toulmin.findPath(REBUTTLE).getTextValue(); // Rebuttle
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
33 ObjectNode t = Json.newObject();
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
34 t.put(TITLE, title);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
35 t.put(CONTENTS, contents);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
36 t.put(QUALIFIER, q);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
37 t.put(DATA, d);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
38 t.put(WARRANT, w);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
39 t.put(BACKING, b);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
40 t.put(REBUTTLE, r);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
41 if (type == null) {
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
42 setProperty(TYPE, UNANIMOUSLY);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
43 } else {
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
44 setProperty(TYPE, type);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
45 }
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
46 if (getProperty(STATUS) == null) {
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
47 setProperty(STATUS, UNKNOWN); // Default Status is unknown.
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
48 }
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
49 setProperty(TOULMIN, t);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
50 }
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
51 public ObjectNode getSimpleClaimInfo() {
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
52 ObjectNode property = Json.newObject();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
53 property.put(TYPE, Json.toJson(getProperty(TYPE)));
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
54 property.put(STATUS, Json.toJson(getProperty(STATUS)));
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
55 property.put(TOULMIN, Json.toJson(getProperty(TOULMIN)));
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
56 property.put(L_AUTHOR, Json.toJson(getAuthorId()));
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
57 property.put(MENTIONS, Json.toJson(getMentionsId()));
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
58 property.put(USERS, Json.toJson(getUsersId()));
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
59 return property;
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
60 }
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
61
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
62 public ObjectNode getClaimInfoTraverse() {
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
63 ObjectNode property = Json.newObject();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
64 property.put(TYPE, Json.toJson(getProperty(TYPE)));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
65 property.put(STATUS, Json.toJson(getProperty(STATUS)));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
66 property.put(TOULMIN, Json.toJson(getProperty(TOULMIN)));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
67 property.put(L_AUTHOR, Json.toJson(getAuthorId()));
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
68 property.put(MENTIONS, Json.toJson(getClaimMentionsRecursive()));
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
69 property.put(USERS, Json.toJson(getUsersIdAndStatus()));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
70 return property;
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
71 }
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
72
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
73 public Object[] getClaimMentionsRecursive() {
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
74 GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex,Edge>();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
75 pipe.start(vertex).outE(L_QUESTION,L_REFUTATION,L_SUGGESTION);
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
76 ArrayList<Object> array = new ArrayList<Object>();
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
77 for (Edge e:pipe) {
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
78 String label = e.getLabel();
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
79 ObjectNode info = Json.newObject();
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
80 info.put(TYPE, Json.toJson(label));
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
81 GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>();
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
82 pipeChildVertex.start(e).inV();
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
83 ClaimModel childClaim = new ClaimModel(pipeChildVertex.next());
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
84 info.put(CLAIM, childClaim.getClaimInfoTraverse());
38
a2abe67d7c7a fix createMention action bug
one
parents: 37
diff changeset
85 info.put(ID, Json.toJson(childClaim.getId()));
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
86 array.add(info);
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
87 }
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
88 return array.toArray();
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
89 }
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
90
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
91 private Iterable<Vertex> getVertex(Direction direction, String... labels) {
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
92 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
93 if (direction.equals(Direction.IN)){
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
94 pipe.start(vertex).in(labels);
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
95 } else if (direction.equals(Direction.OUT)) {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
96 pipe.start(vertex).out(labels);
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
97 } else {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
98 pipe.start(vertex).both(labels);
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
99 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
100 ArrayList<Vertex> array = new ArrayList<Vertex>();
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
101 for (Vertex v : pipe) {
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
102 array.add(v);
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
103 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
104 if (array.size() == 0) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
105 return null;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
106 }
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
107 return array;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
108 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
109
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
110 private Object[] getVertexArray(Direction direction,String... labels) {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
111 Iterable<Vertex> iter = getVertex(direction,labels);
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
112 if (iter == null) {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
113 return null;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
114 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
115 ArrayList<Object> array = new ArrayList<Object>();
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
116 for (Vertex v : iter) {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
117 array.add(v.getId());
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
118 }
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
119 return array.toArray();
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
120 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
121
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
122 public Object[] getMentionsId() {
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
123 return getVertexArray(Direction.OUT, L_QUESTION,L_REFUTATION,L_SUGGESTION);
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
124 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
125
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
126 public Object[] getUsersId() {
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
127 return getVertexArray(Direction.OUT, L_REQUEST);
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
128 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
129
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
130 public Object[] getEdgeArray(String... labels) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
131 GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex,Edge>();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
132 pipe.start(vertex).outE(labels);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
133 ArrayList<Object> array = new ArrayList<Object>();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
134 for (Edge e : pipe) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
135 array.add(e.getId());
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
136 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
137 if (array.size() == 0) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
138 return null;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
139 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
140 return array.toArray();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
141 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
142
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
143 public Object[] getRequestEdges() {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
144 return getEdgeArray(L_REQUEST);
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
145 }
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
146
39
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
147 public ObjectNode getUserRequestStatus(UserModel user) {
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
148 GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
149 pipeEdge.start(vertex).outE(L_REQUEST);
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
150 ObjectNode info = Json.newObject();
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
151 for (Edge e : pipeEdge) {
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
152 GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>();
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
153 pipeChildVertex.start(e).inV();
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
154 Vertex childVertex = pipeChildVertex.next();
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
155 if (childVertex.getId() == user.getId()) {
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
156 info.put(STATUS, Json.toJson(e.getProperty(STATUS)));
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
157 break;
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
158 }
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
159 }
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
160 return info;
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
161 }
870553e92e3e create getUserConsensusStatus action
one
parents: 38
diff changeset
162
41
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
163 public Boolean updateUserRequestStatus(ClaimModel claim, UserModel user, String status) {
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
164 GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
165 pipeEdge.start(vertex).outE(L_REQUEST);
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
166 for (Edge e : pipeEdge) {
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
167 GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>();
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
168 pipeChildVertex.start(e).inV();
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
169 Vertex childVertex = pipeChildVertex.next();
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
170 if (childVertex.getId() == user.getId()) {
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
171 e.setProperty(STATUS, status);
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
172 break;
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
173 }
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
174 }
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
175 return true;
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
176 }
f78442777849 create updateRequestStatus
one
parents: 39
diff changeset
177
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
178 public Object[] getUsersIdAndStatus() {
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
179 GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
180 pipeEdge.start(vertex).outE(L_REQUEST);
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
181 ArrayList<Object> array = new ArrayList<Object>();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
182 for (Edge e : pipeEdge) {
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
183 GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
184 ObjectNode info = Json.newObject();
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
185 pipeChildVertex.start(e).inV();
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
186 Vertex childVertex = pipeChildVertex.next();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
187 info.put(ID, Json.toJson(childVertex.getId()));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
188 info.put(STATUS, Json.toJson(e.getProperty(STATUS)));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
189 array.add(info);
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
190 }
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
191 return array.toArray();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
192 }
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
193
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
194 public Object[] getRequestUsersId() {
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
195 return getVertexArray(Direction.OUT, NodeModel.REQUESTS);
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
196 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
197
36
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
198 public void editRequestsEdgeUsers(Object[] updateUsers) {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
199 TPGraph tpGraph = TPGraph.getInstance();
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
200 Object[] currentUsers = getUsersId();
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
201 HashSet<Object> currentUsersHashSet = new HashSet<Object>();
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
202 for (Object u : currentUsers) {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
203 currentUsersHashSet.add(u);
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
204 }
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
205 for (Object updateUser : updateUsers) {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
206 if (currentUsersHashSet.contains(updateUser)) {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
207 currentUsersHashSet.remove(updateUser);
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
208 } else {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
209 tpGraph.setLabelStatusToUser(this, updateUser.toString(), L_REQUEST, UNKNOWN);
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
210 }
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
211 }
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
212 tpGraph.deleteRequestEdge(this, currentUsersHashSet);
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
213 }
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
214
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
215 public Object getAuthorId() {
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
216 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
217 pipe.start(vertex).out(L_AUTHOR);
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
218 if (!pipe.hasNext()) {
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
219 return null;
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
220 }
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
221 Vertex authorV = pipe.next();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
222 return authorV.getId();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
223 }
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
224
47
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
225
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
226
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
227 public long getAgreedNumber(Object[] requestEdges) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
228 return getEdgeStatusNumber(requestEdges, AGREED);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
229 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
230
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
231 public long getDeninedNumber(Object[] requestEdges) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
232 return getEdgeStatusNumber(requestEdges, DENIED);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
233 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
234
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
235 public long getDeniedNumber(Object[] requestEdges) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
236 return getEdgeStatusNumber(requestEdges, DENIED);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
237 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
238
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
239 private long getEdgeStatusNumber(Object[] requestEdges, String checkStatus) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
240 TPGraph tpGraph = TPGraph.getInstance();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
241 Graph graph = tpGraph.getGraph();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
242 long count = 0;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
243 for (Object eId : requestEdges) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
244 Edge e = graph.getEdge(eId);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
245 String status = e.getProperty(STATUS).toString();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
246 if (status.equals(checkStatus)) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
247 count++;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
248 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
249 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
250 return count;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
251 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
252
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
253 private Boolean checkUnanimously(String childStatus, long requestsNumber, long agreedNumber, long deniedNumber) {
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
254 String preStatus = getProperty(STATUS).toString();
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
255 if ( requestsNumber == agreedNumber && childStatus.equals(PASS)) {
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
256 setProperty(STATUS,PASS);
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
257 } else if ( requestsNumber == deniedNumber && childStatus.equals(FAILED)){
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
258 setProperty(STATUS, FAILED);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
259 } else {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
260 setProperty(STATUS, UNKNOWN);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
261 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
262 String nowStatus = getProperty(STATUS).toString();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
263 return nowStatus.equals(preStatus);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
264 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
265
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
266 private Boolean checkMajority(long requestsNumber, long agreedNumber, long deniedNumber) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
267 // TODO
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
268 return false;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
269 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
270
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
271 public void computeAndUpdateStatus() {
47
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
272 /* Check child claim */
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
273 String refutationStatus = checkRefutationClaims();
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
274 if (refutationStatus.equals(FAILED)) {
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
275 setProperty(STATUS,FAILED);
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
276 return;
47
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
277 } else if (refutationStatus.equals(UNKNOWN)) {
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
278 setProperty(STATUS,UNKNOWN);
46
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
279 return;
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
280 }
47
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
281 String queAndSugStatus = checkQuestionAndSuggestionClaims();
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
282 if (queAndSugStatus.equals(UNKNOWN)) {
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
283 setProperty(STATUS,UNKNOWN);
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
284 return;
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
285 }
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
286 String childStatus;
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
287 /* refutationStatus == PASS */
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
288 if (refutationStatus.equals(queAndSugStatus)) {
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
289 childStatus = PASS;
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
290 } else { /* queAndSugStatus == FAILED */
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
291 childStatus = FAILED;
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
292 }
9645bfb49603 modified computeAndUpdateStatus
one
parents: 46
diff changeset
293 /* Check user request status */
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
294 Object[] requestEdges = getRequestEdges();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
295 String type = getProperty(TYPE).toString();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
296 long requestsNumber = requestEdges.length;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
297 long agreedNumber = getAgreedNumber(requestEdges);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
298 long deniedNumber = getDeninedNumber(requestEdges);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
299 Boolean statusChanged = false;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
300 if (type.equals(UNANIMOUSLY)) {
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
301 statusChanged = checkUnanimously(childStatus, requestsNumber, agreedNumber, deniedNumber);
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
302 } else if (type.equals(MAJORITY)) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
303
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
304 } else {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
305 statusChanged = false;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
306 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
307 if (statusChanged) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
308 ClaimModel parentClaim = new ClaimModel(getParentVertex());
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
309 if (parentClaim.getVertex() == null) { // If parentClaim is Root.
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
310 return;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
311 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
312 parentClaim.computeAndUpdateStatus();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
313 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
314 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
315
46
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
316 private String checkQuestionAndSuggestionClaims() {
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
317 Iterable<Vertex> iter = getVertex(Direction.OUT, L_QUESTION, L_SUGGESTION);
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
318 if (iter == null) {
46
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
319 return PASS;
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
320 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
321 String status = null;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
322 for (Vertex v : iter) {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
323 String nextChildStatus = v.getProperty(STATUS).toString();
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
324 if (status == null) {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
325 status = nextChildStatus;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
326 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
327 if (!nextChildStatus.equals(status)) {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
328 return UNKNOWN;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
329 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
330 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
331 return status;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
332 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
333
46
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
334 private String checkRefutationClaims() {
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
335 Iterable<Vertex> iter = getVertex(Direction.OUT, L_REFUTATION);
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
336 if (iter == null) {
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
337 return PASS;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
338 }
46
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
339 String status = null;
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
340 for (Vertex v : iter) {
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
341 String childStatus = v.getProperty(STATUS).toString();
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
342 if (status == null) {
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
343 status = childStatus;
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
344 }
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
345 if (status.equals(PASS)) {
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
346 return FAILED;
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
347 } else if (!status.equals(childStatus)) {
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
348 status = UNKNOWN;
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
349 }
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
350 }
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
351 if (status.equals(FAILED)) {
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
352 return PASS;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
353 }
46
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
354 return UNKNOWN;
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
355 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
356
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
357 private String checkAllChildsStatus() {
45
one
parents: 44
diff changeset
358 String queAndSugStatus = checkQuestionAndSuggestionClaims();
one
parents: 44
diff changeset
359 String refutationStatus = checkRefutationClaims();
one
parents: 44
diff changeset
360 if (refutationStatus.equals(FAILED)) {
one
parents: 44
diff changeset
361 return FAILED;
46
49aa4ad3008f modified ClaimModel/checkRefutationClaim method
one
parents: 45
diff changeset
362 } else if (refutationStatus.equals(queAndSugStatus)) {
45
one
parents: 44
diff changeset
363 return queAndSugStatus;
44
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
364 } else {
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
365 return UNKNOWN;
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
366 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
367 }
853bc291a3bb modified ClaimModel/computeAndUpdateStatus method
one
parents: 43
diff changeset
368
42
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
369 private Vertex getParentVertex() {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
370 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
371 pipe.start(vertex).in(L_QUESTION,L_REFUTATION,L_SUGGESTION);
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
372 if (pipe.hasNext()) {
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
373 return pipe.next();
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
374 }
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
375 return null;
4321d97da830 modified updateUserConsensusStatus
one
parents: 41
diff changeset
376 }
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
377 }