# HG changeset patch # User one # Date 1349092296 -32400 # Node ID a8ea4191fa9931f47ba7b474c1761b75ddb1be5f # Parent d050b7fb4cda137ccc08db5713ddc729d506108e modified User.java diff -r d050b7fb4cda -r a8ea4191fa99 app/controllers/User.java --- 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 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 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 hash = user.getUserClaims(); + if (hash == null) return notFound("requests not found"); return created(Json.toJson(hash)); } } diff -r d050b7fb4cda -r a8ea4191fa99 app/models/UserModel.java --- 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 getUserRequests() { - HashMap hash = new HashMap(1); - hash.put(REQUESTS, vertex.getProperty(REQUESTS)); + HashMap hash = getOneProperty(REQUESTS); + return hash; + } + + public HashMap getUserConsensus() { + HashMap hash = getOneProperty(CONSENSUS); return hash; } - + public HashMap getUserClaims() { + HashMap hash = getOneProperty(CLAIMS); + return hash; + } + + private HashMap getOneProperty(String key) { + HashMap hash = new HashMap(1); + Object obj = vertex.getProperty(key); + if (obj == null) return null; + hash.put(key,obj); + return hash; + } + diff -r d050b7fb4cda -r a8ea4191fa99 conf/routes --- 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