changeset 34:fac4aa26ea04

fix
author one
date Wed, 03 Oct 2012 16:58:34 +0900
parents 1ca28e3eb4e9
children 5d422941b702
files app/controllers/Claim.java app/models/ClaimModel.java test/RequestTest.java
diffstat 3 files changed, 16 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/Claim.java	Wed Oct 03 16:55:16 2012 +0900
+++ b/app/controllers/Claim.java	Wed Oct 03 16:58:34 2012 +0900
@@ -16,33 +16,28 @@
 import play.mvc.Result;
 
 public class Claim extends Controller {
-
 	
 	@BodyParser.Of(BodyParser.Json.class)
 	public static Result crateClaim() {
 		JsonNode json = request().body().asJson();
 		String author = json.findPath(NodeModel.L_AUTHOR).getTextValue(); // Author
-
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
-		if ( graph.getVertex(author) == null) 
+		if ( graph.getVertex(author) == null) { 
 			return badRequest("Author "+ author + "is not exist.");
-		
+		}
 		JsonNode toulmin = json.findPath(NodeModel.TOULMIN);
-		if (toulmin.findPath(NodeModel.TITLE) == null) 
+		if (toulmin.findPath(NodeModel.TITLE) == null) { 
 			return badRequest("Please set title");
-
+		}
 		JsonNode usersJson = json.get(NodeModel.USERS); // Users (class JsonNode) 
 		String type = json.findPath(NodeModel.TYPE).getTextValue(); // Type (majority|unanimously)		
-		
 		ClaimModel newClaim = new ClaimModel(graph.addVertex(null));
 		tpGraph.setLabelToAuthor(newClaim, author);
 		newClaim.setClaimProperties(toulmin, type);
-
 		String[] users = toStringArray(usersJson);
 		tpGraph.setLabelStatusToUsers(newClaim, users, NodeModel.L_REQUEST, NodeModel.FAIL);
 		tpGraph.setLabelToRootClaim(newClaim);
-		
 		return created();
 	}
 	
@@ -57,11 +52,13 @@
 		String author = json.findPath(NodeModel.L_AUTHOR).getTextValue(); // Author
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
-		if ( graph.getVertex(author) == null) 
+		if ( graph.getVertex(author) == null) { 
 			return badRequest("Author "+ author + "is not exist.");
+		}
 		JsonNode toulmin = json.findPath(NodeModel.TOULMIN);
-		if (toulmin.findPath(NodeModel.TITLE) == null) 
+		if (toulmin.findPath(NodeModel.TITLE) == null) { 
 			return badRequest("Please set title");
+		}
 		JsonNode usersJson = json.get(NodeModel.USERS); // Users (class JsonNode) 
 		String type = json.findPath(NodeModel.TYPE).getTextValue(); // Type (majority|unanimously)		
 		ClaimModel newClaim = new ClaimModel(graph.addVertex(null));
@@ -79,7 +76,9 @@
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
 		Vertex claimV = graph.getVertex(id); 
-		if (claimV == null) badRequest("Claim id "+id+" is not found.");
+		if (claimV == null) {
+			badRequest("Claim id "+id+" is not found.");
+		}
 		ClaimModel claim = new ClaimModel(claimV);
 		ObjectNode claimInfo = claim.getSimpleClaimInfo();
 		ObjectNode result = Json.newObject();
@@ -104,7 +103,9 @@
 	
 	private static String[] toStringArray(JsonNode jsonNode) {
 		int length = jsonNode.size();
-		if (length == 0) return null;
+		if (length == 0) {
+			return null;
+		}
 		String[] userArray = new String[length];
 		for (int i=0; i<length; i++ ) {
 			userArray[i] = jsonNode.get(i).getTextValue();
--- a/app/models/ClaimModel.java	Wed Oct 03 16:55:16 2012 +0900
+++ b/app/models/ClaimModel.java	Wed Oct 03 16:58:34 2012 +0900
@@ -114,7 +114,6 @@
 		String w = toulmin.findPath(WARRANT).getTextValue(); // Warrant
 		String b = toulmin.findPath(BACKING).getTextValue(); // Backing
 		String r = toulmin.findPath(REBUTTLE).getTextValue(); // Rebuttle
-
 		ObjectNode t = Json.newObject();
 		t.put(TITLE, title);
 		t.put(CONTENTS, contents);
@@ -123,17 +122,8 @@
 		t.put(WARRANT, w);
 		t.put(BACKING, b);
 		t.put(REBUTTLE, r);
-
 		setProperty(TYPE, type);
 		setProperty(STATUS, FAIL); // Default Status is fail.
 		setProperty(TOULMIN, t);
 	}
-	
-	public void setClaimMention(String label) {
-		
-		
-	}
-
-	
-	
 }
--- a/test/RequestTest.java	Wed Oct 03 16:55:16 2012 +0900
+++ b/test/RequestTest.java	Wed Oct 03 16:58:34 2012 +0900
@@ -1,5 +1,3 @@
-import java.util.Iterator;
-
 import javax.ws.rs.core.MediaType;
 
 import models.NodeModel;
@@ -22,12 +20,9 @@
 		String user1 = "akifumi";
 		String user2 = "takaaki";
 		String user3 = "yosiaki";
-
 		createUser(user1);
 		createUser(user2);
 		createUser(user3);
-
-
 		String[] users1 = {user2,user3};
 		createClaim(user1, users1);
 		String[] users2 = {user2};
@@ -40,32 +35,20 @@
 			createMention(user3, users3, NodeModel.L_REFUTATION, claimId);
 			getClaimInfo(claimId);
 		}
-
-
-		/*		
 		getUserInfo(user1,"requests/");
 		getUserInfo(user1,"consensus/");
-		
-
 		getUserInfo(user2,"claims/");
 		getUserInfo(user2,"consensus/");
-		
 		getUserInfo(user3,"claims/");
 		getUserInfo(user3,"consensus/");
-
-*/
-
-		for (int i=0; i<user1Claim.size(); i++ ) {
+		for (int i=0; i<user1Claim.size(); i++) {
 			int id = user1Claim.get(i).asInt(); 
-//			getClaimInfo(user1Claim.get(i).asInt());
+			getClaimInfo(user1Claim.get(i).asInt());
 			getClaimTree(id); 
 			break;
 		}
-
-
 	}
 
-	
 	public static JsonNode getClaimTree(int id) {
 		final String uri = SERVER_ROOT_URI + "/consensus/browse/"+id;
 		WebResource resource = Client.create().resource(uri);
@@ -76,7 +59,6 @@
 		return Json.parse(resStr);
 	}
 	
-	
 	public static JsonNode getClaimInfo(int id) {
 		final String uri = SERVER_ROOT_URI + "/claims/browse/"+id;
 		WebResource resource = Client.create().resource(uri);