diff app/controllers/Claim.java @ 13:9b677755cb93

create action Claim/createClaim
author one
date Tue, 02 Oct 2012 11:39:39 +0900
parents ef434ebd64ae
children 7cdc9d19834f
line wrap: on
line diff
--- a/app/controllers/Claim.java	Tue Oct 02 10:38:08 2012 +0900
+++ b/app/controllers/Claim.java	Tue Oct 02 11:39:39 2012 +0900
@@ -1,14 +1,62 @@
 package controllers;
 
+import java.util.HashMap;
+
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.node.ObjectNode;
+
+import models.ClaimModel;
+import models.NodeModel;
+import models.TPGraph;
+import models.UserModel;
+
+import com.tinkerpop.blueprints.Graph;
+import com.tinkerpop.blueprints.Vertex;
+
+import play.libs.Json;
+import play.mvc.BodyParser;
 import play.mvc.Controller;
+import play.mvc.Result;
 
 public class Claim extends Controller {
 
 	
-	
-	public static void crateClaim() {
+	@BodyParser.Of(BodyParser.Json.class)
+	public static Result crateClaim() {
+		JsonNode json = request().body().asJson();
+		ObjectNode result = Json.newObject();
+		String title = json.findPath("title").getTextValue();
+		if (title == null) {
+			result.put("status", "KO");
+			result.put("message", "Please set title");
+			return badRequest(result);
+		} 
+		String contents = json.findPath("contents").getTextValue();
+		String author = json.findPath(NodeModel.AUTHOR).getTextValue(); // Author
+		String q = json.findPath(NodeModel.QUALIFIER).getTextValue(); // Qualifier
+		String d = json.findPath(NodeModel.DATA).getTextValue(); // Data
+		String w = json.findPath(NodeModel.WARRANT).getTextValue(); // Warrant
+		String b = json.findPath(NodeModel.BACKING).getTextValue(); // Backing
+		String r = json.findPath(NodeModel.REBUTTLE).getTextValue(); // Rebuttle
+		String users = json.get(NodeModel.USERS).toString(); // Users
+		String type = json.findPath(NodeModel.TYPE).getTextValue(); // Type (majority|unanimously)		
 		
+		TPGraph tpGraph = TPGraph.getInstance();
+		Graph graph = tpGraph.getGraph();
+		Vertex v = null;
+		v = graph.addVertex(null);
+		ClaimModel newClaim = new ClaimModel(v);
+		newClaim.setClaimProperties(author, title, contents, q, d, w, b, r, users, type);
+		tpGraph.setLabelToRootClaim(newClaim);
+//		newUser.setName(name); // user node hasn't name property(only TinkerGraph).
+
+		HashMap<Object, Object> property = newClaim.getAllProperty();
+		for (Object key: property.keySet()) {
+			System.out.println("key = "+ key + " value = "+ property.get(key));
+		}
 		
+		return created();		
+
 		
 	}