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