# HG changeset patch # User one # Date 1349285717 -32400 # Node ID f784427778498041b2c7750cd91d121330c1dfee # Parent 1d5c086e069b7bf29ed9c3277028ebec87510f96 create updateRequestStatus diff -r 1d5c086e069b -r f78442777849 app/controllers/Claim.java --- a/app/controllers/Claim.java Thu Oct 04 01:59:21 2012 +0900 +++ b/app/controllers/Claim.java Thu Oct 04 02:35:17 2012 +0900 @@ -25,7 +25,7 @@ TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); if ( graph.getVertex(author) == null) { - return badRequest("Author "+ author + "is not exist."); + return badRequest("Author "+ author + "does not exist."); } JsonNode toulmin = json.findPath(NodeModel.TOULMIN); if (toulmin.findPath(NodeModel.TITLE) == null) { @@ -53,13 +53,13 @@ Graph graph = tpGraph.getGraph(); ClaimModel claim = new ClaimModel(graph.getVertex(id)); if ( claim.getVertex() == null ) { - return badRequest("Claim id "+ id + "does not exist."); + return badRequest("Claim id "+ id + " does not exist."); } if ( !claim.getAuthorId().equals(author)) { return badRequest("Wrong Author."); } if ( graph.getVertex(author) == null) { - return badRequest("Author "+ author + "is not exist."); + return badRequest("Author "+ author + " does not exist."); } JsonNode toulmin = json.findPath(NodeModel.TOULMIN); if (toulmin.findPath(NodeModel.TITLE) == null) { @@ -92,6 +92,26 @@ return ok(result); } + public static Result updateUserConsensusStatus(String id, String name, String status) { + if ( !(status.equals(NodeModel.AGREED) + ||status.equals(NodeModel.FAILED) + ||status.equals(NodeModel.UNKNOWN) + ||status.equals(NodeModel.PEND))) { + return badRequest("Wrong status type."); + } + 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"); + } + claim.updateUserRequestStatus(claim, user, status); + return created(); + } @BodyParser.Of(BodyParser.Json.class) public static Result createMention(String mentionType, String id) { @@ -105,7 +125,7 @@ TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); if ( graph.getVertex(author) == null) { - return badRequest("Author "+ author + "is not exist."); + return badRequest("Author "+ author + " does not exist."); } JsonNode toulmin = json.findPath(NodeModel.TOULMIN); if (toulmin.findPath(NodeModel.TITLE) == null) { @@ -132,7 +152,7 @@ Graph graph = tpGraph.getGraph(); Vertex claimV = graph.getVertex(id); if (claimV == null) { - badRequest("Claim id "+id+" is not exist."); + badRequest("Claim id "+id+" does not exist."); } ClaimModel claim = new ClaimModel(claimV); ObjectNode claimInfo = claim.getSimpleClaimInfo(); @@ -146,7 +166,7 @@ Graph graph = tpGraph.getGraph(); Vertex v = graph.getVertex(id); if (v == null) { - return badRequest("Consensus id "+ id +" is not exist."); + return badRequest("Consensus id "+ id +" does not exist."); } ClaimModel consensusRoot = new ClaimModel(v); ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse(); diff -r 1d5c086e069b -r f78442777849 app/models/ClaimModel.java --- a/app/models/ClaimModel.java Thu Oct 04 01:59:21 2012 +0900 +++ b/app/models/ClaimModel.java Thu Oct 04 02:35:17 2012 +0900 @@ -94,6 +94,22 @@ return info; } + + public Boolean updateUserRequestStatus(ClaimModel claim, UserModel user, String status) { + GremlinPipeline pipeEdge = new GremlinPipeline(); + pipeEdge.start(vertex).outE(L_REQUEST); + for (Edge e : pipeEdge) { + GremlinPipeline pipeChildVertex = new GremlinPipeline(); + pipeChildVertex.start(e).inV(); + Vertex childVertex = pipeChildVertex.next(); + if (childVertex.getId() == user.getId()) { + e.setProperty(STATUS, status); + break; + } + } + return true; + } + public Object[] getUsersIdAndStatus() { GremlinPipeline pipeEdge = new GremlinPipeline(); pipeEdge.start(vertex).outE(L_REQUEST); diff -r 1d5c086e069b -r f78442777849 app/models/NodeModel.java --- a/app/models/NodeModel.java Thu Oct 04 01:59:21 2012 +0900 +++ b/app/models/NodeModel.java Thu Oct 04 02:35:17 2012 +0900 @@ -49,6 +49,7 @@ public static final String AGREED = "agreed"; public static final String DENIED = "denied"; public static final String UNKNOWN = "unknown"; + public static final String PEND = "pend"; // Use This key Json Data public static final String CLAIM = "claim"; diff -r 1d5c086e069b -r f78442777849 app/models/UserModel.java --- a/app/models/UserModel.java Thu Oct 04 01:59:21 2012 +0900 +++ b/app/models/UserModel.java Thu Oct 04 02:35:17 2012 +0900 @@ -49,12 +49,6 @@ return set; } - /* - public Object[] getUserConsensus() { - return null; - } - */ - public HashMap getUserInfo() { TPGraph tpGraph = TPGraph.getInstance(); Object[] requests = getUserRequests(); @@ -67,6 +61,4 @@ return hash; } - - } diff -r 1d5c086e069b -r f78442777849 conf/routes --- a/conf/routes Thu Oct 04 01:59:21 2012 +0900 +++ b/conf/routes Thu Oct 04 02:35:17 2012 +0900 @@ -14,8 +14,7 @@ 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/answer/:id/:name/:status controllers.Claim.updateUserConsensusStatus(id: String, name: String, status: 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) diff -r 1d5c086e069b -r f78442777849 target/scala-2.9.1/cache/compile/compile Binary file target/scala-2.9.1/cache/compile/compile has changed diff -r 1d5c086e069b -r f78442777849 test/RequestTest.java --- a/test/RequestTest.java Thu Oct 04 01:59:21 2012 +0900 +++ b/test/RequestTest.java Thu Oct 04 02:35:17 2012 +0900 @@ -46,28 +46,22 @@ String[] users = {user2}; createMention(user1, users, NodeModel.L_SUGGESTION, claimId); } - getUserInfo(user1,"requests/"); getUserInfo(user1,"claims/"); getUserInfo(user1,"consensus/"); - getUserInfo(user2,"requests/"); getUserInfo(user2,"claims/"); getUserInfo(user2,"consensus/"); - getUserInfo(user3,"claims/"); getUserInfo(user3,"consensus/"); - for (int i=0; i