extract method

Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/6216412e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/6216412e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/6216412e

Branch: refs/heads/feature/test_daewon
Commit: 6216412e9121f894ea12162c93bb26accc375a1d
Parents: e8ae5dc
Author: daewon <[email protected]>
Authored: Mon Dec 21 15:00:07 2015 +0900
Committer: daewon <[email protected]>
Committed: Mon Dec 21 15:00:07 2015 +0900

----------------------------------------------------------------------
 .../main/scala/com/kakao/s2graph/core/PostProcess.scala   |  4 +++-
 s2rest_netty/src/main/scala/Server.scala                  | 10 +++++-----
 s2rest_play/app/controllers/ApplicationController.scala   |  2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/6216412e/s2core/src/main/scala/com/kakao/s2graph/core/PostProcess.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/com/kakao/s2graph/core/PostProcess.scala 
b/s2core/src/main/scala/com/kakao/s2graph/core/PostProcess.scala
index d39c87f..c3f3359 100644
--- a/s2core/src/main/scala/com/kakao/s2graph/core/PostProcess.scala
+++ b/s2core/src/main/scala/com/kakao/s2graph/core/PostProcess.scala
@@ -11,9 +11,11 @@ object PostProcess extends JSONParser {
   /**
    * Result Entity score field name
    */
-  val SCORE_FIELD_NAME = "scoreSum"
   val timeoutResults = Json.obj("size" -> 0, "results" -> Json.arr(), 
"isTimeout" -> true)
   val emptyResults = Json.obj("size" -> 0, "results" -> Json.arr(), "isEmpty" 
-> true)
+  def badRequestResults(ex: => Exception) = Json.obj("message" -> 
ex.getMessage)
+
+  val SCORE_FIELD_NAME = "scoreSum"
   val reservedColumns = Set("cacheRemain", "from", "to", "label", "direction", 
"_timestamp", "timestamp", "score", "props")
 
   def groupEdgeResult(queryRequestWithResultLs: Seq[QueryRequestWithResult], 
exclude: Seq[QueryRequestWithResult]) = {

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/6216412e/s2rest_netty/src/main/scala/Server.scala
----------------------------------------------------------------------
diff --git a/s2rest_netty/src/main/scala/Server.scala 
b/s2rest_netty/src/main/scala/Server.scala
index 3f1e70a..10d1275 100644
--- a/s2rest_netty/src/main/scala/Server.scala
+++ b/s2rest_netty/src/main/scala/Server.scala
@@ -59,7 +59,7 @@ class S2RestHandler(s2rest: RestCaller)(implicit ec: 
ExecutionContext) extends S
     }
   }
 
-  def toResponse(ctx: ChannelHandlerContext, req: FullHttpRequest, jsonQuery: 
JsValue, future: Future[(JsValue, String)], startedAt: Long) = {
+  def toResponse(ctx: ChannelHandlerContext, req: FullHttpRequest, body: 
JsValue, future: Future[(JsValue, String)], startedAt: Long) = {
 
     val defaultHeaders = List(Names.CONTENT_TYPE -> ApplicationJson)
     // NOTE: logging size of result should move to s2core.
@@ -81,7 +81,7 @@ class S2RestHandler(s2rest: RestCaller)(implicit ec: 
ExecutionContext) extends S
           if (impId.isEmpty) headerWithKeepAlive
           else (Experiment.impressionKey, impId) :: headerWithKeepAlive
 
-        val log = s"${req.getMethod} ${req.getUri} took ${duration} ms 200 
${s2rest.calcSize(resJson)} ${jsonQuery}"
+        val log = s"${req.getMethod} ${req.getUri} took ${duration} ms 200 
${s2rest.calcSize(resJson)} ${body}"
         logger.info(log)
 
         val responseHeaders = (Names.CONTENT_LENGTH -> 
buf.readableBytes().toString) :: headerWithImpKey
@@ -89,11 +89,11 @@ class S2RestHandler(s2rest: RestCaller)(implicit ec: 
ExecutionContext) extends S
 
       case Failure(ex) => ex match {
         case e: BadQueryException =>
-          logger.error(s"{$jsonQuery}, ${e.getMessage}", e)
-          val buf: ByteBuf = Unpooled.copiedBuffer(Json.obj("message" -> 
e.getMessage).toString, CharsetUtil.UTF_8)
+          logger.error(s"{$body}, ${e.getMessage}", e)
+          val buf: ByteBuf = 
Unpooled.copiedBuffer(PostProcess.badRequestResults(e).toString, 
CharsetUtil.UTF_8)
           simpleResponse(ctx, Ok, byteBufOpt = Option(buf), 
channelFutureListenerOpt = Option(Close), headers = defaultHeaders)
         case e: Exception =>
-          logger.error(s"${jsonQuery}, ${e.getMessage}", e)
+          logger.error(s"${body}, ${e.getMessage}", e)
           val buf: ByteBuf = 
Unpooled.copiedBuffer(PostProcess.emptyResults.toString, CharsetUtil.UTF_8)
           simpleResponse(ctx, InternalServerError, byteBufOpt = Option(buf), 
channelFutureListenerOpt = Option(Close), headers = defaultHeaders)
       }

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/6216412e/s2rest_play/app/controllers/ApplicationController.scala
----------------------------------------------------------------------
diff --git a/s2rest_play/app/controllers/ApplicationController.scala 
b/s2rest_play/app/controllers/ApplicationController.scala
index 484d282..7c30a5f 100644
--- a/s2rest_play/app/controllers/ApplicationController.scala
+++ b/s2rest_play/app/controllers/ApplicationController.scala
@@ -18,7 +18,7 @@ object ApplicationController extends Controller {
   val jsonParser: BodyParser[JsValue] = controllers.s2parse.json
 
   private def badQueryExceptionResults(ex: Exception) =
-    Future.successful(BadRequest(Json.obj("message" -> 
ex.getMessage)).as(applicationJsonHeader))
+    
Future.successful(BadRequest(PostProcess.badRequestResults(ex)).as(applicationJsonHeader))
 
   private def errorResults =
     Future.successful(Ok(PostProcess.emptyResults).as(applicationJsonHeader))

Reply via email to