Skip to content

Commit

Permalink
FIX partially json handling
Browse files Browse the repository at this point in the history
  • Loading branch information
prayagupa committed Jan 2, 2014
1 parent ffa411d commit bd124ee
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
40 changes: 32 additions & 8 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
package controllers

import play.api._
import java.net.URLEncoder
import play.api.mvc._
import play.api.libs.ws.WS
import akka.util.Timeout
import play.api.libs.concurrent.Execution.Implicits._
import scala.concurrent.{ Await, Future }
import scala.concurrent.duration._
import play.Logger
import play.api.libs.json.JsValue


object Application extends Controller {

def index = Action {
val url = "http://localhost:8443/DasTest/esReport?clientId=2000&reportingBasis=ServiceDate&reportingTo=2013-10-31&reportingFrom=2012-11-01&comparisonFrom=2011-11-01&comparisonTo=2012-10-31&report=qualityMetric&reportingPaidThrough=2013-10-31&comparisonPaidThrough=2012-10-31&phiCSDate=11-10-2008&phiCEDate=10-31-2013&isParticipation=y&program_type=Wellness&program_type=ActivityTracker"
val responseFuture = WS.url(url).get().map { response =>
Ok("Feed title: " + (response.json \ "title").as[String])
println("Response : " + response.json.as[String])
def index = Action {
val start = java.lang.System.currentTimeMillis()
implicit val timeout = Timeout(50000 milliseconds)
val url = "http://localhost:8443/DasTest/esReport?clientId=2000&reportingBasis=ServiceDate&reportingTo=2013-10-31&reportingFrom=2012-11-01&comparisonFrom=2011-11-01&comparisonTo=2012-10-31&report=qualityMetric&reportingPaidThrough=2013-10-31&comparisonPaidThrough=2012-10-31&phiCSDate=11-10-2008&phiCEDate=10-31-2013&isParticipation=y&program_type=Wellness&program_type=Activity%20Tracker"
Logger.info("url : {}",url)
val responseFuture = WS.url(url).get()
val future = responseFuture map {
response => (response.json \\ "reporting")
}
val future = responseFuture.value
Ok(views.html.index(future.toString))
val result = Await.result(future, timeout.duration).asInstanceOf[List[play.api.libs.json.JsObject]]

val size = result.size
var jsonVal: JsValue = null
var json: String = ""
val json_ = result.foreach(jsonObject =>
jsonObject.values.foreach(jsValue => {
Logger.info("jsvalue : "+jsValue)
jsonVal = jsValue
json = jsValue.toString()
}
)
)
val end = java.lang.System.currentTimeMillis()
Logger.info("size : {}", size.toString)
Logger.info("Time taken : {} seconds", ((end - start)/1000).toString)
Ok(views.html.index(size, json.toString))
}

}
7 changes: 3 additions & 4 deletions app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@(message: String)
@(size : Int, message: String)

@main("OnlyWallet") {

@play20.welcome(message)

@size
@message
}

0 comments on commit bd124ee

Please sign in to comment.