diff app/controllers/Claim.java @ 36:5f7fcdf98380

create editClaim
author one
date Thu, 04 Oct 2012 00:01:40 +0900
parents 5d422941b702
children bc3ac73320f9
line wrap: on
line diff
--- a/app/controllers/Claim.java	Wed Oct 03 18:43:49 2012 +0900
+++ b/app/controllers/Claim.java	Thu Oct 04 00:01:40 2012 +0900
@@ -36,7 +36,7 @@
 		tpGraph.setLabelToAuthor(newClaim, author);
 		newClaim.setClaimProperties(toulmin, type);
 		String[] users = toStringArray(usersJson);
-		tpGraph.setLabelStatusToUsers(newClaim, users, NodeModel.L_REQUEST, NodeModel.FAIL);
+		Boolean flag = tpGraph.setLabelStatusToUsers(newClaim, users, NodeModel.L_REQUEST, NodeModel.FAIL);
 		tpGraph.setLabelToRootClaim(newClaim);
 		return created();
 	}
@@ -47,9 +47,12 @@
 		String author = json.findPath(NodeModel.L_AUTHOR).getTextValue(); // Author
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
-		Vertex claimVertex = graph.getVertex(id);
-		if ( claimVertex == null ) {
-			return badRequest("Claim id "+ id + "is not exist.");		
+		ClaimModel claim = new ClaimModel(graph.getVertex(id));
+		if ( claim.getVertex() == null ) {
+			return badRequest("Claim id "+ id + "does not exist.");
+		} 
+		if ( !claim.getAuthorId().equals(author)) {
+			return badRequest("Wrong Author.");
 		}
 		if ( graph.getVertex(author) == null) { 
 			return badRequest("Author "+ author + "is not exist.");
@@ -58,13 +61,11 @@
 		if (toulmin.findPath(NodeModel.TITLE) == null) { 
 			return badRequest("Please set title");
 		}
-		JsonNode usersJson = json.get(NodeModel.USERS);  
+		JsonNode usersJson = json.get(NodeModel.USERS);
 		String type = json.findPath(NodeModel.TYPE).getTextValue(); // Type (majority|unanimously)		
-		ClaimModel claim = new ClaimModel(claimVertex);
-		tpGraph.setLabelToAuthor(claim, author);
 		claim.setClaimProperties(toulmin, type);
-		String[] users = toStringArray(usersJson);
-		tpGraph.setLabelStatusToUsers(claim, users, NodeModel.L_REQUEST, NodeModel.FAIL);
+		Object[] users = toStringObject(usersJson);
+		claim.editRequestsEdgeUsers(users);
 		tpGraph.setLabelToRootClaim(claim);
 		return created();
 	}
@@ -111,7 +112,6 @@
 		ClaimModel claim = new ClaimModel(claimV);
 		ObjectNode claimInfo = claim.getSimpleClaimInfo();
 		ObjectNode result = Json.newObject();
-		result.put("status", "OK");
 		result.put("message", claimInfo);
 		return ok(result);
 	}
@@ -127,10 +127,18 @@
 		ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse();
 		return ok(resultEntity);
 	}
-	
 
-		
-	
+	private static Object[] toStringObject(JsonNode jsonNode) {
+		int length = jsonNode.size();
+		if (length == 0) {
+			return null;
+		}
+		Object[] userArray = new Object[length];
+		for (int i=0; i<length; i++ ) {
+			userArray[i] = jsonNode.get(i).getTextValue();
+		}
+		return userArray;
+	}
 	
 	private static String[] toStringArray(JsonNode jsonNode) {
 		int length = jsonNode.size();