changeset 41:f78442777849

create updateRequestStatus
author one
date Thu, 04 Oct 2012 02:35:17 +0900
parents 1d5c086e069b
children 4321d97da830
files app/controllers/Claim.java app/models/ClaimModel.java app/models/NodeModel.java app/models/UserModel.java conf/routes target/scala-2.9.1/cache/compile/compile test/RequestTest.java
diffstat 7 files changed, 54 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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();
--- 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<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();		
+		pipeEdge.start(vertex).outE(L_REQUEST);
+		for (Edge e : pipeEdge) {
+			GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>();		
+			pipeChildVertex.start(e).inV();
+			Vertex childVertex = pipeChildVertex.next();
+			if (childVertex.getId() == user.getId()) {
+				e.setProperty(STATUS, status);
+				break;
+			}
+		}		
+		return true;
+	}
+	
 	public Object[] getUsersIdAndStatus() {
 		GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();		
 		pipeEdge.start(vertex).outE(L_REQUEST);
--- 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";
--- 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<Object,Object[]> getUserInfo() {
 		TPGraph tpGraph = TPGraph.getInstance();
 		Object[] requests = getUserRequests();
@@ -67,6 +61,4 @@
 		return hash;
 	}
 
-		
-	
 }
--- 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)
Binary file target/scala-2.9.1/cache/compile/compile has changed
--- 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<user1Claim.size(); i++) {
 			int id = user1Claim.get(i).asInt();
 			getClaimTree(id); 
 			getUserConsensusStatus(id, user2);
+			updateUserConsensusStatus(id, user2, NodeModel.AGREED);
 		}
-		
 	}
 	
-	
-	
 	public static JsonNode editClaimInfo(String author, String[] users, int id) {
 		ObjectNode jobj =  createEditClaimParameter(author,users);
 		final String uri = SERVER_ROOT_URI + "/claims/edit/"+id;
@@ -90,6 +84,15 @@
 		System.out.println(resStr);
 		return Json.parse(resStr);
 	}
+
+	public static void updateUserConsensusStatus(int id, String name, String status) {
+		final String uri = SERVER_ROOT_URI + "/claims/answer/"+id+"/"+name+"/"+status;
+		WebResource resource = Client.create().resource(uri);
+		ClientResponse response = resource.post(ClientResponse.class);
+		System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
+		String resStr = response.getEntity(String.class);
+		System.out.println(resStr);
+	}
 	
 	public static JsonNode getUserConsensusStatus(int id, String name) {
 		final String uri = SERVER_ROOT_URI + "/claims/answer/"+id+"/"+name;