comparison 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
comparison
equal deleted inserted replaced
12:ef434ebd64ae 13:9b677755cb93
1 package controllers; 1 package controllers;
2 2
3 import java.util.HashMap;
4
5 import org.codehaus.jackson.JsonNode;
6 import org.codehaus.jackson.node.ObjectNode;
7
8 import models.ClaimModel;
9 import models.NodeModel;
10 import models.TPGraph;
11 import models.UserModel;
12
13 import com.tinkerpop.blueprints.Graph;
14 import com.tinkerpop.blueprints.Vertex;
15
16 import play.libs.Json;
17 import play.mvc.BodyParser;
3 import play.mvc.Controller; 18 import play.mvc.Controller;
19 import play.mvc.Result;
4 20
5 public class Claim extends Controller { 21 public class Claim extends Controller {
6 22
7 23
8 24 @BodyParser.Of(BodyParser.Json.class)
9 public static void crateClaim() { 25 public static Result crateClaim() {
26 JsonNode json = request().body().asJson();
27 ObjectNode result = Json.newObject();
28 String title = json.findPath("title").getTextValue();
29 if (title == null) {
30 result.put("status", "KO");
31 result.put("message", "Please set title");
32 return badRequest(result);
33 }
34 String contents = json.findPath("contents").getTextValue();
35 String author = json.findPath(NodeModel.AUTHOR).getTextValue(); // Author
36 String q = json.findPath(NodeModel.QUALIFIER).getTextValue(); // Qualifier
37 String d = json.findPath(NodeModel.DATA).getTextValue(); // Data
38 String w = json.findPath(NodeModel.WARRANT).getTextValue(); // Warrant
39 String b = json.findPath(NodeModel.BACKING).getTextValue(); // Backing
40 String r = json.findPath(NodeModel.REBUTTLE).getTextValue(); // Rebuttle
41 String users = json.get(NodeModel.USERS).toString(); // Users
42 String type = json.findPath(NodeModel.TYPE).getTextValue(); // Type (majority|unanimously)
10 43
44 TPGraph tpGraph = TPGraph.getInstance();
45 Graph graph = tpGraph.getGraph();
46 Vertex v = null;
47 v = graph.addVertex(null);
48 ClaimModel newClaim = new ClaimModel(v);
49 newClaim.setClaimProperties(author, title, contents, q, d, w, b, r, users, type);
50 tpGraph.setLabelToRootClaim(newClaim);
51 // newUser.setName(name); // user node hasn't name property(only TinkerGraph).
52
53 HashMap<Object, Object> property = newClaim.getAllProperty();
54 for (Object key: property.keySet()) {
55 System.out.println("key = "+ key + " value = "+ property.get(key));
56 }
11 57
58 return created();
59
12 60
13 } 61 }
14 62
15 63
16 64