Mercurial > hg > Members > nobuyasu > Consensus
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/models/NodeModel.java Mon Oct 01 16:39:19 2012 +0900 @@ -0,0 +1,94 @@ +package models; + +import java.util.HashMap; +import java.util.Iterator; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.tinkerpop.blueprints.Vertex; + +public class NodeModel { + + private Vertex vertex; + private Object id; + + final String ID = "id"; + + final String TOULMIN = "toulmin"; + final String TITLE = "title"; + final String CONTENTS = "contents"; + final String DATA = "d"; + final String WARRANT = "w"; + final String BACKING = "b"; + final String REBUTTLE = "r"; + final String AUTHOR = "author"; + final String USERS = "users"; + final String TYPE = "type"; + final String MENTIONS = "mentions"; + + final String STATUS = "status"; + final String PASS = "pass"; + final String FAIL = "fail"; + final String AGREED = "agreed"; + final String DENIED = "denied"; + + final String QUESTION = "question"; + final String REFUTATION = "refutation"; + + final String MAJORITY = "majority"; + final String UNANIMOUSLY = "unanimously"; + + JSONObject properties = new JSONObject(); + + public NodeModel(Vertex vertex) { + this.vertex = vertex; + this.id = vertex.getId(); + } + + public JSONObject getProperties() throws JSONException { + for (String key: vertex.getPropertyKeys() ) { + properties.put(key, vertex.getProperty(key)); + } + return properties; + } + + public void setId(Object id) { + this.id = id; + } + + public Object getId() { + return this.id; + } + + public Vertex getVertex() { + return this.vertex; + } + + public void setJsonProperty(String key, Object value) throws JSONException { + properties.put(key, value); + } + + public void setPropetiesFromJson(JSONObject jobj) throws JSONException { + for (Iterator<String> iter=jobj.keys(); iter.hasNext();) { + String key = iter.next(); + this.setJsonProperty(key, jobj.get(key)); + } + } + + public void writeProperties() throws JSONException { + for (Iterator<String> iter=properties.keys(); iter.hasNext(); ) { + String key = iter.next(); + vertex.setProperty(key, properties.get(key)); + } + } + + public JSONObject getNodeJson() throws JSONException { + JSONObject jobj = new JSONObject(); + jobj.put("id",this.id); + jobj.put("data", this.properties); + return jobj; + } + + +}