changeset 31:995be14b30a2

create ClaimModel/getUsersIdAndStatus method
author one
date Wed, 03 Oct 2012 15:16:56 +0900
parents 80b5628f17d8
children be6bbd4967e4
files app/controllers/Claim.java app/models/ClaimModel.java conf/routes logs/application.log target/scala-2.9.1/cache/compile/compile test/RequestTest.java
diffstat 6 files changed, 158 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/Claim.java	Wed Oct 03 14:27:44 2012 +0900
+++ b/app/controllers/Claim.java	Wed Oct 03 15:16:56 2012 +0900
@@ -90,7 +90,7 @@
 		Vertex claimV = graph.getVertex(id); 
 		if (claimV == null) badRequest("Claim id "+id+" is not found.");
 		ClaimModel claim = new ClaimModel(claimV);
-		ObjectNode claimInfo = claim.getClaimInfoFromGraph();
+		ObjectNode claimInfo = claim.getSimpleClaimInfo();
 		ObjectNode result = Json.newObject();
 		result.put("status", "OK");
 		result.put("message", claimInfo.toString());
@@ -104,15 +104,13 @@
 		Vertex v = graph.getVertex(id);
 		if (v == null) return badRequest("Consensus id "+ id +" is not found.");
 		ClaimModel consensusRoot = new ClaimModel(v);
-		ObjectNode consensusObj = consensusRoot.getClaimInfoFromGraph();
-		
-		JsonNode jobj = consensusObj.findValue(NodeModel.TOULMIN);
+		ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse();
+
+		ObjectNode mentions = consensusRoot.getClaimMentions();
+		resultEntity.put(NodeModel.MENTIONS, Json.toJson(mentions));
 		
 		
-		
-		ObjectNode result = Json.newObject();
-		result.put("message",jobj.toString());
-		return ok(result);
+		return ok(resultEntity);
 	}
 	
 	
--- a/app/models/ClaimModel.java	Wed Oct 03 14:27:44 2012 +0900
+++ b/app/models/ClaimModel.java	Wed Oct 03 15:16:56 2012 +0900
@@ -7,6 +7,7 @@
 
 import play.libs.Json;
 
+import com.tinkerpop.blueprints.Edge;
 import com.tinkerpop.blueprints.Vertex;
 import com.tinkerpop.gremlin.java.GremlinPipeline;
 
@@ -17,22 +18,36 @@
 		super(vertex);
 	}
 	
-	public ObjectNode getClaimInfoFromGraph() {
+	public ObjectNode getSimpleClaimInfo() {
 		ObjectNode property = Json.newObject();
 		property.put(TYPE, Json.toJson(getProperty(TYPE)));
 		property.put(STATUS, Json.toJson(getProperty(STATUS)));
 		property.put(TOULMIN, Json.toJson(getProperty(TOULMIN)));
-		
 		property.put(L_AUTHOR, Json.toJson(getAuthorId()));
 		property.put(MENTIONS, Json.toJson(getMentionsId()));
-		property.put(USERS, Json.toJson(getUsers()));
+		property.put(USERS, Json.toJson(getUsersId()));
 		return property;
 	}
 	
-	public JsonNode getClaimMentions() {
-		
-		
-		
+	public ObjectNode getClaimInfoTraverse() {
+		ObjectNode property = Json.newObject();
+		property.put(TYPE, Json.toJson(getProperty(TYPE)));
+		property.put(STATUS, Json.toJson(getProperty(STATUS)));
+		property.put(TOULMIN, Json.toJson(getProperty(TOULMIN)));
+		property.put(L_AUTHOR, Json.toJson(getAuthorId()));
+		property.put(MENTIONS, Json.toJson(getMentionsId()));
+		property.put(USERS, Json.toJson(getUsersIdAndStatus()));
+		return property;
+	}
+	
+	public ObjectNode getClaimMentions() {
+		GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex,Edge>();
+		pipe.start(vertex).outE(L_QUESTION,L_REFUTATION,L_SUGGESTION);		
+		for (Edge e:pipe) {
+			String label = e.getLabel();
+			
+			
+		}
 		return null;
 	}
 	
@@ -54,9 +69,25 @@
 		return getInfoArray(L_QUESTION,L_REFUTATION,L_SUGGESTION);
 	}
 	
-	public Object[] getUsers() {
+	public Object[] getUsersId() {
 		return getInfoArray(L_REQUEST);
 	}
+	
+	public Object[] getUsersIdAndStatus() {
+		GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();		
+		pipeEdge.start(vertex).outE(L_REQUEST);
+		ArrayList<Object> array = new ArrayList<Object>();
+		for (Edge e : pipeEdge) {
+			GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>();		
+			ObjectNode info = Json.newObject();
+			pipeChildVertex.start(e).outV();
+			Vertex childVertex = pipeChildVertex.next();
+			info.put(ID, Json.toJson(childVertex.getId()));
+			info.put(STATUS, Json.toJson(e.getProperty(STATUS)));
+			array.add(info);
+		}
+		return array.toArray();
+	}
 
 
 	public Object[] getRequestUsersId() {
--- a/conf/routes	Wed Oct 03 14:27:44 2012 +0900
+++ b/conf/routes	Wed Oct 03 15:16:56 2012 +0900
@@ -8,12 +8,12 @@
 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)
+GET		/users/claims/:name			controllers.User.getUserClaims(name: String)
 
-GET		/claims/browse/:id		controllers.Claim.getClaimInfo(id: String)
+GET		/claims/browse/:id			controllers.Claim.getClaimInfo(id: String)
 GET		/claims/consensus/:id		controllers.Claim.getClaimTree(id: String)
 
-POST	/claims/create			controllers.Claim.crateClaim()
+POST	/claims/create				controllers.Claim.crateClaim()
 POST	/claims/:mentionType/:id/create			controllers.Claim.createMention(mentionType: String ,id: String)
 
 
--- a/logs/application.log	Wed Oct 03 14:27:44 2012 +0900
+++ b/logs/application.log	Wed Oct 03 15:16:56 2012 +0900
@@ -1,6 +1,106 @@
-2012-10-03 13:27:42,762 - [INFO] - from play in main 
+2012-10-03 15:05:55,385 - [INFO] - from play in main 
 Listening for HTTP on port 9000...
 
-2012-10-03 13:27:47,831 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
+2012-10-03 15:06:03,213 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
+Application started (Dev)
+
+2012-10-03 15:06:05,058 - [ERROR] - from application in play-akka.actor.actions-dispatcher-4 
+
+
+! @6bphfi9bo - Internal server error, for request [GET /claims/browse/10] ->
+
+play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[ClassCastException: com.tinkerpop.blueprints.impls.tg.TinkerVertex cannot be cast to com.tinkerpop.blueprints.Edge]]
+	at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.3]
+	at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.3]
+	at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
+	at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.3]
+	at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
+	at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
+	at akka.dispatch.Mailbox.run(Mailbox.scala:179) [akka-actor.jar:2.0.2]
+	at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516) [akka-actor.jar:2.0.2]
+	at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor.jar:2.0.2]
+	at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor.jar:2.0.2]
+	at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) [akka-actor.jar:2.0.2]
+	at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) [akka-actor.jar:2.0.2]
+Caused by: java.lang.ClassCastException: com.tinkerpop.blueprints.impls.tg.TinkerVertex cannot be cast to com.tinkerpop.blueprints.Edge
+	at models.ClaimModel.getUsersIdAndStatus(ClaimModel.java:81) ~[classes/:na]
+	at models.ClaimModel.getClaimInfoTraverse(ClaimModel.java:39) ~[classes/:na]
+	at controllers.Claim.getClaimInfo(Claim.java:94) ~[classes/:na]
+	at Routes$$anonfun$routes$1$$anonfun$apply$13$$anonfun$apply$14.apply(routes_routing.scala:124) ~[classes/:na]
+	at Routes$$anonfun$routes$1$$anonfun$apply$13$$anonfun$apply$14.apply(routes_routing.scala:124) ~[classes/:na]
+	at play.core.Router$HandlerInvoker$$anon$4$$anon$1.invocation(Router.scala:1086) ~[play_2.9.1.jar:2.0.3]
+	at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:33) ~[play_2.9.1.jar:2.0.3]
+	at play.GlobalSettings$1.call(GlobalSettings.java:57) ~[play_2.9.1.jar:2.0.3]
+	at play.core.j.JavaAction$class.apply(JavaAction.scala:74) ~[play_2.9.1.jar:2.0.3]
+	at play.core.Router$HandlerInvoker$$anon$4$$anon$1.apply(Router.scala:1085) ~[play_2.9.1.jar:2.0.3]
+	at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126) ~[play_2.9.1.jar:2.0.3]
+	at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126) ~[play_2.9.1.jar:2.0.3]
+	at play.utils.Threads$.withContextClassLoader(Threads.scala:17) ~[play_2.9.1.jar:2.0.3]
+	at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:125) [play_2.9.1.jar:2.0.3]
+	... 11 common frames omitted
+
+2012-10-03 15:10:08,007 - [INFO] - from application in play-akka.actor.default-dispatcher-2 
+Application shutdown...
+
+2012-10-03 15:10:08,024 - [INFO] - from play in play-akka.actor.default-dispatcher-2 
+Application started (Dev)
+
+2012-10-03 15:11:18,369 - [INFO] - from application in play-akka.actor.default-dispatcher-2 
+Application shutdown...
+
+2012-10-03 15:11:18,384 - [INFO] - from play in play-akka.actor.default-dispatcher-2 
 Application started (Dev)
 
+2012-10-03 15:11:19,607 - [ERROR] - from application in play-akka.actor.actions-dispatcher-8 
+
+
+! @6bphfi9bp - Internal server error, for request [GET /claims/browse/10] ->
+
+play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[ClassCastException: com.tinkerpop.blueprints.impls.tg.TinkerVertex cannot be cast to com.tinkerpop.blueprints.Edge]]
+	at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.3]
+	at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.3]
+	at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
+	at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.3]
+	at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
+	at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
+	at akka.dispatch.Mailbox.run(Mailbox.scala:179) [akka-actor.jar:2.0.2]
+	at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516) [akka-actor.jar:2.0.2]
+	at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor.jar:2.0.2]
+	at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor.jar:2.0.2]
+	at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) [akka-actor.jar:2.0.2]
+	at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) [akka-actor.jar:2.0.2]
+Caused by: java.lang.ClassCastException: com.tinkerpop.blueprints.impls.tg.TinkerVertex cannot be cast to com.tinkerpop.blueprints.Edge
+	at models.ClaimModel.getUsersIdAndStatus(ClaimModel.java:81) ~[classes/:na]
+	at models.ClaimModel.getClaimInfoTraverse(ClaimModel.java:39) ~[classes/:na]
+	at controllers.Claim.getClaimInfo(Claim.java:94) ~[classes/:na]
+	at Routes$$anonfun$routes$1$$anonfun$apply$13$$anonfun$apply$14.apply(routes_routing.scala:124) ~[classes/:na]
+	at Routes$$anonfun$routes$1$$anonfun$apply$13$$anonfun$apply$14.apply(routes_routing.scala:124) ~[classes/:na]
+	at play.core.Router$HandlerInvoker$$anon$4$$anon$1.invocation(Router.scala:1086) ~[play_2.9.1.jar:2.0.3]
+	at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:33) ~[play_2.9.1.jar:2.0.3]
+	at play.GlobalSettings$1.call(GlobalSettings.java:57) ~[play_2.9.1.jar:2.0.3]
+	at play.core.j.JavaAction$class.apply(JavaAction.scala:74) ~[play_2.9.1.jar:2.0.3]
+	at play.core.Router$HandlerInvoker$$anon$4$$anon$1.apply(Router.scala:1085) ~[play_2.9.1.jar:2.0.3]
+	at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126) ~[play_2.9.1.jar:2.0.3]
+	at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126) ~[play_2.9.1.jar:2.0.3]
+	at play.utils.Threads$.withContextClassLoader(Threads.scala:17) ~[play_2.9.1.jar:2.0.3]
+	at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:125) [play_2.9.1.jar:2.0.3]
+	... 11 common frames omitted
+
+2012-10-03 15:14:14,692 - [INFO] - from application in play-akka.actor.default-dispatcher-2 
+Application shutdown...
+
+2012-10-03 15:14:14,708 - [INFO] - from play in play-akka.actor.default-dispatcher-2 
+Application started (Dev)
+
+2012-10-03 15:14:48,014 - [INFO] - from application in play-akka.actor.default-dispatcher-2 
+Application shutdown...
+
+2012-10-03 15:14:48,029 - [INFO] - from play in play-akka.actor.default-dispatcher-2 
+Application started (Dev)
+
+2012-10-03 15:16:13,238 - [INFO] - from application in play-akka.actor.default-dispatcher-2 
+Application shutdown...
+
+2012-10-03 15:16:13,253 - [INFO] - from play in play-akka.actor.default-dispatcher-2 
+Application started (Dev)
+
Binary file target/scala-2.9.1/cache/compile/compile has changed
--- a/test/RequestTest.java	Wed Oct 03 14:27:44 2012 +0900
+++ b/test/RequestTest.java	Wed Oct 03 15:16:56 2012 +0900
@@ -27,6 +27,7 @@
 		createUser(user2);
 		createUser(user3);
 
+
 		String[] users1 = {user2,user3};
 		createClaim(user1, users1);
 		String[] users2 = {user2};
@@ -35,13 +36,16 @@
 		String[] users3 = {user1};
 		for (int i=0; i<user1Claim.size(); i++) {
 			int claimId = user1Claim.get(i).asInt();
-			createMention(user2, users3, NodeModel.L_QUESTION, claimId);
-			createMention(user3, users3, NodeModel.L_REFUTATION, claimId);
+//			createMention(user2, users3, NodeModel.L_QUESTION, claimId);
+//			createMention(user3, users3, NodeModel.L_REFUTATION, claimId);
+			getClaimInfo(claimId);
 		}
 
+
+		/*		
 		getUserInfo(user1,"requests/");
-		getUserInfo(user1,"claims/");
 		getUserInfo(user1,"consensus/");
+		
 
 		getUserInfo(user2,"claims/");
 		getUserInfo(user2,"consensus/");
@@ -55,9 +59,9 @@
 //			getClaimInfo(user1Claim.get(i).asInt());
 			getClaimTree(id); 
 		}
+		*/
 
 	}
-
 	public static JsonNode getClaimTree(int id) {
 		final String uri = SERVER_ROOT_URI + "/claims/consensus/"+id;
 		WebResource resource = Client.create().resource(uri);