annotate app/models/NodeModel.java @ 3:d0ee9edfff28

add libs, models/NodeModel.java
author one
date Mon, 01 Oct 2012 16:39:19 +0900
parents
children cb0baf808047
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
1 package models;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
2
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
3 import java.util.HashMap;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
4 import java.util.Iterator;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
5
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
6 import org.json.JSONException;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
7 import org.json.JSONObject;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
8
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
9 import com.tinkerpop.blueprints.Vertex;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
10
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
11 public class NodeModel {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
12
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
13 private Vertex vertex;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
14 private Object id;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
15
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
16 final String ID = "id";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
17
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
18 final String TOULMIN = "toulmin";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
19 final String TITLE = "title";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
20 final String CONTENTS = "contents";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
21 final String DATA = "d";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
22 final String WARRANT = "w";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
23 final String BACKING = "b";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
24 final String REBUTTLE = "r";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
25 final String AUTHOR = "author";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
26 final String USERS = "users";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
27 final String TYPE = "type";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
28 final String MENTIONS = "mentions";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
29
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
30 final String STATUS = "status";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
31 final String PASS = "pass";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
32 final String FAIL = "fail";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
33 final String AGREED = "agreed";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
34 final String DENIED = "denied";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
35
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
36 final String QUESTION = "question";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
37 final String REFUTATION = "refutation";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
38
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
39 final String MAJORITY = "majority";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
40 final String UNANIMOUSLY = "unanimously";
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
41
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
42 JSONObject properties = new JSONObject();
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
43
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
44 public NodeModel(Vertex vertex) {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
45 this.vertex = vertex;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
46 this.id = vertex.getId();
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
47 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
48
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
49 public JSONObject getProperties() throws JSONException {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
50 for (String key: vertex.getPropertyKeys() ) {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
51 properties.put(key, vertex.getProperty(key));
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
52 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
53 return properties;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
54 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
55
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
56 public void setId(Object id) {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
57 this.id = id;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
58 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
59
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
60 public Object getId() {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
61 return this.id;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
62 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
63
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
64 public Vertex getVertex() {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
65 return this.vertex;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
66 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
67
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
68 public void setJsonProperty(String key, Object value) throws JSONException {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
69 properties.put(key, value);
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
70 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
71
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
72 public void setPropetiesFromJson(JSONObject jobj) throws JSONException {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
73 for (Iterator<String> iter=jobj.keys(); iter.hasNext();) {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
74 String key = iter.next();
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
75 this.setJsonProperty(key, jobj.get(key));
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
76 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
77 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
78
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
79 public void writeProperties() throws JSONException {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
80 for (Iterator<String> iter=properties.keys(); iter.hasNext(); ) {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
81 String key = iter.next();
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
82 vertex.setProperty(key, properties.get(key));
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
83 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
84 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
85
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
86 public JSONObject getNodeJson() throws JSONException {
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
87 JSONObject jobj = new JSONObject();
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
88 jobj.put("id",this.id);
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
89 jobj.put("data", this.properties);
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
90 return jobj;
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
91 }
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
92
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
93
d0ee9edfff28 add libs, models/NodeModel.java
one
parents:
diff changeset
94 }