Mercurial > hg > Members > nobuyasu > Consensus
changeset 81:3ebc3061f869 draft
create getUserLatestClaims.
line wrap: on
line diff
--- a/app/controllers/User.java Fri Mar 08 17:37:22 2013 +0900 +++ b/app/controllers/User.java Fri Mar 08 21:12:37 2013 +0900 @@ -16,16 +16,17 @@ public static Result createUser(String name) { TPGraph tpGraph = TPGraph.getInstance(); Vertex v = null; - UserModel newUser = null; + UserModel newUser = null; try { v = tpGraph.addVertex(name); } catch (IllegalArgumentException e) { - return status(CONFLICT, name+" already exists"); + return status(CONFLICT, name + " already exists"); } newUser = new UserModel(v); tpGraph.setLabelFromRootUser(newUser); -// newUser.setName(name); // user node hasn't name property only TinkerGraph. - return created(); + // newUser.setName(name); // user node hasn't name property only + // TinkerGraph. + return created(); } public static Result getUser(String name) { @@ -33,13 +34,12 @@ Vertex v = tpGraph.getVertex(name); if (v == null) { return notFound(); - } else { - UserModel user = new UserModel(v); - HashMap<Object, Object[]> hash = user.getUserInfo(); - return created(Json.toJson(hash)); } + UserModel user = new UserModel(v); + HashMap<Object, Object[]> hash = user.getUserInfo(); + return created(Json.toJson(hash)); } - + public static Result getAllUsers() { TPGraph tpGraph = TPGraph.getInstance(); Object[] allUser = tpGraph.searchAllUser(); @@ -48,67 +48,85 @@ } return ok(Json.toJson(allUser)); } - + public static Result getUserRequests(String name) { TPGraph tpGraph = TPGraph.getInstance(); Vertex v = tpGraph.getVertex(name); if (v == null) { - return notFound("User: "+name+" does not found"); - } else { - UserModel user = new UserModel(v); - Object[] requests = user.getUserRequests(); - if (requests == null) { - return notFound("Requests not found"); - } - return created(Json.toJson(requests)); - } + return notFound("User: " + name + " does not found"); + } + UserModel user = new UserModel(v); + Object[] requests = user.getUserRequests(); + if (requests == null) { + return notFound("Requests not found"); + } + return created(Json.toJson(requests)); } - + public static Result getUserConsensus(String name) { TPGraph tpGraph = TPGraph.getInstance(); Vertex v = tpGraph.getVertex(name); if (v == null) { - return notFound("user: "+name+" not found"); - } else { - UserModel user = new UserModel(v); - HashSet<Object> set = user.getClaimsAndRequests(); - if (set == null) { - return notFound("Consensus not found"); - } - Object[] consensus = tpGraph.checkConsensus(set); - return created(Json.toJson(consensus)); - } + return notFound("user: " + name + " not found"); + } + UserModel user = new UserModel(v); + HashSet<Object> set = user.getClaimsAndRequests(); + if (set == null) { + return notFound("Consensus not found"); + } + Object[] consensus = tpGraph.checkConsensus(set); + return created(Json.toJson(consensus)); } - + + /* + * TODO: Code Refactoring. getUserLatestConsensus method is almost the same + * getUserConsensus method. + */ public static Result getUserLatestConsensus(String name) { TPGraph tpGraph = TPGraph.getInstance(); Vertex v = tpGraph.getVertex(name); if (v == null) { - return notFound("user: "+name+" not found"); - } else { - UserModel user = new UserModel(v); - HashSet<Object> set = user.getLatestClaimsAndRequests(); - if (set == null) { - return notFound("Consensus not found"); - } - Object[] consensus = tpGraph.checkConsensus(set); - return created(Json.toJson(consensus)); + return notFound("user: " + name + " not found"); } + UserModel user = new UserModel(v); + HashSet<Object> set = user.getLatestClaimsAndRequests(); + if (set == null) { + return notFound("Consensus not found"); + } + Object[] consensus = tpGraph.checkConsensus(set); + return created(Json.toJson(consensus)); } public static Result getUserClaims(String name) { TPGraph tpGraph = TPGraph.getInstance(); Vertex v = tpGraph.getVertex(name); if (v == null) { - return notFound("User "+name+" does not found"); - } else { - UserModel user = new UserModel(v); - Object[] claims = user.getUserClaims(); - if (claims == null) { - return notFound("Claims does not found"); - } - return created(Json.toJson(claims)); - } + return notFound("User " + name + " does not found"); + } + UserModel user = new UserModel(v); + Object[] claims = user.getUserClaims(); + if (claims == null) { + return notFound("Claims does not found"); + } + return created(Json.toJson(claims)); } - + + /* + * TODO: Code refactoring. getUserLatestClaims method is almost the same + * getUserClaims method. + */ + public static Result getUserLatestClaims(String name) { + TPGraph tpGraph = TPGraph.getInstance(); + Vertex v = tpGraph.getVertex(name); + if (v == null) { + return notFound("User " + name + " does not found"); + } + UserModel user = new UserModel(v); + Object[] claims = user.getLatestUserClaims(); + if (claims == null) { + return notFound("Claims does not found"); + } + return created(Json.toJson(claims)); + } + }
--- a/conf/routes Fri Mar 08 17:37:22 2013 +0900 +++ b/conf/routes Fri Mar 08 21:12:37 2013 +0900 @@ -22,7 +22,7 @@ # latest GET /users/latest/consensus/:name controllers.User.getUserLatestConsensus(name: String) - +GET /users/latest/claims/:name controllers.User.getUserLatestClaims(name: String) GET /reset controllers.Claim.reset()
--- a/logs/application.log Fri Mar 08 17:37:22 2013 +0900 +++ b/logs/application.log Fri Mar 08 21:12:37 2013 +0900 @@ -169,3 +169,12 @@ 2013-03-08 17:20:53,356 - [INFO] - from play in play-akka.actor.default-dispatcher-11 Application started (Dev) +2013-03-08 19:46:34,614 - [INFO] - from application in play-akka.actor.default-dispatcher-15 +Application shutdown... + +2013-03-08 19:46:34,636 - [INFO] - from play in play-akka.actor.default-dispatcher-15 +Application started (Dev) + +2013-03-08 20:06:38,305 - [INFO] - from application in main +Application shutdown... +
Binary file target/scala-2.9.1/classes/Routes$$anonfun$routes$1$$anonfun$apply$1$$anonfun$apply$2.class has changed
Binary file target/scala-2.9.1/classes/Routes$$anonfun$routes$1$$anonfun$apply$3$$anonfun$apply$4.class has changed
Binary file target/scala-2.9.1/classes/Routes$$anonfun$routes$1$$anonfun$apply$5$$anonfun$apply$6.class has changed
Binary file target/scala-2.9.1/classes/controllers/ref/ReverseApplication$$anonfun$hello$1.class has changed
Binary file target/scala-2.9.1/classes/controllers/ref/ReverseAssets$$anonfun$at$1.class has changed
--- a/target/scala-2.9.1/classes/routes Fri Mar 08 17:37:22 2013 +0900 +++ b/target/scala-2.9.1/classes/routes Fri Mar 08 21:12:37 2013 +0900 @@ -22,7 +22,7 @@ # latest GET /users/latest/consensus/:name controllers.User.getUserLatestConsensus(name: String) - +GET /users/latest/claims/:name controllers.User.getUserLatestClaims(name: String) GET /reset controllers.Claim.reset()
Binary file target/scala-2.9.1/classes_managed/Routes$$anonfun$routes$1$$anonfun$apply$1$$anonfun$apply$2.class has changed
Binary file target/scala-2.9.1/classes_managed/Routes$$anonfun$routes$1$$anonfun$apply$1.class has changed
Binary file target/scala-2.9.1/classes_managed/Routes$$anonfun$routes$1$$anonfun$apply$3$$anonfun$apply$4.class has changed
Binary file target/scala-2.9.1/classes_managed/Routes$$anonfun$routes$1$$anonfun$apply$3.class has changed
Binary file target/scala-2.9.1/classes_managed/Routes$$anonfun$routes$1$$anonfun$apply$5$$anonfun$apply$6.class has changed
Binary file target/scala-2.9.1/classes_managed/Routes$$anonfun$routes$1$$anonfun$apply$5.class has changed
Binary file target/scala-2.9.1/classes_managed/controllers/javascript/ReverseApplication.class has changed
Binary file target/scala-2.9.1/classes_managed/controllers/javascript/ReverseAssets.class has changed
Binary file target/scala-2.9.1/classes_managed/controllers/ref/ReverseApplication$$anonfun$hello$1.class has changed
Binary file target/scala-2.9.1/classes_managed/controllers/ref/ReverseAssets$$anonfun$at$1.class has changed
--- a/target/scala-2.9.1/src_managed/main/controllers/routes.java Fri Mar 08 17:37:22 2013 +0900 +++ b/target/scala-2.9.1/src_managed/main/controllers/routes.java Fri Mar 08 21:12:37 2013 +0900 @@ -1,6 +1,6 @@ // @SOURCE:/Users/aotokage/workspace/Consensus/conf/routes -// @HASH:32d29c3020c757d877de6640fd77db72a2541e76 -// @DATE:Fri Mar 08 17:18:10 JST 2013 +// @HASH:877e6ae13b5f6e3fe7f6b31a89522b61199bb86d +// @DATE:Fri Mar 08 19:46:30 JST 2013 package controllers;
--- a/target/scala-2.9.1/src_managed/main/routes_reverseRouting.scala Fri Mar 08 17:37:22 2013 +0900 +++ b/target/scala-2.9.1/src_managed/main/routes_reverseRouting.scala Fri Mar 08 21:12:37 2013 +0900 @@ -1,6 +1,6 @@ // @SOURCE:/Users/aotokage/workspace/Consensus/conf/routes -// @HASH:32d29c3020c757d877de6640fd77db72a2541e76 -// @DATE:Fri Mar 08 17:18:10 JST 2013 +// @HASH:877e6ae13b5f6e3fe7f6b31a89522b61199bb86d +// @DATE:Fri Mar 08 19:46:30 JST 2013 import play.core._ import play.core.Router._ @@ -17,6 +17,7 @@ // @LINE:31 // @LINE:30 // @LINE:27 +// @LINE:25 // @LINE:24 // @LINE:21 // @LINE:20 @@ -167,6 +168,7 @@ } +// @LINE:25 // @LINE:24 // @LINE:12 // @LINE:11 @@ -215,6 +217,12 @@ } +// @LINE:25 +def getUserLatestClaims(name:String) = { + Call("GET", "/users/latest/claims/" + implicitly[PathBindable[String]].unbind("name", name)) +} + + // @LINE:12 def getUserClaims(name:String) = { Call("GET", "/users/claims/" + implicitly[PathBindable[String]].unbind("name", name)) @@ -234,6 +242,7 @@ // @LINE:31 // @LINE:30 // @LINE:27 +// @LINE:25 // @LINE:24 // @LINE:21 // @LINE:20 @@ -440,6 +449,7 @@ } +// @LINE:25 // @LINE:24 // @LINE:12 // @LINE:11 @@ -518,6 +528,17 @@ ) +// @LINE:25 +def getUserLatestClaims = JavascriptReverseRoute( + "controllers.User.getUserLatestClaims", + """ + function(name) { + return _wA({method:"GET", url:"/users/latest/claims/" + (""" + implicitly[PathBindable[String]].javascriptUnbind + """)("name", name)}) + } + """ +) + + // @LINE:12 def getUserClaims = JavascriptReverseRoute( "controllers.User.getUserClaims", @@ -542,6 +563,7 @@ // @LINE:31 // @LINE:30 // @LINE:27 +// @LINE:25 // @LINE:24 // @LINE:21 // @LINE:20 @@ -676,6 +698,7 @@ } +// @LINE:25 // @LINE:24 // @LINE:12 // @LINE:11 @@ -724,6 +747,12 @@ ) +// @LINE:25 +def getUserLatestClaims(name:String) = new play.api.mvc.HandlerRef( + controllers.User.getUserLatestClaims(name), HandlerDef(this, "controllers.User", "getUserLatestClaims", Seq(classOf[String])) +) + + // @LINE:12 def getUserClaims(name:String) = new play.api.mvc.HandlerRef( controllers.User.getUserClaims(name), HandlerDef(this, "controllers.User", "getUserClaims", Seq(classOf[String]))
--- a/target/scala-2.9.1/src_managed/main/routes_routing.scala Fri Mar 08 17:37:22 2013 +0900 +++ b/target/scala-2.9.1/src_managed/main/routes_routing.scala Fri Mar 08 21:12:37 2013 +0900 @@ -1,6 +1,6 @@ // @SOURCE:/Users/aotokage/workspace/Consensus/conf/routes -// @HASH:32d29c3020c757d877de6640fd77db72a2541e76 -// @DATE:Fri Mar 08 17:18:10 JST 2013 +// @HASH:877e6ae13b5f6e3fe7f6b31a89522b61199bb86d +// @DATE:Fri Mar 08 19:46:30 JST 2013 import play.core._ import play.core.Router._ @@ -78,26 +78,30 @@ val controllers_User_getUserLatestConsensus15 = Route("GET", PathPattern(List(StaticPart("/users/latest/consensus/"),DynamicPart("name", """[^/]+""")))) +// @LINE:25 +val controllers_User_getUserLatestClaims16 = Route("GET", PathPattern(List(StaticPart("/users/latest/claims/"),DynamicPart("name", """[^/]+""")))) + + // @LINE:27 -val controllers_Claim_reset16 = Route("GET", PathPattern(List(StaticPart("/reset")))) +val controllers_Claim_reset17 = Route("GET", PathPattern(List(StaticPart("/reset")))) // @LINE:30 -val controllers_Application_hello17 = Route("POST", PathPattern(List(StaticPart("/hello")))) +val controllers_Application_hello18 = Route("POST", PathPattern(List(StaticPart("/hello")))) // @LINE:31 -val controllers_Application_test18 = Route("GET", PathPattern(List(StaticPart("/test")))) +val controllers_Application_test19 = Route("GET", PathPattern(List(StaticPart("/test")))) // @LINE:36 -val controllers_Assets_at19 = Route("GET", PathPattern(List(StaticPart("/")))) +val controllers_Assets_at20 = Route("GET", PathPattern(List(StaticPart("/")))) // @LINE:37 -val controllers_Assets_at20 = Route("GET", PathPattern(List(StaticPart("/"),DynamicPart("file", """.+""")))) +val controllers_Assets_at21 = Route("GET", PathPattern(List(StaticPart("/"),DynamicPart("file", """.+""")))) -def documentation = List(("""GET""","""/users/all""","""controllers.User.getAllUsers()"""),("""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)"""),("""GET""","""/consensus/browse/$id<[^/]+>""","""controllers.Claim.getClaimTree(id:String)"""),("""GET""","""/claims/answer/$id<[^/]+>/$name<[^/]+>""","""controllers.Claim.getUserConsensusStatus(id:String, name:String)"""),("""GET""","""/copytree/$id<[^/]+>""","""controllers.Claim.copyClaims(id:String)"""),("""POST""","""/claims/answer/$id<[^/]+>/$name<[^/]+>/$status<[^/]+>""","""controllers.Claim.updateUserConsensusStatus(id:String, name:String, status:String)"""),("""POST""","""/claims/create""","""controllers.Claim.createClaim()"""),("""POST""","""/claims/$mentionType<[^/]+>/$id<[^/]+>/create""","""controllers.Claim.createMention(mentionType:String, id:String)"""),("""POST""","""/claims/edit/$id<[^/]+>""","""controllers.Claim.editClaim(id:String)"""),("""GET""","""/users/latest/consensus/$name<[^/]+>""","""controllers.User.getUserLatestConsensus(name:String)"""),("""GET""","""/reset""","""controllers.Claim.reset()"""),("""POST""","""/hello""","""controllers.Application.hello()"""),("""GET""","""/test""","""controllers.Application.test()"""),("""GET""","""/""","""controllers.Assets.at(path:String = "/public/viewer", file:String = "index.html")"""),("""GET""","""/$file<.+>""","""controllers.Assets.at(path:String = "/public/viewer", file:String)""")) +def documentation = List(("""GET""","""/users/all""","""controllers.User.getAllUsers()"""),("""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)"""),("""GET""","""/consensus/browse/$id<[^/]+>""","""controllers.Claim.getClaimTree(id:String)"""),("""GET""","""/claims/answer/$id<[^/]+>/$name<[^/]+>""","""controllers.Claim.getUserConsensusStatus(id:String, name:String)"""),("""GET""","""/copytree/$id<[^/]+>""","""controllers.Claim.copyClaims(id:String)"""),("""POST""","""/claims/answer/$id<[^/]+>/$name<[^/]+>/$status<[^/]+>""","""controllers.Claim.updateUserConsensusStatus(id:String, name:String, status:String)"""),("""POST""","""/claims/create""","""controllers.Claim.createClaim()"""),("""POST""","""/claims/$mentionType<[^/]+>/$id<[^/]+>/create""","""controllers.Claim.createMention(mentionType:String, id:String)"""),("""POST""","""/claims/edit/$id<[^/]+>""","""controllers.Claim.editClaim(id:String)"""),("""GET""","""/users/latest/consensus/$name<[^/]+>""","""controllers.User.getUserLatestConsensus(name:String)"""),("""GET""","""/users/latest/claims/$name<[^/]+>""","""controllers.User.getUserLatestClaims(name:String)"""),("""GET""","""/reset""","""controllers.Claim.reset()"""),("""POST""","""/hello""","""controllers.Application.hello()"""),("""GET""","""/test""","""controllers.Application.test()"""),("""GET""","""/""","""controllers.Assets.at(path:String = "/public/viewer", file:String = "index.html")"""),("""GET""","""/$file<.+>""","""controllers.Assets.at(path:String = "/public/viewer", file:String)""")) def routes:PartialFunction[RequestHeader,Handler] = { @@ -230,8 +234,16 @@ } +// @LINE:25 +case controllers_User_getUserLatestClaims16(params) => { + call(params.fromPath[String]("name", None)) { (name) => + invokeHandler(_root_.controllers.User.getUserLatestClaims(name), HandlerDef(this, "controllers.User", "getUserLatestClaims", Seq(classOf[String]))) + } +} + + // @LINE:27 -case controllers_Claim_reset16(params) => { +case controllers_Claim_reset17(params) => { call { invokeHandler(_root_.controllers.Claim.reset(), HandlerDef(this, "controllers.Claim", "reset", Nil)) } @@ -239,7 +251,7 @@ // @LINE:30 -case controllers_Application_hello17(params) => { +case controllers_Application_hello18(params) => { call { invokeHandler(_root_.controllers.Application.hello(), HandlerDef(this, "controllers.Application", "hello", Nil)) } @@ -247,7 +259,7 @@ // @LINE:31 -case controllers_Application_test18(params) => { +case controllers_Application_test19(params) => { call { invokeHandler(_root_.controllers.Application.test(), HandlerDef(this, "controllers.Application", "test", Nil)) } @@ -255,7 +267,7 @@ // @LINE:36 -case controllers_Assets_at19(params) => { +case controllers_Assets_at20(params) => { call(Param[String]("path", Right("/public/viewer")), Param[String]("file", Right("index.html"))) { (path, file) => invokeHandler(_root_.controllers.Assets.at(path, file), HandlerDef(this, "controllers.Assets", "at", Seq(classOf[String], classOf[String]))) } @@ -263,7 +275,7 @@ // @LINE:37 -case controllers_Assets_at20(params) => { +case controllers_Assets_at21(params) => { call(Param[String]("path", Right("/public/viewer")), params.fromPath[String]("file", None)) { (path, file) => invokeHandler(_root_.controllers.Assets.at(path, file), HandlerDef(this, "controllers.Assets", "at", Seq(classOf[String], classOf[String]))) }