{"action":"created","comment":{"url":"https://api.github.com/repos/kaltura/kanalony/pulls/comments/53751050","id":53751050,"diff_hunk":"@@ -0,0 +1,126 @@\n+package controllers\n+\n+import kanalony.storage.logic.queries.model._\n+import kanalony.storage.logic._\n+import model._\n+import org.joda.time.DateTime\n+import scala.concurrent.ExecutionContext.Implicits.global\n+import model.Implicits._\n+import play.api.mvc._\n+import argonaut._\n+import Argonaut._\n+import scala.concurrent._\n+\n+class Application extends Controller {\n+\n+  def query: Action[AnyContent] = Action.async({ implicit request => doQuery(request) })\n+\n+  def doQuery(request : Request[AnyContent]) : Future[Result] = {\n+    try {\n+      val analyticsRequestOption = for {\n+        input <- request.body.asJson\n+        req <- input.toString.decodeOption[AnalyticsRequest]\n+      } yield req\n+\n+      if (analyticsRequestOption.isEmpty) {\n+        return wrapWithPromise(BadRequest(\"Invalid input - ensure proper JSON is supplied with the mandatory fields supplied and that the supplied MIME type is application/json\"))\n+      }\n+\n+      val queryParams = requestToQueryParams(analyticsRequestOption.get)\n+      val queryExecutionResult = execute(queryParams)\n+      val queryResponseData =  queryExecutionResult map { data => AnalyticsResponse(data.headers, data.rows) }\n+\n+      queryResponseData map {\n+        data => Ok(data.asJson.toString)\n+      } recover {\n+        case e : Exception => BadRequest(e.getMessage)\n+      }\n+    }\n+    catch {\n+      case e: QueryNotSupportedException => {\n+        return wrapWithPromise(BadRequest(e.getMessage))\n+      }\n+      case e: IllegalArgumentException => {\n+        return wrapWithPromise(BadRequest(e.getMessage))\n+      }\n+      case e: Exception => {\n+        println(e.getClass.getTypeName)\n+        return wrapWithPromise(InternalServerError(e.getMessage))\n+      }\n+    }\n+  }\n+\n+  def wrapWithPromise(res : Result): Future[Result] = {\n+    return (Promise[Result] success res).future\n+  }\n+\n+  def execute(queryParams: QueryParams): Future[IQueryResult] = {\n+    QueryLocator.locate(queryParams).query(queryParams)\n+  }\n+\n+  def extractValues[T, E <: Exception](values : List[String], enumConverter : String => T, exceptionCreator : String => E): List[T] = {\n+    var processedValue = \"\"\n+    var res = List[T]()\n+    try {\n+      values.foreach(d => {\n+        processedValue = d\n+        res = res :+ enumConverter(d)\n+      })\n+      res\n+    }\n+    catch {\n+      case e : Exception => throw exceptionCreator(processedValue)\n+    }\n+  }\n+\n+  def extractMetrics(metrics : List[String]): List[Metrics.Value] = {\n+    extractValues(metrics, Metrics.withName(_), s => new InvalidMetricsException(\"Metric \" + s + \" not supported\"))\n+  }\n+\n+  def extractDimension(dimension : String): Dimensions.Value = {\n+    val results = extractValues(List(dimension), Dimensions.withName(_), s => new InvalidDimensionException(s))\n+    results(0)\n+  }\n+\n+  def extractDimensions(dimensions : List[String]): List[Dimensions.Value] = {\n+    extractValues(dimensions, Dimensions.withName(_), s => new InvalidDimensionException(s))\n+  }\n+\n+  def createConstraint(dimension: Dimensions.Value, values: List[String]) : IDimensionConstraint = {\n+    try {\n+      dimension match {\n+        case Dimensions.partner => new DimensionEqualityConstraint[Int](values.toSet.map { (v: String) => v.toInt })","path":"kanalony-web-server/app/controllers/Application.scala","position":92,"original_position":92,"commit_id":"db7892aa9d19ef7a4255831ff9dda8d956462c42","original_commit_id":"db7892aa9d19ef7a4255831ff9dda8d956462c42","user":{"login":"kerkero","id":2822450,"avatar_url":"https://avatars.githubusercontent.com/u/2822450?v=3","gravatar_id":"","url":"https://api.github.com/users/kerkero","html_url":"https://github.com/kerkero","followers_url":"https://api.github.com/users/kerkero/followers","following_url":"https://api.github.com/users/kerkero/following{/other_user}","gists_url":"https://api.github.com/users/kerkero/gists{/gist_id}","starred_url":"https://api.github.com/users/kerkero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kerkero/subscriptions","organizations_url":"https://api.github.com/users/kerkero/orgs","repos_url":"https://api.github.com/users/kerkero/repos","events_url":"https://api.github.com/users/kerkero/events{/privacy}","received_events_url":"https://api.github.com/users/kerkero/received_events","type":"User","site_admin":false},"body":":+1: ","created_at":"2016-02-23T08:51:08Z","updated_at":"2016-02-23T08:51:08Z","html_url":"https://github.com/kaltura/kanalony/pull/5#discussion_r53751050","pull_request_url":"https://api.github.com/repos/kaltura/kanalony/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/kaltura/kanalony/pulls/comments/53751050"},"html":{"href":"https://github.com/kaltura/kanalony/pull/5#discussion_r53751050"},"pull_request":{"href":"https://api.github.com/repos/kaltura/kanalony/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/kaltura/kanalony/pulls/5","id":60297210,"html_url":"https://github.com/kaltura/kanalony/pull/5","diff_url":"https://github.com/kaltura/kanalony/pull/5.diff","patch_url":"https://github.com/kaltura/kanalony/pull/5.patch","issue_url":"https://api.github.com/repos/kaltura/kanalony/issues/5","number":5,"state":"open","locked":false,"title":"Add data access web server","user":{"login":"eladBenedict","id":11731485,"avatar_url":"https://avatars.githubusercontent.com/u/11731485?v=3","gravatar_id":"","url":"https://api.github.com/users/eladBenedict","html_url":"https://github.com/eladBenedict","followers_url":"https://api.github.com/users/eladBenedict/followers","following_url":"https://api.github.com/users/eladBenedict/following{/other_user}","gists_url":"https://api.github.com/users/eladBenedict/gists{/gist_id}","starred_url":"https://api.github.com/users/eladBenedict/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eladBenedict/subscriptions","organizations_url":"https://api.github.com/users/eladBenedict/orgs","repos_url":"https://api.github.com/users/eladBenedict/repos","events_url":"https://api.github.com/users/eladBenedict/events{/privacy}","received_events_url":"https://api.github.com/users/eladBenedict/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-23T07:09:00Z","updated_at":"2016-02-23T08:51:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9f404e3930caa1791f34f947d8a7ff3d8b6250d8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/kaltura/kanalony/pulls/5/commits","review_comments_url":"https://api.github.com/repos/kaltura/kanalony/pulls/5/comments","review_comment_url":"https://api.github.com/repos/kaltura/kanalony/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kaltura/kanalony/issues/5/comments","statuses_url":"https://api.github.com/repos/kaltura/kanalony/statuses/db7892aa9d19ef7a4255831ff9dda8d956462c42","head":{"label":"kaltura:addDataAccessWebServer","ref":"addDataAccessWebServer","sha":"db7892aa9d19ef7a4255831ff9dda8d956462c42","user":{"login":"kaltura","id":319096,"avatar_url":"https://avatars.githubusercontent.com/u/319096?v=3","gravatar_id":"","url":"https://api.github.com/users/kaltura","html_url":"https://github.com/kaltura","followers_url":"https://api.github.com/users/kaltura/followers","following_url":"https://api.github.com/users/kaltura/following{/other_user}","gists_url":"https://api.github.com/users/kaltura/gists{/gist_id}","starred_url":"https://api.github.com/users/kaltura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaltura/subscriptions","organizations_url":"https://api.github.com/users/kaltura/orgs","repos_url":"https://api.github.com/users/kaltura/repos","events_url":"https://api.github.com/users/kaltura/events{/privacy}","received_events_url":"https://api.github.com/users/kaltura/received_events","type":"Organization","site_admin":false},"repo":{"id":42642837,"name":"kanalony","full_name":"kaltura/kanalony","owner":{"login":"kaltura","id":319096,"avatar_url":"https://avatars.githubusercontent.com/u/319096?v=3","gravatar_id":"","url":"https://api.github.com/users/kaltura","html_url":"https://github.com/kaltura","followers_url":"https://api.github.com/users/kaltura/followers","following_url":"https://api.github.com/users/kaltura/following{/other_user}","gists_url":"https://api.github.com/users/kaltura/gists{/gist_id}","starred_url":"https://api.github.com/users/kaltura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaltura/subscriptions","organizations_url":"https://api.github.com/users/kaltura/orgs","repos_url":"https://api.github.com/users/kaltura/repos","events_url":"https://api.github.com/users/kaltura/events{/privacy}","received_events_url":"https://api.github.com/users/kaltura/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kaltura/kanalony","description":"Kaltura's next generation Analytics solution based on Spark, Cassandra and Kafka","fork":false,"url":"https://api.github.com/repos/kaltura/kanalony","forks_url":"https://api.github.com/repos/kaltura/kanalony/forks","keys_url":"https://api.github.com/repos/kaltura/kanalony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kaltura/kanalony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kaltura/kanalony/teams","hooks_url":"https://api.github.com/repos/kaltura/kanalony/hooks","issue_events_url":"https://api.github.com/repos/kaltura/kanalony/issues/events{/number}","events_url":"https://api.github.com/repos/kaltura/kanalony/events","assignees_url":"https://api.github.com/repos/kaltura/kanalony/assignees{/user}","branches_url":"https://api.github.com/repos/kaltura/kanalony/branches{/branch}","tags_url":"https://api.github.com/repos/kaltura/kanalony/tags","blobs_url":"https://api.github.com/repos/kaltura/kanalony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kaltura/kanalony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kaltura/kanalony/git/refs{/sha}","trees_url":"https://api.github.com/repos/kaltura/kanalony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kaltura/kanalony/statuses/{sha}","languages_url":"https://api.github.com/repos/kaltura/kanalony/languages","stargazers_url":"https://api.github.com/repos/kaltura/kanalony/stargazers","contributors_url":"https://api.github.com/repos/kaltura/kanalony/contributors","subscribers_url":"https://api.github.com/repos/kaltura/kanalony/subscribers","subscription_url":"https://api.github.com/repos/kaltura/kanalony/subscription","commits_url":"https://api.github.com/repos/kaltura/kanalony/commits{/sha}","git_commits_url":"https://api.github.com/repos/kaltura/kanalony/git/commits{/sha}","comments_url":"https://api.github.com/repos/kaltura/kanalony/comments{/number}","issue_comment_url":"https://api.github.com/repos/kaltura/kanalony/issues/comments{/number}","contents_url":"https://api.github.com/repos/kaltura/kanalony/contents/{+path}","compare_url":"https://api.github.com/repos/kaltura/kanalony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kaltura/kanalony/merges","archive_url":"https://api.github.com/repos/kaltura/kanalony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kaltura/kanalony/downloads","issues_url":"https://api.github.com/repos/kaltura/kanalony/issues{/number}","pulls_url":"https://api.github.com/repos/kaltura/kanalony/pulls{/number}","milestones_url":"https://api.github.com/repos/kaltura/kanalony/milestones{/number}","notifications_url":"https://api.github.com/repos/kaltura/kanalony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kaltura/kanalony/labels{/name}","releases_url":"https://api.github.com/repos/kaltura/kanalony/releases{/id}","deployments_url":"https://api.github.com/repos/kaltura/kanalony/deployments","created_at":"2015-09-17T07:54:13Z","updated_at":"2016-02-22T18:31:48Z","pushed_at":"2016-02-23T07:09:00Z","git_url":"git://github.com/kaltura/kanalony.git","ssh_url":"git@github.com:kaltura/kanalony.git","clone_url":"https://github.com/kaltura/kanalony.git","svn_url":"https://github.com/kaltura/kanalony","homepage":null,"size":188,"stargazers_count":5,"watchers_count":5,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":5,"default_branch":"master"}},"base":{"label":"kaltura:master","ref":"master","sha":"a783a3c24a02dd6d3e8f23177333bacbd84b8dc6","user":{"login":"kaltura","id":319096,"avatar_url":"https://avatars.githubusercontent.com/u/319096?v=3","gravatar_id":"","url":"https://api.github.com/users/kaltura","html_url":"https://github.com/kaltura","followers_url":"https://api.github.com/users/kaltura/followers","following_url":"https://api.github.com/users/kaltura/following{/other_user}","gists_url":"https://api.github.com/users/kaltura/gists{/gist_id}","starred_url":"https://api.github.com/users/kaltura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaltura/subscriptions","organizations_url":"https://api.github.com/users/kaltura/orgs","repos_url":"https://api.github.com/users/kaltura/repos","events_url":"https://api.github.com/users/kaltura/events{/privacy}","received_events_url":"https://api.github.com/users/kaltura/received_events","type":"Organization","site_admin":false},"repo":{"id":42642837,"name":"kanalony","full_name":"kaltura/kanalony","owner":{"login":"kaltura","id":319096,"avatar_url":"https://avatars.githubusercontent.com/u/319096?v=3","gravatar_id":"","url":"https://api.github.com/users/kaltura","html_url":"https://github.com/kaltura","followers_url":"https://api.github.com/users/kaltura/followers","following_url":"https://api.github.com/users/kaltura/following{/other_user}","gists_url":"https://api.github.com/users/kaltura/gists{/gist_id}","starred_url":"https://api.github.com/users/kaltura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaltura/subscriptions","organizations_url":"https://api.github.com/users/kaltura/orgs","repos_url":"https://api.github.com/users/kaltura/repos","events_url":"https://api.github.com/users/kaltura/events{/privacy}","received_events_url":"https://api.github.com/users/kaltura/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kaltura/kanalony","description":"Kaltura's next generation Analytics solution based on Spark, Cassandra and Kafka","fork":false,"url":"https://api.github.com/repos/kaltura/kanalony","forks_url":"https://api.github.com/repos/kaltura/kanalony/forks","keys_url":"https://api.github.com/repos/kaltura/kanalony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kaltura/kanalony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kaltura/kanalony/teams","hooks_url":"https://api.github.com/repos/kaltura/kanalony/hooks","issue_events_url":"https://api.github.com/repos/kaltura/kanalony/issues/events{/number}","events_url":"https://api.github.com/repos/kaltura/kanalony/events","assignees_url":"https://api.github.com/repos/kaltura/kanalony/assignees{/user}","branches_url":"https://api.github.com/repos/kaltura/kanalony/branches{/branch}","tags_url":"https://api.github.com/repos/kaltura/kanalony/tags","blobs_url":"https://api.github.com/repos/kaltura/kanalony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kaltura/kanalony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kaltura/kanalony/git/refs{/sha}","trees_url":"https://api.github.com/repos/kaltura/kanalony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kaltura/kanalony/statuses/{sha}","languages_url":"https://api.github.com/repos/kaltura/kanalony/languages","stargazers_url":"https://api.github.com/repos/kaltura/kanalony/stargazers","contributors_url":"https://api.github.com/repos/kaltura/kanalony/contributors","subscribers_url":"https://api.github.com/repos/kaltura/kanalony/subscribers","subscription_url":"https://api.github.com/repos/kaltura/kanalony/subscription","commits_url":"https://api.github.com/repos/kaltura/kanalony/commits{/sha}","git_commits_url":"https://api.github.com/repos/kaltura/kanalony/git/commits{/sha}","comments_url":"https://api.github.com/repos/kaltura/kanalony/comments{/number}","issue_comment_url":"https://api.github.com/repos/kaltura/kanalony/issues/comments{/number}","contents_url":"https://api.github.com/repos/kaltura/kanalony/contents/{+path}","compare_url":"https://api.github.com/repos/kaltura/kanalony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kaltura/kanalony/merges","archive_url":"https://api.github.com/repos/kaltura/kanalony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kaltura/kanalony/downloads","issues_url":"https://api.github.com/repos/kaltura/kanalony/issues{/number}","pulls_url":"https://api.github.com/repos/kaltura/kanalony/pulls{/number}","milestones_url":"https://api.github.com/repos/kaltura/kanalony/milestones{/number}","notifications_url":"https://api.github.com/repos/kaltura/kanalony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kaltura/kanalony/labels{/name}","releases_url":"https://api.github.com/repos/kaltura/kanalony/releases{/id}","deployments_url":"https://api.github.com/repos/kaltura/kanalony/deployments","created_at":"2015-09-17T07:54:13Z","updated_at":"2016-02-22T18:31:48Z","pushed_at":"2016-02-23T07:09:00Z","git_url":"git://github.com/kaltura/kanalony.git","ssh_url":"git@github.com:kaltura/kanalony.git","clone_url":"https://github.com/kaltura/kanalony.git","svn_url":"https://github.com/kaltura/kanalony","homepage":null,"size":188,"stargazers_count":5,"watchers_count":5,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kaltura/kanalony/pulls/5"},"html":{"href":"https://github.com/kaltura/kanalony/pull/5"},"issue":{"href":"https://api.github.com/repos/kaltura/kanalony/issues/5"},"comments":{"href":"https://api.github.com/repos/kaltura/kanalony/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/kaltura/kanalony/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/kaltura/kanalony/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kaltura/kanalony/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/kaltura/kanalony/statuses/db7892aa9d19ef7a4255831ff9dda8d956462c42"}}}}