annotate app/models/ClaimModel.java @ 38:a2abe67d7c7a

fix createMention action bug
author one
date Thu, 04 Oct 2012 01:05:19 +0900
parents bc3ac73320f9
children 870553e92e3e
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
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
12 import com.tinkerpop.blueprints.Edge;
36
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
13 import com.tinkerpop.blueprints.Graph;
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
14 import com.tinkerpop.blueprints.Vertex;
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
15 import com.tinkerpop.gremlin.java.GremlinPipeline;
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
16
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
17 public class ClaimModel extends NodeModel {
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
18
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
19
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
20 public ClaimModel(Vertex vertex) {
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
21 super(vertex);
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
22 }
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
23
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
24 public ObjectNode getSimpleClaimInfo() {
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
25 ObjectNode property = Json.newObject();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
26 property.put(TYPE, Json.toJson(getProperty(TYPE)));
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
27 property.put(STATUS, Json.toJson(getProperty(STATUS)));
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
28 property.put(TOULMIN, Json.toJson(getProperty(TOULMIN)));
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
29 property.put(L_AUTHOR, Json.toJson(getAuthorId()));
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
30 property.put(MENTIONS, Json.toJson(getMentionsId()));
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
31 property.put(USERS, Json.toJson(getUsersId()));
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
32 return property;
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
33 }
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
34
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
35 public ObjectNode getClaimInfoTraverse() {
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
36 ObjectNode property = Json.newObject();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
37 property.put(TYPE, Json.toJson(getProperty(TYPE)));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
38 property.put(STATUS, Json.toJson(getProperty(STATUS)));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
39 property.put(TOULMIN, Json.toJson(getProperty(TOULMIN)));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
40 property.put(L_AUTHOR, Json.toJson(getAuthorId()));
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
41 property.put(MENTIONS, Json.toJson(getClaimMentionsRecursive()));
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
42 property.put(USERS, Json.toJson(getUsersIdAndStatus()));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
43 return property;
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
44 }
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
45
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
46 public Object[] getClaimMentionsRecursive() {
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
47 GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex,Edge>();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
48 pipe.start(vertex).outE(L_QUESTION,L_REFUTATION,L_SUGGESTION);
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
49 ArrayList<Object> array = new ArrayList<Object>();
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
50 for (Edge e:pipe) {
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
51 String label = e.getLabel();
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
52 ObjectNode info = Json.newObject();
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
53 info.put(TYPE, Json.toJson(label));
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
54 GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>();
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
55 pipeChildVertex.start(e).inV();
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
56 ClaimModel childClaim = new ClaimModel(pipeChildVertex.next());
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
57 info.put(CLAIM, childClaim.getClaimInfoTraverse());
38
a2abe67d7c7a fix createMention action bug
one
parents: 37
diff changeset
58 info.put(ID, Json.toJson(childClaim.getId()));
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
59 array.add(info);
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
60 }
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
61 return array.toArray();
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
62 }
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
63
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
64 public Object[] getInfoArray(String... labels) {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
65 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
66 pipe.start(vertex).out(labels);
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
67 ArrayList<Object> array = new ArrayList<Object>();
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
68 for (Vertex v : pipe) array.add(v.getId());
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
69 if (array.size() == 0) return null;
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
70 return array.toArray();
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
71 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
72
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
73 public Object[] getMentionsId() {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
74 return getInfoArray(L_QUESTION,L_REFUTATION,L_SUGGESTION);
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
75 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
76
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
77 public Object[] getUsersId() {
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
78 return getInfoArray(L_REQUEST);
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
79 }
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
80
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
81 public Object[] getUsersIdAndStatus() {
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
82 GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
83 pipeEdge.start(vertex).outE(L_REQUEST);
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
84 ArrayList<Object> array = new ArrayList<Object>();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
85 for (Edge e : pipeEdge) {
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
86 GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
87 ObjectNode info = Json.newObject();
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
88 pipeChildVertex.start(e).inV();
31
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
89 Vertex childVertex = pipeChildVertex.next();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
90 info.put(ID, Json.toJson(childVertex.getId()));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
91 info.put(STATUS, Json.toJson(e.getProperty(STATUS)));
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
92 array.add(info);
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
93 }
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
94 return array.toArray();
995be14b30a2 create ClaimModel/getUsersIdAndStatus method
one
parents: 30
diff changeset
95 }
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
96
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
97 public Object[] getRequestUsersId() {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
98 return getInfoArray(NodeModel.REQUESTS);
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
99 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
100
36
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
101 public void editRequestsEdgeUsers(Object[] updateUsers) {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
102 TPGraph tpGraph = TPGraph.getInstance();
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
103 Object[] currentUsers = getUsersId();
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
104 HashSet<Object> currentUsersHashSet = new HashSet<Object>();
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
105 for (Object u : currentUsers) {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
106 currentUsersHashSet.add(u);
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
107 }
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
108 for (Object updateUser : updateUsers) {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
109 if (currentUsersHashSet.contains(updateUser)) {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
110 currentUsersHashSet.remove(updateUser);
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
111 } else {
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
112 tpGraph.setLabelStatusToUser(this, updateUser.toString(), L_REQUEST, UNKNOWN);
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
113 }
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
114 }
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
115 tpGraph.deleteRequestEdge(this, currentUsersHashSet);
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
116 }
5f7fcdf98380 create editClaim
one
parents: 34
diff changeset
117
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
118 public Object getAuthorId() {
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
119 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
120 pipe.start(vertex).out(L_AUTHOR);
32
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
121 if (!pipe.hasNext()) {
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
122 return null;
be6bbd4967e4 create createMentions
one
parents: 31
diff changeset
123 }
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
124 Vertex authorV = pipe.next();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
125 return authorV.getId();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
126 }
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
127
18
one
parents: 16
diff changeset
128 public void setClaimProperties(JsonNode toulmin, String type) {
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
129 String title = toulmin.findPath(TITLE).getTextValue();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
130 String contents = toulmin.findPath(CONTENTS).getTextValue();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
131 String q = toulmin.findPath(QUALIFIER).getTextValue(); // Qualifier
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
132 String d = toulmin.findPath(DATA).getTextValue(); // Data
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
133 String w = toulmin.findPath(WARRANT).getTextValue(); // Warrant
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
134 String b = toulmin.findPath(BACKING).getTextValue(); // Backing
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
135 String r = toulmin.findPath(REBUTTLE).getTextValue(); // Rebuttle
16
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
136 ObjectNode t = Json.newObject();
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
137 t.put(TITLE, title);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
138 t.put(CONTENTS, contents);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
139 t.put(QUALIFIER, q);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
140 t.put(DATA, d);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
141 t.put(WARRANT, w);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
142 t.put(BACKING, b);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
143 t.put(REBUTTLE, r);
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
144 setProperty(TYPE, type);
37
bc3ac73320f9 fix const value FAILED from FAIL
one
parents: 36
diff changeset
145 setProperty(STATUS, UNKNOWN); // Default Status is unknown.
16
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
146 setProperty(TOULMIN, t);
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 18
diff changeset
147 }
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
148 }