Mercurial > hg > Members > nobuyasu > Consensus
changeset 20:34ea98c5a18c
modified UserModel/getEdgeInUser
author | one |
---|---|
date | Tue, 02 Oct 2012 22:49:16 +0900 |
parents | 20b2daf76635 |
children | e113f946c9c1 |
files | app/controllers/Claim.java app/controllers/User.java app/models/TPGraph.java app/models/UserModel.java test/RequestTest.java |
diffstat | 5 files changed, 31 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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;
--- 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; }
--- 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<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); 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<Object> array = new ArrayList<Object>(); + 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<length; i++ ) { - newRequestsObj[i] = requestsObj[i]; - } - newRequestsObj[length] = claimVertex.getId(); -// vertex.setProperty(REQUESTS, newRequestsObj); - } - -/* - public Vertex setName(String name) { - this.vertex.setProperty(NAME, name); - return vertex; - } -*/ - - + }
--- a/test/RequestTest.java Tue Oct 02 21:52:17 2012 +0900 +++ b/test/RequestTest.java Tue Oct 02 22:49:16 2012 +0900 @@ -14,20 +14,26 @@ final static String SERVER_ROOT_URI = "http://localhost:9000"; public static void main(String[] args) throws JSONException { + String user1 = "akifumi"; + String user2 = "takaaki"; + String user3 = "yosiaki"; - createUser("akifumi"); - createUser("takaaki"); - createUser("yosiaki"); + createUser(user1); + createUser(user2); + createUser(user3); -/* + /* getUser("akifumi"); - getUserInfo("akifumi","requests/"); getUserInfo("akifumi","claims/"); getUserInfo("akifumi","consensus/"); */ - String[] users = {"takaaki", "yosiaki"}; - createClaim("akifumi", users); - getUserInfo("akifumi","requests/"); + String[] users = {user2,user3}; + createClaim(user1, users); + createClaim(user1, users); + getUserInfo(user2,"requests/"); + getUserInfo(user3,"requests/"); + + } public static void createClaim(String author, String[] users) throws JSONException {