changeset 28:7112b826a53a

modified RequestTest.java
author one
date Wed, 03 Oct 2012 12:53:37 +0900
parents e246e0dac9c8
children fbb232e78422
files app/controllers/Claim.java app/models/ClaimModel.java test/RequestTest.java
diffstat 3 files changed, 63 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/Claim.java	Wed Oct 03 04:44:45 2012 +0900
+++ b/app/controllers/Claim.java	Wed Oct 03 12:53:37 2012 +0900
@@ -7,6 +7,7 @@
 import models.TPGraph;
 
 import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.Vertex;
 
 import play.mvc.BodyParser;
 import play.mvc.Controller;
@@ -81,7 +82,19 @@
 		return created();
 	}
 	
-	private static Result checkClaimData() {
+	public static Result getClaimTree(String id) {
+		TPGraph tpGraph = TPGraph.getInstance();
+		Graph graph = tpGraph.getGraph();
+		
+		Vertex v = graph.getVertex(id);
+		if (v == null) return badRequest("Consensus id "+ id +" is not found.");
+		ClaimModel consensusRoot = new ClaimModel(v);
+		
+		
+		
+		
+		
+		
 		
 		
 		return ok();
@@ -90,6 +103,7 @@
 	
 	
 	
+	
 	private static String[] toStringArray(JsonNode jsonNode) {
 		int length = jsonNode.size();
 		if (length == 0) return null;
--- a/app/models/ClaimModel.java	Wed Oct 03 04:44:45 2012 +0900
+++ b/app/models/ClaimModel.java	Wed Oct 03 12:53:37 2012 +0900
@@ -16,6 +16,17 @@
 		super(vertex);
 	}
 	
+	public ObjectNode getClaimPropertyFromGraph() {
+		
+		ObjectNode t = Json.newObject();
+		
+		
+		
+		
+		
+		return null;
+	}
+	
 	
 	public void setClaimProperties(JsonNode toulmin, String type) {
 		String title = toulmin.findPath(NodeModel.TITLE).getTextValue();
--- a/test/RequestTest.java	Wed Oct 03 04:44:45 2012 +0900
+++ b/test/RequestTest.java	Wed Oct 03 12:53:37 2012 +0900
@@ -1,25 +1,24 @@
-import java.lang.reflect.Array;
-import java.util.ArrayList;
 import java.util.Iterator;
 
 import javax.ws.rs.core.MediaType;
 
 import models.NodeModel;
 
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.node.ArrayNode;
+import org.codehaus.jackson.node.ObjectNode;
+
+import play.libs.Json;
 
 import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientHandlerException;
 import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.UniformInterfaceException;
 import com.sun.jersey.api.client.WebResource;
 
 
 public class RequestTest {
 	final static String SERVER_ROOT_URI = "http://localhost:9000";
 
-	public static void main(String[] args) throws JSONException {
+	public static void main(String[] args) {
 		String user1 = "akifumi";
 		String user2 = "takaaki";
 		String user3 = "yosiaki";
@@ -32,19 +31,16 @@
 		createClaim(user1, users1);
 		String[] users2 = {user2};
 		createClaim(user1, users2);
-		
 
-		getUser(user1);
-		getUserInfo(user1,"consensus/");
-
-
+		JsonNode user1Claim =  getUserInfo(user1,"consensus/");
 
 		String[] users3 = {user1};
-		createMention(user2, users3, NodeModel.L_QUESTION, "5");
-		createMention(user3, users3, NodeModel.L_REFUTATION, "5");
+		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, "10");
-		createMention(user3, users3, NodeModel.L_REFUTATION, "10");
 
 		getUserInfo(user1,"requests/");
 		getUserInfo(user1,"claims/");
@@ -64,30 +60,33 @@
 
 	}
 
-	public static void createMention(String author, String[] users, String type, Object id) throws JSONException {
-		JSONObject jobj = createClaimParameter(author, users);
+	public static void createMention(String author, String[] users, String type, Object id) {
+		ObjectNode jobj = createClaimParameter(author, users);
 		final String uri = SERVER_ROOT_URI + "/claims/"+type+"/"+id+"/create";
 		WebResource resource = Client.create().resource(uri);
 		ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
 				.entity(jobj.toString())
 				.post(ClientResponse.class);
 		System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
-		System.out.println(response.getEntity(String.class));		
+		String resStr = response.getEntity(String.class);
+		System.out.println(resStr);
 	}
 	
-	public static void createClaim(String author, String[] users) throws JSONException {
-		JSONObject jobj = createClaimParameter(author, users);
+	public static JsonNode createClaim(String author, String[] users) {
+		ObjectNode jobj = createClaimParameter(author, users);
 		final String uri = SERVER_ROOT_URI + "/claims/create";
 		WebResource resource = Client.create().resource(uri);
 		ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
 				.entity(jobj.toString())
 				.post(ClientResponse.class);
 		System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
-		System.out.println(response.getEntity(String.class));		
+		String resStr = response.getEntity(String.class);
+		System.out.println(resStr);
+		return Json.toJson(resStr);
 	}
 	
-	public static JSONObject createClaimParameter(String author, String[] users) throws JSONException {
-		JSONObject toulmin = new JSONObject();
+	public static ObjectNode createClaimParameter(String author, String[] users) {
+		ObjectNode toulmin = Json.newObject();
 		toulmin.put(NodeModel.TITLE, "アプリでGraphDBを利用する。");
 		toulmin.put(NodeModel.CONTENTS, "最近話題のデータベースとしてGraphDBがある。我々のアプリでは、新しい技術のためにもGraphDBを利用したい。");
 		toulmin.put(NodeModel.QUALIFIER, "絶対");
@@ -96,21 +95,25 @@
 		toulmin.put(NodeModel.DATA,"GraphDBの実用例 etc...");
 		toulmin.put(NodeModel.REBUTTLE,"");
 
-		JSONObject jobj = new JSONObject();
+		ObjectNode jobj = Json.newObject();
 		jobj.put(NodeModel.TOULMIN, toulmin);
 		jobj.put(NodeModel.L_AUTHOR, author);
-		jobj.put(NodeModel.USERS,users);
-		jobj.put(NodeModel.TYPE, "unanimously");
+		ArrayNode usersArray = jobj.putArray(NodeModel.USERS);
+		for (String u : users) usersArray.add(u);
+
+		jobj.put(NodeModel.TYPE, NodeModel.UNANIMOUSLY);
 		return jobj;
 		
 	}
 	
-	public static void getUserInfo(String name, String preUri) throws ClientHandlerException, UniformInterfaceException, JSONException {
+	public static JsonNode getUserInfo(String name, String preUri) {
 		final String uri = SERVER_ROOT_URI + "/users/"+preUri+name;
 		WebResource resource = Client.create().resource(uri);
 		ClientResponse response = resource.get(ClientResponse.class);
 		System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus()));
-		System.out.println(response.getEntity(String.class));
+		String resStr = response.getEntity(String.class);
+		System.out.println(resStr);
+		return Json.parse(resStr);
 	}
 	
 	public static void createUser(String name) {
@@ -119,22 +122,21 @@
 		ClientResponse response = resource.put(ClientResponse.class);
 		System.out.println(String.format("PUT on [%s], status code [%d]", uri, response.getStatus()));
 		System.out.println(response.getEntity(String.class));
-		
 	}
 
-	public static void getUser(String name) throws ClientHandlerException, UniformInterfaceException, JSONException {
+	public static JsonNode getUser(String name) {
 		final String uri = SERVER_ROOT_URI + "/users/browse/"+name;
 		WebResource resource = Client.create().resource(uri);
 		ClientResponse response = resource.get(ClientResponse.class);
 		System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus()));
-		System.out.println(response.getEntity(String.class));
+		String resStr = response.getEntity(String.class);
+		return Json.parse(resStr);
 	}
 
-	
-	public static void postName() throws JSONException {
+	public static void postName() {
 		final String uri = SERVER_ROOT_URI + "/hello";
 		WebResource resource = Client.create().resource(uri);
-		JSONObject jobj = new JSONObject();
+		ObjectNode jobj = Json.newObject();
 		jobj.put("name","taro");
 //		ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
 		ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
@@ -142,9 +144,5 @@
 		.post(ClientResponse.class);
 		System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
 		System.out.println(response.getEntity(String.class));
-		
 	}
-	
-	
-	
 }