# HG changeset patch # User one # Date 1349185756 -32400 # Node ID 34ea98c5a18c3b6366d92d13a19f320b7a310d72 # Parent 20b2daf766353ca64134870985aa4cd1c0fecd3a modified UserModel/getEdgeInUser diff -r 20b2daf76635 -r 34ea98c5a18c app/controllers/Claim.java --- a/app/controllers/Claim.java Tue Oct 02 21:52:17 2012 +0900 +++ b/app/controllers/Claim.java Tue Oct 02 22:49:16 2012 +0900 @@ -1,20 +1,13 @@ package controllers; -import java.util.HashMap; -import java.util.Iterator; - 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; @@ -39,16 +32,16 @@ JsonNode usersJson = json.get(NodeModel.USERS); // Users (class JsonNode) String type = json.findPath(NodeModel.TYPE).getTextValue(); // Type (majority|unanimously) - Vertex claimVertex = null; - claimVertex = graph.addVertex(null); - ClaimModel newClaim = new ClaimModel(claimVertex); - tpGraph.setLabelToAuthor(author, newClaim); + ClaimModel newClaim = new ClaimModel(graph.addVertex(null)); + tpGraph.setLabelToAuthor(newClaim, author); newClaim.setClaimProperties(toulmin, type); + String[] users = toStringArray(usersJson); - tpGraph.setLabelToUsers(claimVertex, users, NodeModel.L_REQUEST); + tpGraph.setLabelToUsers(newClaim, users, NodeModel.L_REQUEST); tpGraph.setLabelToRootClaim(newClaim); - tpGraph.setLabelToAuthor(author, newClaim); - return created(); + + + return created(); } private static String[] toStringArray(JsonNode jsonNode) { diff -r 20b2daf76635 -r 34ea98c5a18c app/controllers/User.java --- a/app/controllers/User.java Tue Oct 02 21:52:17 2012 +0900 +++ b/app/controllers/User.java Tue Oct 02 22:49:16 2012 +0900 @@ -5,7 +5,6 @@ import com.tinkerpop.blueprints.Graph; import com.tinkerpop.blueprints.Vertex; -import models.NodeModel; import models.TPGraph; import models.UserModel; import play.libs.Json; diff -r 20b2daf76635 -r 34ea98c5a18c app/models/TPGraph.java --- a/app/models/TPGraph.java Tue Oct 02 21:52:17 2012 +0900 +++ b/app/models/TPGraph.java Tue Oct 02 22:49:16 2012 +0900 @@ -1,11 +1,5 @@ package models; -import java.util.Iterator; - -import org.codehaus.jackson.JsonNode; - -import scala.reflect.generic.Trees.This; - import com.tinkerpop.blueprints.Graph; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.tg.TinkerGraph; @@ -93,18 +87,18 @@ setLabel(rootClaim, claim.getVertex(), CHILD); } - public void setLabelToAuthor(String author, ClaimModel claim) { + public void setLabelToAuthor(ClaimModel claim, String author) { Vertex authorVertex = graph.getVertex(author); // claim ---author---> authorVertex(userVertex) setLabel(claim.getVertex(), authorVertex, NodeModel.L_AUTHOR); } - public Boolean setLabelToUsers(Vertex claimVertex, String[] users, String label) { + public Boolean setLabelToUsers(ClaimModel claim, String[] users, String label) { for (String userName: users) { Vertex userVertex = graph.getVertex(userName); if (userVertex == null) return false; - setLabel(claimVertex, userVertex, label); + setLabel(claim.getVertex(), userVertex, label); } return true; } diff -r 20b2daf76635 -r 34ea98c5a18c app/models/UserModel.java --- a/app/models/UserModel.java Tue Oct 02 21:52:17 2012 +0900 +++ b/app/models/UserModel.java Tue Oct 02 22:49:16 2012 +0900 @@ -1,18 +1,7 @@ package models; -import java.util.HashMap; -import java.util.Iterator; - - +import java.util.ArrayList; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.node.ArrayNode; -import org.codehaus.jackson.node.JsonNodeFactory; - -import play.libs.Json; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.gremlin.java.GremlinPipeline; @@ -26,15 +15,12 @@ private Object[] getEdgeInUser(String labels) { GremlinPipeline pipe = new GremlinPipeline(); pipe.start(this.vertex).in(labels); - long length = pipe.count(); - if (length == 0) return null; - Object[] requests = new Object[(int) length]; - int i = 0; - for (Vertex v :pipe) { - requests[i] = v.getId(); - i++; + ArrayList array = new ArrayList(); + for (Vertex v : pipe) { + array.add(v.getId()); } - return requests; + if (array.size() == 0) return null; + return array.toArray(); } public Object[] getUserRequests() { @@ -49,24 +35,6 @@ return null; } - public void appendRequests(Vertex claimVertex) { - Object[] requestsObj = getUserRequests(); - int length = requestsObj == null ? 0 : requestsObj.length; - Object[] newRequestsObj = new Object[length+1]; - for (int i=0; i