changeset 10:a8ea4191fa99

modified User.java
author one
date Mon, 01 Oct 2012 20:51:36 +0900
parents d050b7fb4cda
children 6aa0452a7f9f
files app/controllers/User.java app/models/UserModel.java conf/routes
diffstat 3 files changed, 55 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/User.java	Mon Oct 01 20:23:19 2012 +0900
+++ b/app/controllers/User.java	Mon Oct 01 20:51:36 2012 +0900
@@ -52,10 +52,39 @@
 		Graph graph = tpGraph.getGraph();
 		Vertex v = graph.getVertex(name);
 		if (v == null) {
-			return notFound();
+			return notFound("user: "+name+" not found");
 		} else {
 			UserModel user = new UserModel(v);
 			HashMap<Object,Object> hash = user.getUserRequests();
+			if (hash == null) return notFound("requests not found");
+			return created(Json.toJson(hash));
+		}		
+	}
+	
+	public static Result getUserConsensus(String name) {
+		TPGraph tpGraph = TPGraph.getInstance();
+		Graph graph = tpGraph.getGraph();
+		Vertex v = graph.getVertex(name);
+		if (v == null) {
+			return notFound("user: "+name+" not found");
+		} else {
+			UserModel user = new UserModel(v);
+			HashMap<Object,Object> hash = user.getUserConsensus();
+			if (hash == null) return notFound("requests not found");
+			return created(Json.toJson(hash));
+		}		
+	}
+	
+	public static Result getUserClaims(String name) {
+		TPGraph tpGraph = TPGraph.getInstance();
+		Graph graph = tpGraph.getGraph();
+		Vertex v = graph.getVertex(name);
+		if (v == null) {
+			return notFound("user: "+name+" not found");
+		} else {
+			UserModel user = new UserModel(v);
+			HashMap<Object,Object> hash = user.getUserClaims();
+			if (hash == null) return notFound("requests not found");
 			return created(Json.toJson(hash));
 		}		
 	}
--- a/app/models/UserModel.java	Mon Oct 01 20:23:19 2012 +0900
+++ b/app/models/UserModel.java	Mon Oct 01 20:51:36 2012 +0900
@@ -18,9 +18,9 @@
 	
 
 	public void setUserInfo() {
-		this.vertex.setProperty(CONSENSUS, "");
-		this.vertex.setProperty(CLAIMS, "");
-		this.vertex.setProperty(REQUESTS, "");
+		this.vertex.setProperty(CONSENSUS, null);
+		this.vertex.setProperty(CLAIMS, null);
+		this.vertex.setProperty(REQUESTS, null);
 	}
 	
 
@@ -32,12 +32,28 @@
 	}
 
 	public HashMap<Object, Object> getUserRequests() {
-		HashMap<Object, Object> hash = new HashMap<Object,Object>(1);
-		hash.put(REQUESTS, vertex.getProperty(REQUESTS));
+		HashMap<Object, Object> hash = getOneProperty(REQUESTS);
+		return hash;
+	}
+	
+	public HashMap<Object, Object> getUserConsensus() {
+		HashMap<Object, Object> hash = getOneProperty(CONSENSUS);
 		return hash;
 	}
 	
-	
+	public HashMap<Object, Object> getUserClaims() {
+		HashMap<Object, Object> hash = getOneProperty(CLAIMS);
+		return hash;
+	}
+
+	private HashMap<Object,Object> getOneProperty(String key) {
+		HashMap<Object, Object> hash = new HashMap<Object,Object>(1);
+		Object obj = vertex.getProperty(key);
+		if (obj == null) return null;
+		hash.put(key,obj);
+		return hash;
+	}
+
 	
 	
 	
--- a/conf/routes	Mon Oct 01 20:23:19 2012 +0900
+++ b/conf/routes	Mon Oct 01 20:51:36 2012 +0900
@@ -7,6 +7,9 @@
 PUT		/users/create/:name			controllers.User.create(name: String)
 GET		/users/browse/:name			controllers.User.getUser(name: String)
 GET		/users/requests/:name		controllers.User.getUserRequests(name: String)
+GET		/users/consensus/:name		controllers.User.getUserConsensus(name: String)
+GET		/users/claims/:name		controllers.User.getUserClaims(name: String)
+
 
 
 # test action