Mercurial > hg > Members > nobuyasu > Consensus
changeset 32:be6bbd4967e4
create createMentions
author | one |
---|---|
date | Wed, 03 Oct 2012 16:47:44 +0900 |
parents | 995be14b30a2 |
children | 1ca28e3eb4e9 |
files | app/controllers/Claim.java app/models/ClaimModel.java app/models/NodeModel.java app/models/UserModel.java conf/routes target/scala-2.9.1/cache/compile/copy-resources target/scala-2.9.1/classes/routes target/scala-2.9.1/src_managed/main/controllers/routes.java target/scala-2.9.1/src_managed/main/routes_reverseRouting.scala target/scala-2.9.1/src_managed/main/routes_routing.scala test/RequestTest.java |
diffstat | 11 files changed, 83 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controllers/Claim.java Wed Oct 03 15:16:56 2012 +0900 +++ b/app/controllers/Claim.java Wed Oct 03 16:47:44 2012 +0900 @@ -100,21 +100,15 @@ public static Result getClaimTree(String id) { TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); - Vertex v = graph.getVertex(id); - if (v == null) return badRequest("Consensus id "+ id +" is not found."); + if (v == null) { + return badRequest("Consensus id "+ id +" is not found."); + } ClaimModel consensusRoot = new ClaimModel(v); ObjectNode resultEntity = consensusRoot.getClaimInfoTraverse(); - - ObjectNode mentions = consensusRoot.getClaimMentions(); - resultEntity.put(NodeModel.MENTIONS, Json.toJson(mentions)); - - return ok(resultEntity); } - - - + private static String[] toStringArray(JsonNode jsonNode) {
--- a/app/models/ClaimModel.java Wed Oct 03 15:16:56 2012 +0900 +++ b/app/models/ClaimModel.java Wed Oct 03 16:47:44 2012 +0900 @@ -35,27 +35,30 @@ property.put(STATUS, Json.toJson(getProperty(STATUS))); property.put(TOULMIN, Json.toJson(getProperty(TOULMIN))); property.put(L_AUTHOR, Json.toJson(getAuthorId())); - property.put(MENTIONS, Json.toJson(getMentionsId())); + property.put(MENTIONS, Json.toJson(getClaimMentionsRecursive())); property.put(USERS, Json.toJson(getUsersIdAndStatus())); return property; } - public ObjectNode getClaimMentions() { + public Object[] getClaimMentionsRecursive() { GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex,Edge>(); pipe.start(vertex).outE(L_QUESTION,L_REFUTATION,L_SUGGESTION); + ArrayList<Object> array = new ArrayList<Object>(); for (Edge e:pipe) { String label = e.getLabel(); - - + ObjectNode info = Json.newObject(); + info.put(TYPE, Json.toJson(label)); + info.put(STATUS, Json.toJson(e.getProperty(STATUS))); + GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>(); + pipeChildVertex.start(e).inV(); + ClaimModel childClaim = new ClaimModel(pipeChildVertex.next()); + info.put(CLAIM, childClaim.getClaimInfoTraverse()); + info.put(MENTIONS, Json.toJson(childClaim.getClaimMentionsRecursive())); + array.add(info); } - return null; + return array.toArray(); } - - private JsonNode getClaimMention() { - - return null; - } - + public Object[] getInfoArray(String... labels) { GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); pipe.start(vertex).out(labels); @@ -80,7 +83,7 @@ for (Edge e : pipeEdge) { GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>(); ObjectNode info = Json.newObject(); - pipeChildVertex.start(e).outV(); + pipeChildVertex.start(e).inV(); Vertex childVertex = pipeChildVertex.next(); info.put(ID, Json.toJson(childVertex.getId())); info.put(STATUS, Json.toJson(e.getProperty(STATUS))); @@ -97,14 +100,13 @@ public Object getAuthorId() { GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); pipe.start(vertex).out(L_AUTHOR); - if (pipe.hasNext()) return null; + if (!pipe.hasNext()) { + return null; + } Vertex authorV = pipe.next(); return authorV.getId(); } - - - public void setClaimProperties(JsonNode toulmin, String type) { String title = toulmin.findPath(TITLE).getTextValue(); String contents = toulmin.findPath(CONTENTS).getTextValue();
--- a/app/models/NodeModel.java Wed Oct 03 15:16:56 2012 +0900 +++ b/app/models/NodeModel.java Wed Oct 03 16:47:44 2012 +0900 @@ -50,7 +50,7 @@ public static final String DENIED = "denied"; // Use This key Json Data - public static final String CLAIMS = "claims"; + public static final String CLAIM = "claim"; public static final String REQUESTS = "requests"; public static final String CONSENSUS = "consensus";
--- a/app/models/UserModel.java Wed Oct 03 15:16:56 2012 +0900 +++ b/app/models/UserModel.java Wed Oct 03 16:47:44 2012 +0900 @@ -61,7 +61,7 @@ Object[] claims = getUserClaims(); HashMap<Object,Object[]> hash = new HashMap<Object, Object[]>(); hash.put(NodeModel.REQUESTS, requests); - hash.put(NodeModel.CLAIMS, claims); + hash.put(NodeModel.CLAIM, claims); HashSet<Object> set = makeSet(requests, claims); hash.put(NodeModel.CONSENSUS, tpGraph.checkConsensus(set)); return hash;
--- a/conf/routes Wed Oct 03 15:16:56 2012 +0900 +++ b/conf/routes Wed Oct 03 16:47:44 2012 +0900 @@ -15,7 +15,7 @@ POST /claims/create controllers.Claim.crateClaim() POST /claims/:mentionType/:id/create controllers.Claim.createMention(mentionType: String ,id: String) - +GET /consensus/browse/:id controllers.Claim.getClaimTree(id: String) # test action
--- a/target/scala-2.9.1/classes/routes Wed Oct 03 15:16:56 2012 +0900 +++ b/target/scala-2.9.1/classes/routes Wed Oct 03 16:47:44 2012 +0900 @@ -8,14 +8,14 @@ GET /users/browse/:name controllers.User.getUser(name: String) GET /users/requests/:name controllers.User.getUserRequests(name: String) GET /users/consensus/:name controllers.User.getUserConsensus(name: String) -GET /users/claims/:name controllers.User.getUserClaims(name: String) +GET /users/claims/:name controllers.User.getUserClaims(name: String) -GET /claims/browse/:id controllers.Claim.getClaimInfo(id: String) +GET /claims/browse/:id controllers.Claim.getClaimInfo(id: String) GET /claims/consensus/:id controllers.Claim.getClaimTree(id: String) -POST /claims/create controllers.Claim.crateClaim() +POST /claims/create controllers.Claim.crateClaim() POST /claims/:mentionType/:id/create controllers.Claim.createMention(mentionType: String ,id: String) - +GET /consensus/browse/:id controllers.Claim.getClaimTree(id: String) # test action
--- a/target/scala-2.9.1/src_managed/main/controllers/routes.java Wed Oct 03 15:16:56 2012 +0900 +++ b/target/scala-2.9.1/src_managed/main/controllers/routes.java Wed Oct 03 16:47:44 2012 +0900 @@ -1,6 +1,6 @@ // @SOURCE:/Users/aotokage/workspace/Consensus/conf/routes -// @HASH:4e0ef425af6fa19939155c7491434fa337e3afc9 -// @DATE:Wed Oct 03 13:57:35 JST 2012 +// @HASH:f5c672b7256d9fa8e950b3ac1ed290083dabeefe +// @DATE:Wed Oct 03 15:56:50 JST 2012 package controllers;
--- a/target/scala-2.9.1/src_managed/main/routes_reverseRouting.scala Wed Oct 03 15:16:56 2012 +0900 +++ b/target/scala-2.9.1/src_managed/main/routes_reverseRouting.scala Wed Oct 03 16:47:44 2012 +0900 @@ -1,6 +1,6 @@ // @SOURCE:/Users/aotokage/workspace/Consensus/conf/routes -// @HASH:4e0ef425af6fa19939155c7491434fa337e3afc9 -// @DATE:Wed Oct 03 13:57:35 JST 2012 +// @HASH:f5c672b7256d9fa8e950b3ac1ed290083dabeefe +// @DATE:Wed Oct 03 15:56:50 JST 2012 import play.core._ import play.core.Router._ @@ -15,6 +15,7 @@ // @LINE:27 // @LINE:23 // @LINE:22 +// @LINE:18 // @LINE:17 // @LINE:16 // @LINE:14 @@ -27,6 +28,7 @@ // @LINE:6 package controllers { +// @LINE:18 // @LINE:17 // @LINE:16 // @LINE:14 @@ -42,9 +44,17 @@ } +// @LINE:18 // @LINE:14 def getClaimTree(id:String) = { - Call("GET", "/claims/consensus/" + implicitly[PathBindable[String]].unbind("id", id)) + (id) match { +// @LINE:14 +case (id) if true => Call("GET", "/claims/consensus/" + implicitly[PathBindable[String]].unbind("id", id)) + +// @LINE:18 +case (id) if true => Call("GET", "/consensus/browse/" + implicitly[PathBindable[String]].unbind("id", id)) + + } } @@ -164,6 +174,7 @@ // @LINE:27 // @LINE:23 // @LINE:22 +// @LINE:18 // @LINE:17 // @LINE:16 // @LINE:14 @@ -176,6 +187,7 @@ // @LINE:6 package controllers.javascript { +// @LINE:18 // @LINE:17 // @LINE:16 // @LINE:14 @@ -196,13 +208,19 @@ ) +// @LINE:18 // @LINE:14 def getClaimTree = JavascriptReverseRoute( "controllers.Claim.getClaimTree", """ function(id) { + if (true) { return _wA({method:"GET", url:"/claims/consensus/" + (""" + implicitly[PathBindable[String]].javascriptUnbind + """)("id", id)}) } + if (true) { + return _wA({method:"GET", url:"/consensus/browse/" + (""" + implicitly[PathBindable[String]].javascriptUnbind + """)("id", id)}) + } + } """ ) @@ -378,6 +396,7 @@ // @LINE:27 // @LINE:23 // @LINE:22 +// @LINE:18 // @LINE:17 // @LINE:16 // @LINE:14 @@ -390,6 +409,7 @@ // @LINE:6 package controllers.ref { +// @LINE:18 // @LINE:17 // @LINE:16 // @LINE:14
--- a/target/scala-2.9.1/src_managed/main/routes_routing.scala Wed Oct 03 15:16:56 2012 +0900 +++ b/target/scala-2.9.1/src_managed/main/routes_routing.scala Wed Oct 03 16:47:44 2012 +0900 @@ -1,6 +1,6 @@ // @SOURCE:/Users/aotokage/workspace/Consensus/conf/routes -// @HASH:4e0ef425af6fa19939155c7491434fa337e3afc9 -// @DATE:Wed Oct 03 13:57:35 JST 2012 +// @HASH:f5c672b7256d9fa8e950b3ac1ed290083dabeefe +// @DATE:Wed Oct 03 15:56:50 JST 2012 import play.core._ import play.core.Router._ @@ -54,18 +54,22 @@ val controllers_Claim_createMention9 = Route("POST", PathPattern(List(StaticPart("/claims/"),DynamicPart("mentionType", """[^/]+"""),StaticPart("/"),DynamicPart("id", """[^/]+"""),StaticPart("/create")))) +// @LINE:18 +val controllers_Claim_getClaimTree10 = Route("GET", PathPattern(List(StaticPart("/consensus/browse/"),DynamicPart("id", """[^/]+""")))) + + // @LINE:22 -val controllers_Application_hello10 = Route("POST", PathPattern(List(StaticPart("/hello")))) +val controllers_Application_hello11 = Route("POST", PathPattern(List(StaticPart("/hello")))) // @LINE:23 -val controllers_Application_test11 = Route("GET", PathPattern(List(StaticPart("/test")))) +val controllers_Application_test12 = Route("GET", PathPattern(List(StaticPart("/test")))) // @LINE:27 -val controllers_Assets_at12 = Route("GET", PathPattern(List(StaticPart("/assets/"),DynamicPart("file", """.+""")))) +val controllers_Assets_at13 = Route("GET", PathPattern(List(StaticPart("/assets/"),DynamicPart("file", """.+""")))) -def documentation = List(("""GET""","""/""","""controllers.Application.index()"""),("""PUT""","""/users/create/$name<[^/]+>""","""controllers.User.createUser(name:String)"""),("""GET""","""/users/browse/$name<[^/]+>""","""controllers.User.getUser(name:String)"""),("""GET""","""/users/requests/$name<[^/]+>""","""controllers.User.getUserRequests(name:String)"""),("""GET""","""/users/consensus/$name<[^/]+>""","""controllers.User.getUserConsensus(name:String)"""),("""GET""","""/users/claims/$name<[^/]+>""","""controllers.User.getUserClaims(name:String)"""),("""GET""","""/claims/browse/$id<[^/]+>""","""controllers.Claim.getClaimInfo(id:String)"""),("""GET""","""/claims/consensus/$id<[^/]+>""","""controllers.Claim.getClaimTree(id:String)"""),("""POST""","""/claims/create""","""controllers.Claim.crateClaim()"""),("""POST""","""/claims/$mentionType<[^/]+>/$id<[^/]+>/create""","""controllers.Claim.createMention(mentionType:String, id:String)"""),("""POST""","""/hello""","""controllers.Application.hello()"""),("""GET""","""/test""","""controllers.Application.test()"""),("""GET""","""/assets/$file<.+>""","""controllers.Assets.at(path:String = "/public", file:String)""")) +def documentation = List(("""GET""","""/""","""controllers.Application.index()"""),("""PUT""","""/users/create/$name<[^/]+>""","""controllers.User.createUser(name:String)"""),("""GET""","""/users/browse/$name<[^/]+>""","""controllers.User.getUser(name:String)"""),("""GET""","""/users/requests/$name<[^/]+>""","""controllers.User.getUserRequests(name:String)"""),("""GET""","""/users/consensus/$name<[^/]+>""","""controllers.User.getUserConsensus(name:String)"""),("""GET""","""/users/claims/$name<[^/]+>""","""controllers.User.getUserClaims(name:String)"""),("""GET""","""/claims/browse/$id<[^/]+>""","""controllers.Claim.getClaimInfo(id:String)"""),("""GET""","""/claims/consensus/$id<[^/]+>""","""controllers.Claim.getClaimTree(id:String)"""),("""POST""","""/claims/create""","""controllers.Claim.crateClaim()"""),("""POST""","""/claims/$mentionType<[^/]+>/$id<[^/]+>/create""","""controllers.Claim.createMention(mentionType:String, id:String)"""),("""GET""","""/consensus/browse/$id<[^/]+>""","""controllers.Claim.getClaimTree(id:String)"""),("""POST""","""/hello""","""controllers.Application.hello()"""),("""GET""","""/test""","""controllers.Application.test()"""),("""GET""","""/assets/$file<.+>""","""controllers.Assets.at(path:String = "/public", file:String)""")) def routes:PartialFunction[RequestHeader,Handler] = { @@ -150,8 +154,16 @@ } +// @LINE:18 +case controllers_Claim_getClaimTree10(params) => { + call(params.fromPath[String]("id", None)) { (id) => + invokeHandler(_root_.controllers.Claim.getClaimTree(id), HandlerDef(this, "controllers.Claim", "getClaimTree", Seq(classOf[String]))) + } +} + + // @LINE:22 -case controllers_Application_hello10(params) => { +case controllers_Application_hello11(params) => { call { invokeHandler(_root_.controllers.Application.hello(), HandlerDef(this, "controllers.Application", "hello", Nil)) } @@ -159,7 +171,7 @@ // @LINE:23 -case controllers_Application_test11(params) => { +case controllers_Application_test12(params) => { call { invokeHandler(_root_.controllers.Application.test(), HandlerDef(this, "controllers.Application", "test", Nil)) } @@ -167,7 +179,7 @@ // @LINE:27 -case controllers_Assets_at12(params) => { +case controllers_Assets_at13(params) => { call(Param[String]("path", Right("/public")), params.fromPath[String]("file", None)) { (path, file) => invokeHandler(_root_.controllers.Assets.at(path, file), HandlerDef(this, "controllers.Assets", "at", Seq(classOf[String], classOf[String]))) }
--- a/test/RequestTest.java Wed Oct 03 15:16:56 2012 +0900 +++ b/test/RequestTest.java Wed Oct 03 16:47:44 2012 +0900 @@ -36,8 +36,8 @@ String[] users3 = {user1}; for (int i=0; i<user1Claim.size(); i++) { int claimId = user1Claim.get(i).asInt(); -// createMention(user2, users3, NodeModel.L_QUESTION, claimId); -// createMention(user3, users3, NodeModel.L_REFUTATION, claimId); + createMention(user2, users3, NodeModel.L_QUESTION, claimId); + createMention(user3, users3, NodeModel.L_REFUTATION, claimId); getClaimInfo(claimId); } @@ -53,17 +53,21 @@ getUserInfo(user3,"claims/"); getUserInfo(user3,"consensus/"); +*/ for (int i=0; i<user1Claim.size(); i++ ) { int id = user1Claim.get(i).asInt(); // getClaimInfo(user1Claim.get(i).asInt()); getClaimTree(id); + break; } - */ + } + + public static JsonNode getClaimTree(int id) { - final String uri = SERVER_ROOT_URI + "/claims/consensus/"+id; + final String uri = SERVER_ROOT_URI + "/consensus/browse/"+id; WebResource resource = Client.create().resource(uri); ClientResponse response = resource.get(ClientResponse.class); System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus()));