comparison app/controllers/Claim.java @ 35:5d422941b702

fix
author one
date Wed, 03 Oct 2012 18:43:49 +0900
parents fac4aa26ea04
children 5f7fcdf98380
comparison
equal deleted inserted replaced
34:fac4aa26ea04 35:5d422941b702
40 tpGraph.setLabelToRootClaim(newClaim); 40 tpGraph.setLabelToRootClaim(newClaim);
41 return created(); 41 return created();
42 } 42 }
43 43
44 @BodyParser.Of(BodyParser.Json.class) 44 @BodyParser.Of(BodyParser.Json.class)
45 public static Result editClaim(String id) {
46 JsonNode json = request().body().asJson();
47 String author = json.findPath(NodeModel.L_AUTHOR).getTextValue(); // Author
48 TPGraph tpGraph = TPGraph.getInstance();
49 Graph graph = tpGraph.getGraph();
50 Vertex claimVertex = graph.getVertex(id);
51 if ( claimVertex == null ) {
52 return badRequest("Claim id "+ id + "is not exist.");
53 }
54 if ( graph.getVertex(author) == null) {
55 return badRequest("Author "+ author + "is not exist.");
56 }
57 JsonNode toulmin = json.findPath(NodeModel.TOULMIN);
58 if (toulmin.findPath(NodeModel.TITLE) == null) {
59 return badRequest("Please set title");
60 }
61 JsonNode usersJson = json.get(NodeModel.USERS);
62 String type = json.findPath(NodeModel.TYPE).getTextValue(); // Type (majority|unanimously)
63 ClaimModel claim = new ClaimModel(claimVertex);
64 tpGraph.setLabelToAuthor(claim, author);
65 claim.setClaimProperties(toulmin, type);
66 String[] users = toStringArray(usersJson);
67 tpGraph.setLabelStatusToUsers(claim, users, NodeModel.L_REQUEST, NodeModel.FAIL);
68 tpGraph.setLabelToRootClaim(claim);
69 return created();
70 }
71
72
73 @BodyParser.Of(BodyParser.Json.class)
45 public static Result createMention(String mentionType, String id) { 74 public static Result createMention(String mentionType, String id) {
46 if ( !(mentionType.equals(NodeModel.L_QUESTION) 75 if ( !(mentionType.equals(NodeModel.L_QUESTION)
47 ||mentionType.equals(NodeModel.L_REFUTATION) 76 ||mentionType.equals(NodeModel.L_REFUTATION)
48 ||mentionType.equals(NodeModel.L_QUESTION))) { 77 ||mentionType.equals(NodeModel.L_QUESTION))) {
49 return badRequest("Wrong mention type."); 78 return badRequest("Wrong mention type.");
81 } 110 }
82 ClaimModel claim = new ClaimModel(claimV); 111 ClaimModel claim = new ClaimModel(claimV);
83 ObjectNode claimInfo = claim.getSimpleClaimInfo(); 112 ObjectNode claimInfo = claim.getSimpleClaimInfo();
84 ObjectNode result = Json.newObject(); 113 ObjectNode result = Json.newObject();
85 result.put("status", "OK"); 114 result.put("status", "OK");
86 result.put("message", claimInfo.toString()); 115 result.put("message", claimInfo);
87 return ok(result); 116 return ok(result);
88 } 117 }
89 118
90 public static Result getClaimTree(String id) { 119 public static Result getClaimTree(String id) {
91 TPGraph tpGraph = TPGraph.getInstance(); 120 TPGraph tpGraph = TPGraph.getInstance();
96 } 125 }
97 ClaimModel consensusRoot = new ClaimModel(v); 126 ClaimModel consensusRoot = new ClaimModel(v);
98 ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse(); 127 ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse();
99 return ok(resultEntity); 128 return ok(resultEntity);
100 } 129 }
130
131
101 132
102 133
103 134
104 private static String[] toStringArray(JsonNode jsonNode) { 135 private static String[] toStringArray(JsonNode jsonNode) {
105 int length = jsonNode.size(); 136 int length = jsonNode.size();