# HG changeset patch # User one # Date 1349282384 -32400 # Node ID 870553e92e3ef6e853502db19e8dc43a8d13837c # Parent a2abe67d7c7aac1c59658df2a31b92adc5a2540c create getUserConsensusStatus action diff -r a2abe67d7c7a -r 870553e92e3e app/controllers/Claim.java --- a/app/controllers/Claim.java Thu Oct 04 01:05:19 2012 +0900 +++ b/app/controllers/Claim.java Thu Oct 04 01:39:44 2012 +0900 @@ -6,6 +6,7 @@ import models.ClaimModel; import models.NodeModel; import models.TPGraph; +import models.UserModel; import com.tinkerpop.blueprints.Graph; import com.tinkerpop.blueprints.Vertex; @@ -76,6 +77,21 @@ return created(); } + public static Result getUserConsensusStatus(String id, String name) { + TPGraph tpGraph = TPGraph.getInstance(); + Graph graph = tpGraph.getGraph(); + ClaimModel claim = new ClaimModel(graph.getVertex(id)); + if (claim.getVertex() == null) { + return badRequest("Claim id "+id+" does not exist"); + } + UserModel user = new UserModel(graph.getVertex(name)); + if (user.getVertex() == null) { + return badRequest("User "+name+" does not exist"); + } + ObjectNode result = claim.getUserRequestStatus(user); + return ok(result); + } + @BodyParser.Of(BodyParser.Json.class) public static Result createMention(String mentionType, String id) { @@ -116,7 +132,7 @@ Graph graph = tpGraph.getGraph(); Vertex claimV = graph.getVertex(id); if (claimV == null) { - badRequest("Claim id "+id+" is not found."); + badRequest("Claim id "+id+" is not exist."); } ClaimModel claim = new ClaimModel(claimV); ObjectNode claimInfo = claim.getSimpleClaimInfo(); @@ -130,7 +146,7 @@ Graph graph = tpGraph.getGraph(); Vertex v = graph.getVertex(id); if (v == null) { - return badRequest("Consensus id "+ id +" is not found."); + return badRequest("Consensus id "+ id +" is not exist."); } ClaimModel consensusRoot = new ClaimModel(v); ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse(); diff -r a2abe67d7c7a -r 870553e92e3e app/models/ClaimModel.java --- a/app/models/ClaimModel.java Thu Oct 04 01:05:19 2012 +0900 +++ b/app/models/ClaimModel.java Thu Oct 04 01:39:44 2012 +0900 @@ -78,6 +78,22 @@ return getInfoArray(L_REQUEST); } + public ObjectNode getUserRequestStatus(UserModel user) { + GremlinPipeline pipeEdge = new GremlinPipeline(); + pipeEdge.start(vertex).outE(L_REQUEST); + ObjectNode info = Json.newObject(); + for (Edge e : pipeEdge) { + GremlinPipeline pipeChildVertex = new GremlinPipeline(); + pipeChildVertex.start(e).inV(); + Vertex childVertex = pipeChildVertex.next(); + if (childVertex.getId() == user.getId()) { + info.put(STATUS, Json.toJson(e.getProperty(STATUS))); + break; + } + } + return info; + } + public Object[] getUsersIdAndStatus() { GremlinPipeline pipeEdge = new GremlinPipeline(); pipeEdge.start(vertex).outE(L_REQUEST); diff -r a2abe67d7c7a -r 870553e92e3e conf/routes --- a/conf/routes Thu Oct 04 01:05:19 2012 +0900 +++ b/conf/routes Thu Oct 04 01:39:44 2012 +0900 @@ -9,14 +9,14 @@ 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) - GET /claims/browse/:id controllers.Claim.getClaimInfo(id: String) GET /claims/consensus/:id controllers.Claim.getClaimTree(id: String) +GET /consensus/browse/:id controllers.Claim.getClaimTree(id: String) +GET /claims/answer/:id/:name controllers.Claim.getUserConsensusStatus(id: String, name: String) POST /claims/create controllers.Claim.crateClaim() POST /claims/:mentionType/:id/create controllers.Claim.createMention(mentionType: String ,id: String) POST /claims/edit/:id controllers.Claim.editClaim(id: String) -GET /consensus/browse/:id controllers.Claim.getClaimTree(id: String) # test action diff -r a2abe67d7c7a -r 870553e92e3e target/scala-2.9.1/cache/compile/compile Binary file target/scala-2.9.1/cache/compile/compile has changed diff -r a2abe67d7c7a -r 870553e92e3e test/RequestTest.java --- a/test/RequestTest.java Thu Oct 04 01:05:19 2012 +0900 +++ b/test/RequestTest.java Thu Oct 04 01:39:44 2012 +0900 @@ -39,29 +39,34 @@ createMention(user2, users3, NodeModel.L_QUESTION, claimId); createMention(user3, users3, NodeModel.L_REFUTATION, claimId); } - JsonNode user2Claim = getUserInfo(user2,"claims/"); + JsonNode user2Claim = getUserInfo(user2,"claims/"); for (int i=0; i