changeset 13:9b677755cb93

create action Claim/createClaim
author one
date Tue, 02 Oct 2012 11:39:39 +0900
parents ef434ebd64ae
children 792fdb0c10bf
files app/controllers/Claim.java app/controllers/User.java app/models/NodeModel.java app/models/TPGraph.java app/models/UserModel.java conf/routes target/scala-2.9.1/cache/compile/compile
diffstat 7 files changed, 123 insertions(+), 46 deletions(-) [+]
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();		
+
 		
 	}
 	
--- a/app/controllers/User.java	Tue Oct 02 10:38:08 2012 +0900
+++ b/app/controllers/User.java	Tue Oct 02 11:39:39 2012 +0900
@@ -14,7 +14,7 @@
 
 public class User extends Controller {
 
-	public static Result create(String name) {
+	public static Result createUser(String name) {
 		
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
--- a/app/models/NodeModel.java	Tue Oct 02 10:38:08 2012 +0900
+++ b/app/models/NodeModel.java	Tue Oct 02 11:39:39 2012 +0900
@@ -1,7 +1,6 @@
 package models;
 
 import java.util.HashMap;
-import java.util.Iterator;
 
 import com.tinkerpop.blueprints.Vertex;
 
@@ -10,32 +9,48 @@
 	protected Vertex vertex;
 	protected Object id;
 
-	protected final String ID = "id";
+	protected HashMap<Object,Object> properties = new HashMap<Object,Object>();
+
+	public static  final String ID = "id";
+
+	
+	public static  final String AUTHOR = "author";
+	public static  final String TYPE = "type";
+	public static  final String MENTIONS = "mentions";
+
+
+	public static  final String QUESTION = "question";
+	public static  final String REFUTATION = "refutation";
 
-	protected final String TOULMIN = "toulmin";
-	protected final String TITLE = "title";
-	protected final String CONTENTS = "contents";
-	protected final String DATA = "d";
-	protected final String WARRANT = "w";
-	protected final String BACKING = "b";
-	protected final String REBUTTLE = "r";
-	protected final String AUTHOR = "author";
-	protected final String USERS = "users";
-	protected final String TYPE = "type";
-	protected final String MENTIONS = "mentions";
-
-	protected final String STATUS = "status";
-	protected final String PASS = "pass";
-	protected final String FAIL = "fail";
-	protected final String AGREED = "agreed";
-	protected final String DENIED = "denied"; 
+	public static  final String MAJORITY = "majority";
+	public static  final String UNANIMOUSLY = "unanimously";
+	
+	/*
+	 *  User property
+	 */
+	public static  final String CONSENSUS = "consensus";
+	public static  final String CLAIMS = "claims";
+	public static  final String REQUESTS = "requests";
 	
-	protected final String QUESTION = "question";
-	protected final String REFUTATION = "refutation";
-
-	protected final String MAJORITY = "majority";
-	protected final String UNANIMOUSLY = "unanimously";
-	
+	/*
+	 * Claim property
+	 */
+	public static  final String TOULMIN = "toulmin";
+	public static  final String TITLE = "title";
+	public static  final String CONTENTS = "contents";
+	public static  final String QUALIFIER = "q";	
+	public static  final String DATA = "d";
+	public static  final String WARRANT = "w";
+	public static  final String BACKING = "b";
+	public static  final String REBUTTLE = "r";
+	public static  final String USERS = "users";
+	public static  final String STATUS = "status";
+	// Status statement 
+	public static  final String PASS = "pass";
+	public static  final String FAIL = "fail";
+	public static  final String AGREED = "agreed";
+	public static  final String DENIED = "denied"; 
+		
 	
 	public NodeModel(Vertex vertex) {
 		this.vertex = vertex;
@@ -53,6 +68,18 @@
 	public Vertex getVertex() {
 		return this.vertex;
 	}
+	
+	public void setProperty(String key, Object value) {
+		this.vertex.setProperty(key, value);
+	}
+	
+	public HashMap<Object,Object> getAllProperty() {
+		for (String key : vertex.getPropertyKeys()) {
+			properties.put(key, vertex.getProperty(key));
+		}
+		return properties;
+	}
+	
 
 
 }
--- a/app/models/TPGraph.java	Tue Oct 02 10:38:08 2012 +0900
+++ b/app/models/TPGraph.java	Tue Oct 02 11:39:39 2012 +0900
@@ -12,8 +12,12 @@
 	private Object claimRootId;
 	private Object userRootId;
 	
+	/*
+	 *  Edge type
+	 */
 	protected final String CHILD = "child";
 	
+	
 	private TPGraph() {
 		
 	}
@@ -51,12 +55,16 @@
 		this.userRootId = id;
 	}
 	
+	public Object getClaimRootId() {
+		return claimRootId;
+	}
+
 	public Object getUserRootId() {
 		return userRootId;
 	}
 
 	public Vertex getClaimRootVertex() {
-		return graph.getVertex(userRootId);
+		return graph.getVertex(claimRootId);
 	}
 	
 	public Vertex getUserRootVertex() {
@@ -65,7 +73,14 @@
 
 	public void setLabelToRootUser(UserModel user) {
 		Vertex rootUser = getUserRootVertex(); 
+		/* 
+		 *  rootUser ---child---> newUser
+		 */
+		graph.addEdge(null, rootUser, user.getVertex(), CHILD);
+	}
 
+	public void setLabelToRootClaim(ClaimModel claim) {
+		Vertex rootClaim = getClaimRootVertex(); 
 		/* 
 		 *  rootUser ---child---> newUser
 		 */
--- a/app/models/UserModel.java	Tue Oct 02 10:38:08 2012 +0900
+++ b/app/models/UserModel.java	Tue Oct 02 11:39:39 2012 +0900
@@ -5,12 +5,7 @@
 import com.tinkerpop.blueprints.Vertex;
 
 public class UserModel extends NodeModel {
-
-	protected final String CONSENSUS = "consensus";
-	protected final String CLAIMS = "claims";
-	protected final String REQUESTS = "requests";
 	
-	protected HashMap<Object,Object> properties = new HashMap<Object,Object>();
 	
 	public UserModel(Vertex vertex) {
 		super(vertex);
@@ -18,17 +13,9 @@
 	
 
 	public void setUserInfo() {
-		this.vertex.setProperty(CONSENSUS, null);
-		this.vertex.setProperty(CLAIMS, null);
-		this.vertex.setProperty(REQUESTS, null);
-	}
-	
-
-	public HashMap<Object,Object> getUserProperty() {
-		for (String key : vertex.getPropertyKeys()) {
-			properties.put(key, vertex.getProperty(key));
-		}
-		return properties;
+		setProperty(CONSENSUS, null);
+		setProperty(CLAIMS, null);
+		setProperty(REQUESTS, null);
 	}
 
 	public HashMap<Object, Object> getUserRequests() {
--- a/conf/routes	Tue Oct 02 10:38:08 2012 +0900
+++ b/conf/routes	Tue Oct 02 11:39:39 2012 +0900
@@ -4,7 +4,7 @@
 
 # Home page
 GET		/							controllers.Application.index()
-PUT		/users/create/:name			controllers.User.create(name: String)
+PUT		/users/create/:name			controllers.User.createUser(name: String)
 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)
Binary file target/scala-2.9.1/cache/compile/compile has changed