annotate app/models/ClaimModel.java @ 30:80b5628f17d8

modified ClaimModel/getInfo action
author one
date Wed, 03 Oct 2012 14:27:44 +0900
parents fbb232e78422
children 995be14b30a2
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;
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
4
16
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
5 import org.codehaus.jackson.JsonNode;
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
6 import org.codehaus.jackson.node.ObjectNode;
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
7
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
8 import play.libs.Json;
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
9
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
10 import com.tinkerpop.blueprints.Vertex;
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
11 import com.tinkerpop.gremlin.java.GremlinPipeline;
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
12
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
13 public class ClaimModel extends NodeModel {
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
15
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
16 public ClaimModel(Vertex vertex) {
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
17 super(vertex);
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
18 }
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
19
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
20 public ObjectNode getClaimInfoFromGraph() {
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
21 ObjectNode property = Json.newObject();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
22 property.put(TYPE, Json.toJson(getProperty(TYPE)));
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
23 property.put(STATUS, Json.toJson(getProperty(STATUS)));
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
24 property.put(TOULMIN, Json.toJson(getProperty(TOULMIN)));
28
7112b826a53a modified RequestTest.java
one
parents: 25
diff changeset
25
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
26 property.put(L_AUTHOR, Json.toJson(getAuthorId()));
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
27 property.put(MENTIONS, Json.toJson(getMentionsId()));
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
28 property.put(USERS, Json.toJson(getUsers()));
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
29 return property;
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
30 }
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
31
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
32 public JsonNode getClaimMentions() {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
33
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
34
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
35
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
36 return null;
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
37 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
38
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
39 private JsonNode getClaimMention() {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
40
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
41 return null;
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
42 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
43
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
44 public Object[] getInfoArray(String... labels) {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
45 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
46 pipe.start(vertex).out(labels);
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
47 ArrayList<Object> array = new ArrayList<Object>();
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
48 for (Vertex v : pipe) array.add(v.getId());
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
49 if (array.size() == 0) return null;
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
50 return array.toArray();
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
51 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
52
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
53 public Object[] getMentionsId() {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
54 return getInfoArray(L_QUESTION,L_REFUTATION,L_SUGGESTION);
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
55 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
56
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
57 public Object[] getUsers() {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
58 return getInfoArray(L_REQUEST);
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
59 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
60
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
61
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
62 public Object[] getRequestUsersId() {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
63 return getInfoArray(NodeModel.REQUESTS);
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
64 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
65
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 29
diff changeset
66 public Object getAuthorId() {
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
67 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
68 pipe.start(vertex).out(L_AUTHOR);
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
69 if (pipe.hasNext()) return null;
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
70 Vertex authorV = pipe.next();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
71 return authorV.getId();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
72 }
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
73
28
7112b826a53a modified RequestTest.java
one
parents: 25
diff changeset
74
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
75
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
76
18
one
parents: 16
diff changeset
77 public void setClaimProperties(JsonNode toulmin, String type) {
29
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
78 String title = toulmin.findPath(TITLE).getTextValue();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
79 String contents = toulmin.findPath(CONTENTS).getTextValue();
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
80 String q = toulmin.findPath(QUALIFIER).getTextValue(); // Qualifier
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
81 String d = toulmin.findPath(DATA).getTextValue(); // Data
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
82 String w = toulmin.findPath(WARRANT).getTextValue(); // Warrant
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
83 String b = toulmin.findPath(BACKING).getTextValue(); // Backing
fbb232e78422 create getClaimInfo
one
parents: 28
diff changeset
84 String r = toulmin.findPath(REBUTTLE).getTextValue(); // Rebuttle
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
85
16
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
86 ObjectNode t = Json.newObject();
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
87 t.put(TITLE, title);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
88 t.put(CONTENTS, contents);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
89 t.put(QUALIFIER, q);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
90 t.put(DATA, d);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
91 t.put(WARRANT, w);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
92 t.put(BACKING, b);
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
93 t.put(REBUTTLE, r);
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
94
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
95 setProperty(TYPE, type);
18
one
parents: 16
diff changeset
96 setProperty(STATUS, FAIL); // Default Status is fail.
16
7cdc9d19834f modified createClaim
one
parents: 14
diff changeset
97 setProperty(TOULMIN, t);
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 18
diff changeset
98 }
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 18
diff changeset
99
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 18
diff changeset
100 public void setClaimMention(String label) {
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 18
diff changeset
101
18
one
parents: 16
diff changeset
102
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
103 }
18
one
parents: 16
diff changeset
104
14
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
105
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
106
792fdb0c10bf add ClaimModel.java
one
parents:
diff changeset
107 }