changeset 47:9645bfb49603

modified computeAndUpdateStatus
author one
date Thu, 04 Oct 2012 08:55:13 +0900
parents 49aa4ad3008f
children bc35c27966f5
files app/controllers/Claim.java app/controllers/User.java app/models/ClaimModel.java
diffstat 3 files changed, 56 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/app/controllers/Claim.java	Thu Oct 04 07:14:11 2012 +0900
+++ b/app/controllers/Claim.java	Thu Oct 04 08:55:13 2012 +0900
@@ -21,6 +21,9 @@
 	@BodyParser.Of(BodyParser.Json.class)
 	public static Result crateClaim() {
 		JsonNode json = request().body().asJson();
+		if (json == null) {
+			return badRequest("please set Enitity (Json Data)");
+		}
 		String author = json.findPath(NodeModel.L_AUTHOR).getTextValue(); // Author
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
@@ -48,6 +51,9 @@
 	@BodyParser.Of(BodyParser.Json.class)
 	public static Result editClaim(String id) {
 		JsonNode json = request().body().asJson();
+		if (json == null) {
+			return badRequest();
+		}
 		String author = json.findPath(NodeModel.L_AUTHOR).getTextValue(); // Author
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
@@ -94,7 +100,7 @@
 	
 	public static Result updateUserConsensusStatus(String id, String name, String status) {
 		if ( !(status.equals(NodeModel.AGREED) 
-				||status.equals(NodeModel.FAILED)
+				||status.equals(NodeModel.DENIED)
 				||status.equals(NodeModel.UNKNOWN)
 				||status.equals(NodeModel.PEND))) {
 				return badRequest("Wrong status type.");
@@ -122,6 +128,9 @@
 			return badRequest("Wrong mention type.");
 		}
 		JsonNode json = request().body().asJson();
+		if (json == null) {
+			return badRequest();
+		}
 		String author = json.findPath(NodeModel.L_AUTHOR).getTextValue(); // Author
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
--- a/app/controllers/User.java	Thu Oct 04 07:14:11 2012 +0900
+++ b/app/controllers/User.java	Thu Oct 04 08:55:13 2012 +0900
@@ -30,8 +30,6 @@
 		return created();	
 	}
 
-	
-
 	public static Result getUser(String name) {
 		TPGraph tpGraph = TPGraph.getInstance();
 		Graph graph = tpGraph.getGraph();
--- a/app/models/ClaimModel.java	Thu Oct 04 07:14:11 2012 +0900
+++ b/app/models/ClaimModel.java	Thu Oct 04 08:55:13 2012 +0900
@@ -22,6 +22,32 @@
 		super(vertex);
 	}
 	
+	public void setClaimProperties(JsonNode toulmin, String type) {
+		String title = toulmin.findPath(TITLE).getTextValue();
+		String contents = toulmin.findPath(CONTENTS).getTextValue();
+		String q = toulmin.findPath(QUALIFIER).getTextValue(); // Qualifier
+		String d = toulmin.findPath(DATA).getTextValue(); // Data
+		String w = toulmin.findPath(WARRANT).getTextValue(); // Warrant
+		String b = toulmin.findPath(BACKING).getTextValue(); // Backing
+		String r = toulmin.findPath(REBUTTLE).getTextValue(); // Rebuttle
+		ObjectNode t = Json.newObject();
+		t.put(TITLE, title);
+		t.put(CONTENTS, contents);
+		t.put(QUALIFIER, q);
+		t.put(DATA, d);
+		t.put(WARRANT, w);
+		t.put(BACKING, b);
+		t.put(REBUTTLE, r);
+		if (type == null) {
+			setProperty(TYPE, UNANIMOUSLY);
+		} else {
+			setProperty(TYPE, type);
+		}
+		if (getProperty(STATUS) == null) {
+			setProperty(STATUS, UNKNOWN); // Default Status is unknown.
+		}
+		setProperty(TOULMIN, t);
+	}
 	public ObjectNode getSimpleClaimInfo() {
 		ObjectNode property = Json.newObject();
 		property.put(TYPE, Json.toJson(getProperty(TYPE)));
@@ -196,28 +222,7 @@
 		return authorV.getId();
 	}
 	
-	public void setClaimProperties(JsonNode toulmin, String type) {
-		String title = toulmin.findPath(TITLE).getTextValue();
-		String contents = toulmin.findPath(CONTENTS).getTextValue();
-		String q = toulmin.findPath(QUALIFIER).getTextValue(); // Qualifier
-		String d = toulmin.findPath(DATA).getTextValue(); // Data
-		String w = toulmin.findPath(WARRANT).getTextValue(); // Warrant
-		String b = toulmin.findPath(BACKING).getTextValue(); // Backing
-		String r = toulmin.findPath(REBUTTLE).getTextValue(); // Rebuttle
-		ObjectNode t = Json.newObject();
-		t.put(TITLE, title);
-		t.put(CONTENTS, contents);
-		t.put(QUALIFIER, q);
-		t.put(DATA, d);
-		t.put(WARRANT, w);
-		t.put(BACKING, b);
-		t.put(REBUTTLE, r);
-		setProperty(TYPE, type);
-		if (getProperty(STATUS) == null) {
-			setProperty(STATUS, UNKNOWN); // Default Status is unknown.
-		}
-		setProperty(TOULMIN, t);
-	}
+
 	
 	public long getAgreedNumber(Object[] requestEdges) {
 		return getEdgeStatusNumber(requestEdges, AGREED);
@@ -264,14 +269,28 @@
 	}
 	
 	public void computeAndUpdateStatus() {
-		String childStatus = checkAllChildsStatus();
-		if (childStatus.equals(UNKNOWN)) {
-			setProperty(STATUS, UNKNOWN);
+		/* Check child claim */
+		String refutationStatus = checkRefutationClaims();
+		if (refutationStatus.equals(FAILED)) {
+			setProperty(STATUS,FAILED);
 			return;
-		} else if (childStatus.equals(FAILED)) {
-			setProperty(STATUS, FAILED);
+		} else if (refutationStatus.equals(UNKNOWN)) {
+			setProperty(STATUS,UNKNOWN);
 			return;
 		}
+		String queAndSugStatus = checkQuestionAndSuggestionClaims();
+		if (queAndSugStatus.equals(UNKNOWN)) {
+			setProperty(STATUS,UNKNOWN);
+			return;
+		}
+		String childStatus;
+		/* refutationStatus == PASS */
+		if (refutationStatus.equals(queAndSugStatus)) {
+			childStatus = PASS;
+		} else { /* queAndSugStatus == FAILED */
+			childStatus = FAILED;
+		}
+		/* Check user request status */
 		Object[] requestEdges = getRequestEdges();		
 		String type = getProperty(TYPE).toString();
 		long requestsNumber = requestEdges.length;