Repository: incubator-s2graph
Updated Branches:
  refs/heads/master 488ee0f48 -> 476bde319


make toQuery to use toVertex.


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

Branch: refs/heads/master
Commit: f40affb7a3abfc7d7ec9b60831e6112075d96939
Parents: 0520ffc
Author: DO YUNG YOON <[email protected]>
Authored: Thu Mar 22 21:22:12 2018 +0900
Committer: DO YUNG YOON <[email protected]>
Committed: Thu Mar 22 21:22:12 2018 +0900

----------------------------------------------------------------------
 .../s2graph/core/rest/RequestParser.scala       | 29 +++++++-------------
 1 file changed, 10 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f40affb7/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala
index 2f6f67a..4ef3b1c 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala
@@ -354,12 +354,8 @@ class RequestParser(graph: S2GraphLike) {
     try {
       val vertices = for {
         value <- (jsValue \ "srcVertices").asOpt[Seq[JsValue]].getOrElse(Nil)
-        serviceName <- (value \ "serviceName").asOpt[String].toSeq
-        columnName <- (value \ "columnName").asOpt[String].toSeq
-        idJson = (value \ "id").asOpt[JsValue].map(Seq(_)).getOrElse(Nil)
-        idsJson = (value \ "ids").asOpt[Seq[JsValue]].getOrElse(Nil)
-        id <- (idJson ++ idsJson).flatMap(jsValueToAny(_).toSeq).distinct
-      } yield graph.toVertex(serviceName, columnName, id)
+        vertex <- toVertex(value)
+      } yield vertex
 
       if (vertices.isEmpty) throw BadQueryException("srcVertices`s id is 
empty")
       val steps = parse[Vector[JsValue]](jsValue, "steps")
@@ -578,22 +574,17 @@ class RequestParser(graph: S2GraphLike) {
   }
 
   def toVertices(jsValue: JsValue, operation: String, serviceName: 
Option[String] = None, columnName: Option[String] = None) = {
-    toJsValues(jsValue).map(toVertex(_, operation, serviceName, columnName))
+    toJsValues(jsValue).flatMap(toVertex(_, operation, serviceName, 
columnName))
   }
 
-  def toVertex(jsValue: JsValue, operation: String, serviceName: 
Option[String] = None, columnName: Option[String] = None): S2VertexLike = {
-    var id:String = ""
-    try {
-        id = parse[String](jsValue, "id")
-    } catch {
-        case e:Exception=>
-        id = parse[JsValue](jsValue, "id").toString
+  def toVertex(jsValue: JsValue, operation: String = "insert", serviceName: 
Option[String] = None, columnName: Option[String] = None): Seq[S2VertexLike] = {
+    ((jsValue \ "id").asOpt[JsValue].map(Seq(_)).getOrElse(Nil) ++ (jsValue \ 
"ids").asOpt[Seq[JsValue]].getOrElse(Nil)).flatMap(JSONParser.jsValueToAny).map 
{ id =>
+      val ts = parseOption[Long](jsValue, 
"timestamp").getOrElse(System.currentTimeMillis())
+      val sName = if (serviceName.isEmpty) parse[String](jsValue, 
"serviceName") else serviceName.get
+      val cName = if (columnName.isEmpty) parse[String](jsValue, "columnName") 
else columnName.get
+      val props = fromJsonToProperties((jsValue \ 
"props").asOpt[JsObject].getOrElse(Json.obj()))
+      graph.toVertex(sName, cName, id, props, ts, operation)
     }
-    val ts = parseOption[Long](jsValue, 
"timestamp").getOrElse(System.currentTimeMillis())
-    val sName = if (serviceName.isEmpty) parse[String](jsValue, "serviceName") 
else serviceName.get
-    val cName = if (columnName.isEmpty) parse[String](jsValue, "columnName") 
else columnName.get
-    val props = fromJsonToProperties((jsValue \ 
"props").asOpt[JsObject].getOrElse(Json.obj()))
-    graph.toVertex(sName, cName, id, props, ts, operation)
   }
 
   def toPropElements(jsObj: JsValue) = Try {

Reply via email to