Permalink
Browse files

update to play2.2 (broken)

1 parent 3f9ede0 commit 16fbab74c5724d161103ae0aa49c800e0d18a318 @tgambet tgambet committed Jan 27, 2014
Showing with 309 additions and 354 deletions.
  1. +6 −5 app/controllers/Job.scala
  2. +13 −15 app/controllers/VSController.scala
  3. +3 −3 app/model/Coupon.scala
  4. +6 −5 app/model/Job.scala
  5. +1 −1 app/model/ResourceResponse.scala
  6. +6 −6 app/model/Run.scala
  7. +3 −3 app/model/User.scala
  8. +0 −60 app/store/Migration.scala
  9. +1 −1 app/store/MongoStore.scala
  10. +9 −8 app/vs/Global.scala
  11. +1 −0 build.sbt
  12. +1 −1 conf/application.conf
  13. +5 −4 project/Build.scala
  14. +1 −1 project/build.properties
  15. +1 −1 project/plugins.sbt
  16. +19 −19 test/actor/EnumeratorsTest.scala
  17. +5 −5 test/assertor/CSSValidatorTest.scala
  18. +4 −4 test/assertor/FileAssertorTest.scala
  19. +9 −9 test/assertor/MarkupValidatorTest.scala
  20. +8 −8 test/assertor/UnicornFormatAssertorTest.scala
  21. +3 −3 test/assertor/ValidatorNuTest.scala
  22. +4 −4 test/controllers/AdministrationTest.scala
  23. +15 −15 test/http/CacheTest.scala
  24. +13 −13 test/integration/FunctionalTest.scala
  25. +13 −13 test/model/FilterTest.scala
  26. +28 −28 test/model/FormatsTest.scala
  27. +7 −7 test/model/ResourceInfoTest.scala
  28. +7 −7 test/model/RunTest.scala
  29. +1 −1 test/model/SiteMapTest.scala
  30. +9 −9 test/model/StrategyTest.scala
  31. +3 −3 test/run/CyclicWebsiteTest.scala
  32. +2 −2 test/run/FilteredTreeWebsiteTest.scala
  33. +3 −3 test/run/JobDataTest.scala
  34. +1 −1 test/run/MaxResourcesTest.scala
  35. +1 −1 test/run/OneGETxHEADTest.scala
  36. +11 −9 test/run/ResumedRunTest.scala
  37. +1 −1 test/run/SimpleInterWebsiteTest.scala
  38. +5 −5 test/run/StopActionTest.scala
  39. +6 −6 test/run/W3CWebsiteTest.scala
  40. +1 −1 test/run/WebsiteStartsWithRedirectTest.scala
  41. +2 −2 test/run/WebsiteWithInvalidRedirectCrawlTest.scala
  42. +3 −1 test/run/WebsiteWithRedirectsCrawlTest.scala
  43. +49 −44 test/store/MongoStoreTest.scala
  44. +1 −1 test/util/ServersTest.scala
  45. +1 −1 test/util/TestKitHelper.scala
  46. +12 −9 test/util/VSTest.scala
  47. +1 −1 test/util/website/StringW.scala
  48. +4 −4 test/web/HtmlParserTest.scala
@@ -83,17 +83,18 @@ object Job extends VSController {
import play.api.mvc._
- def dispatcher(implicit id: JobId): ActionA = Action { implicit req =>
- (for {
+ def dispatcher(implicit id: JobId): ActionA = Action.async { implicit req =>
+ val action: String = (for {
body <- req.body.asFormUrlEncoded
param <- body.get("action")
action <- param.headOption
- } yield action.toLowerCase match {
+ } yield action.toLowerCase).getOrElse("notSpecified")
+ action match {
case "delete" => delete(id)(req)
case "run" => run(id)(req)
case "stop" => stop(id)(req)
- case a => BadRequest(views.html.error._400(List(("error", Messages("debug.unexpected", "unknown action " + a)))))
- }).getOrElse(BadRequest(views.html.error._400(List(("error", Messages("debug.unexpected", "no action parameter was specified"))))))
+ case a => Future.successful(BadRequest(views.html.error._400(List(("error", Messages("debug.unexpected", "unknown action " + a))))))
+ }
}
def socket(jobId: JobId, typ: SocketType): Handler = {
@@ -28,7 +28,7 @@ trait VSController extends Controller {
def CloseWebsocket = (Iteratee.ignore[JsValue], Enumerator.eof)
- implicit def toAsynchronousResult(result: Result): Future[Result] = Future.successful(result)
+ implicit def toAsynchronousResult(result: SimpleResult): Future[SimpleResult] = Future.successful(result)
def getUser()(implicit reqHeader: RequestHeader): Future[User] = {
for {
@@ -46,7 +46,7 @@ trait VSController extends Controller {
getUser.map(Some(_)).recover{case _ => None}
}
- def Timer(name: String)(f: Future[Result]): Future[Result] = {
+ def Timer(name: String)(f: Future[SimpleResult]): Future[SimpleResult] = {
if (name == "") {
f
} else {
@@ -57,21 +57,19 @@ trait VSController extends Controller {
}
}
- def AsyncAction(name: String)(f: Request[AnyContent] => Future[Result]): Action[AnyContent] = Action { implicit req =>
- Async {
+ def AsyncAction(name: String)(f: Request[AnyContent] => Future[SimpleResult]): Action[AnyContent] = Action.async { implicit req =>
Timer(name) {
- f(req) recover {
- case AccessNotAllowed(msg) => Forbidden(views.html.error._403(msg))
+ f(req).recoverWith[SimpleResult] {
+ case AccessNotAllowed(msg) => Future.successful(Forbidden(views.html.error._403(msg)))
case UnknownJob(_) => Global.onHandlerNotFound(req)
}
}
- }
}
- def AsyncAction(f: Request[AnyContent] => Future[Result]): Action[AnyContent] = AsyncAction("")(f)
+ def AsyncAction(f: Request[AnyContent] => Future[SimpleResult]): Action[AnyContent] = AsyncAction("")(f)
val AcceptsStream = Accepting(MimeTypes.EVENT_STREAM)
- def Authenticated(f: User => Future[Result])(implicit req: RequestHeader): Future[Result] = {
+ def Authenticated(f: User => Future[SimpleResult])(implicit req: RequestHeader): Future[SimpleResult] = {
(for {
user <- getUser()
result <- f(user)
@@ -90,7 +88,7 @@ trait VSController extends Controller {
}
}
- def RootAction(f: Request[AnyContent] => User => Future[Result]): ActionA = AsyncAction { implicit req =>
+ def RootAction(f: Request[AnyContent] => User => Future[SimpleResult]): ActionA = AsyncAction { implicit req =>
Authenticated { user =>
user match {
case user if user.isRoot => f(req)(user)
@@ -99,21 +97,21 @@ trait VSController extends Controller {
}
}
- def AuthenticatedAction(name: String)(f: Request[AnyContent] => User => Future[Result]): ActionA =
+ def AuthenticatedAction(name: String)(f: Request[AnyContent] => User => Future[SimpleResult]): ActionA =
AsyncAction(name) { implicit req => Authenticated { user => f(req)(user) } }
- def AuthenticatedAction(f: Request[AnyContent] => User => Future[Result]): ActionA = AuthenticatedAction("")(f)
+ def AuthenticatedAction(f: Request[AnyContent] => User => Future[SimpleResult]): ActionA = AuthenticatedAction("")(f)
- def UserAware(f: Option[User] => Future[Result])(implicit req: RequestHeader): Future[Result] = {
+ def UserAware(f: Option[User] => Future[SimpleResult])(implicit req: RequestHeader): Future[SimpleResult] = {
for {
userO <- getUserOption()
result <- f(userO)
} yield result
}
- def UserAwareAction(name: String)(f: Request[AnyContent] => Option[User] => Future[Result]): ActionA =
+ def UserAwareAction(name: String)(f: Request[AnyContent] => Option[User] => Future[SimpleResult]): ActionA =
AsyncAction(name) { implicit req => UserAware { user => f(req)(user) } }
- def UserAwareAction(f: Request[AnyContent] => Option[User] => Future[Result]): ActionA = UserAwareAction("")(f)
+ def UserAwareAction(f: Request[AnyContent] => Option[User] => Future[SimpleResult]): ActionA = UserAwareAction("")(f)
}
@@ -148,7 +148,7 @@ object Coupon {
def getAll()(implicit conf: Database): Future[List[Coupon]] = {
val cursor = collection.find(Json.obj()).cursor[JsValue]
- cursor.toList() map {
+ cursor.collect[List]() map {
list => list flatMap { coupon =>
try {
Some(coupon.as[Coupon])
@@ -162,7 +162,7 @@ object Coupon {
def get(id: CouponId)(implicit conf: Database): Future[Coupon] = {
val query = Json.obj("_id" -> toJson(id))
val cursor = collection.find(query).cursor[JsValue]
- cursor.headOption() map {
+ cursor.headOption map {
case None => throw new NoSuchCouponException(id.toString)
case Some(json) => json.as[Coupon]
}
@@ -171,7 +171,7 @@ object Coupon {
def get(code: String)(implicit conf: Database): Future[Coupon] = {
val query = Json.obj("code" -> toJson(code))
val cursor = collection.find(query).cursor[JsValue]
- cursor.headOption() map {
+ cursor.headOption map {
case None => throw new NoSuchCouponException(code)
case Some(json) => json.as[Coupon]
}
View
@@ -459,7 +459,7 @@ object Job {
def get(jobId: JobId)(implicit conf: Database): Future[Job] = {
val query = Json.obj("_id" -> toJson(jobId))
val cursor = collection.find(query).cursor[JsValue]
- cursor.headOption() map {
+ cursor.headOption map {
case None => throw UnknownJob(jobId) //new NoSuchElementException("Invalid jobId: " + jobId)
case Some(json) => json.as[Job]
}
@@ -468,7 +468,7 @@ object Job {
/**the list of all the Jobs */
def getAll()(implicit conf: Database): Future[List[Job]] = {
val cursor = collection.find(Json.obj()).cursor[JsValue]
- cursor.toList() map {
+ cursor.collect[List]() map {
list => list flatMap { job =>
try {
Some(job.as[Job])
@@ -487,7 +487,7 @@ object Job {
def getRunningJobs()(implicit conf: Database): Future[List[Job]] = {
val query = Json.obj("status.actorName" -> Json.obj("$exists" -> JsBoolean(true)))
val cursor = collection.find(query).cursor[JsValue]
- cursor.toList() map {
+ cursor.collect[List]() map {
list => list map {
_.as[Job]
}
@@ -539,7 +539,7 @@ object Job {
/*def getFor(userId: UserId, jobId: JobId)(implicit conf: Database): Future[Job] = {
val query = Json.obj("_id" -> toJson(jobId))
val cursor = collection.find(query).cursor[JsValue]
- cursor.headOption() map {
+ cursor.headOption map {
case Some(json) if (json \ "creator").asOpt[UserId] === Some(userId) => json.as[Job]
case _ => throw UnknownJob(jobId)
}
@@ -563,7 +563,8 @@ object Job {
def save(job: Job)(implicit conf: Database): Future[Job] = {
val jobJson = toJson(job)
- collection.insert(jobJson) map {
+ println(Json.prettyPrint(jobJson))
+ collection.insert(jobJson, writeConcern = journalCommit) map {
lastError => job
}
}
@@ -23,7 +23,7 @@ object ResourceResponse {
"runId" -> toJson(runId),
"event" -> toJson("resource-response") )
val cursor = Run.collection.find(query).cursor[JsValue]
- cursor.toList() map { list =>
+ cursor.collect[List]() map { list =>
list.map(json => json.as[ResourceResponseEvent](ResourceResponseEventFormat).rr).toSet
}
}
View
@@ -79,7 +79,7 @@ object Run {
"rd" -> BSONInteger(1),
"_id" -> BSONInteger(0))
val cursor = collection.find(query, projection).cursor[JsValue]
- cursor.headOption() flatMap {
+ cursor.headOption flatMap {
case None => Future.failed(new NoSuchElementException(s"${runId} does not exist or is not in Done state"))
case Some(json) =>
(json \ "rd").as[JsArray].value.collectFirst { case json if (json \ "url") == toJson(url) =>
@@ -101,7 +101,7 @@ object Run {
"rd" -> BSONInteger(1),
"_id" -> BSONInteger(0))
val cursor = collection.find(query, projection).cursor[JsValue]
- cursor.headOption() flatMap {
+ cursor.headOption flatMap {
case None => Future.failed(new NoSuchElementException(s"${runId} does not exist or is not in Done state"))
case Some(json) => Future.successful {
val rds: Seq[ResourceData] =
@@ -121,7 +121,7 @@ object Run {
"gad" -> BSONInteger(1),
"_id" -> BSONInteger(0))
val cursor = collection.find(query, projection).cursor[JsValue]
- cursor.headOption() flatMap {
+ cursor.headOption flatMap {
case None => Future.failed(new NoSuchElementException(s"${runId} does not exist or is not in Done state"))
case Some(json) => Future.successful {
(json \ "gad").as[Seq[GroupedAssertionData]]
@@ -140,7 +140,7 @@ object Run {
"runData" -> BSONInteger(1),
"_id" -> BSONInteger(0))
val cursor = collection.find(query, projection).cursor[JsValue]
- cursor.headOption() flatMap {
+ cursor.headOption flatMap {
case None => Future.failed(new NoSuchElementException(runId.toString))
case Some(json) => Future.successful((json \ "runData").as[RunData])
}
@@ -158,7 +158,7 @@ object Run {
"runData" -> BSONInteger(1),
"_id" -> BSONInteger(0))
val cursor = collection.find(query, projection).cursor[JsValue]
- cursor.headOption() flatMap {
+ cursor.headOption flatMap {
case None => Future.failed(new NoSuchElementException(runId.toString))
case Some(json) => Future.successful {
val timestamp = (json \ "timestamp").as[DateTime]
@@ -178,7 +178,7 @@ object Run {
def get(runId: RunId)(implicit conf: Database): Future[(Run, Iterable[RunAction])] = {
val query = Json.obj("runId" -> toJson(runId))
val cursor = collection.find(query).cursor[JsValue]
- cursor.toList() map { list =>
+ cursor.collect[List]() map { list =>
// the sort is done client-side
val orderedEvents = list.map(_.as[RunEvent]).sortBy(_.timestamp)
val (createRun, events) = orderedEvents match {
@@ -177,15 +177,15 @@ object User {
import conf._
val query = Json.obj("_id" -> toJson(userId))
val cursor = collection.find(query).cursor[JsValue]
- cursor.headOption() map {
+ cursor.headOption map {
case Some(json) => json.as[User]
case None => sys.error("user not found")
}
}
def getAll()(implicit conf: Database): Future[List[User]] = {
val cursor = collection.find(Json.obj()).cursor[JsValue]
- cursor.toList() map {
+ cursor.collect[List]() map {
list => list flatMap { user =>
try {
Some(user.as[User])
@@ -280,7 +280,7 @@ object User {
import conf._
val query = Json.obj("email" -> JsString(email.toLowerCase))
val cursor = collection.find(query).cursor[JsValue]
- cursor.headOption() map {
+ cursor.headOption map {
case Some(json) => json.as[User]
case None => throw UnknownUser(email)
}
@@ -1,60 +0,0 @@
-package org.w3.vs.store
-
-import org.w3.vs.model._
-import org.joda.time.{ DateTime, DateTimeZone }
-import org.w3.vs.web._
-import org.w3.vs._
-import org.w3.vs.actor.JobActor._
-
-import scala.util._
-import scala.concurrent.{ Future, Await }
-import scala.concurrent.duration.Duration
-import scala.concurrent.ExecutionContext.Implicits.global
-
-// Reactive Mongo imports
-import reactivemongo.api._
-import reactivemongo.api.collections.default._
-import reactivemongo.bson._
-// Reactive Mongo plugin
-import play.modules.reactivemongo._
-import play.modules.reactivemongo.json.ImplicitBSONHandlers._
-// Play Json imports
-import play.api.libs.iteratee._
-import play.api.libs.json._
-import play.api.libs.functional.syntax._
-import Json.toJson
-import play.api.libs.json.Reads.pattern
-import org.w3.vs.util.timer._
-
-import org.w3.vs.store.Formats._
-
-object Migration {
-
- val node = "localhost:27017"
- val dbName = "vs-test"
-
- def makeAllPasswordsLowerCase(): Unit = {
- val driver = new reactivemongo.api.MongoDriver
- val connection = driver.connection(Seq(node))
- val db = connection(dbName)
-
- val collection = db("users")
-
- val users: List[JsValue] = collection.find(Json.obj()).cursor[JsValue].toList.getOrFail()
-
- users foreach { user =>
- val email = (user \ "email").as[String]
- println(email)
- collection.update(
- selector = Json.obj("email" -> toJson(email)),
- update = Json.obj("$set" -> Json.obj("email" -> toJson(email.toLowerCase())))
- ).getOrFail()
- }
-
- }
-
- def main(args: Array[String]): Unit = {
- makeAllPasswordsLowerCase()
- }
-
-}
@@ -26,7 +26,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
*/
object MongoStore {
- val journalCommit = GetLastError(awaitJournalCommit = true)
+ val journalCommit = GetLastError(j = true)
def reInitializeDb()(implicit conf: Database): Future[Unit] = {
for {
View
@@ -4,6 +4,7 @@ import play.api._
import play.api.mvc._
import play.api.mvc.Results._
import play.api.Mode._
+import concurrent.Future
object Global extends GlobalSettings with Rendering with AcceptExtractors {
@@ -41,31 +42,31 @@ object Global extends GlobalSettings with Rendering with AcceptExtractors {
vs = null
}
- override def onHandlerNotFound(request : RequestHeader) : Result = {
+ override def onHandlerNotFound(request : RequestHeader): Future[SimpleResult] = {
implicit val implReq = request
Metrics.errors.e404()
- render {
+ Future.successful(render {
case Accepts.Html() => NotFound(views.html.error._404())
case Accepts.Json() => NotFound
- }
+ })
}
- override def onError(request: RequestHeader, ex: Throwable): Result = {
+ override def onError(request: RequestHeader, ex: Throwable): Future[SimpleResult] = {
implicit val implReq = request
Metrics.errors.e500()
- render {
+ Future.successful(render {
case Accepts.Html() => InternalServerError(views.html.error._500(List(("error", ex.getMessage))))
case Accepts.Json() => InternalServerError
- }
+ })
}
- override def onBadRequest(request: RequestHeader, error: String) = {
+ override def onBadRequest(request: RequestHeader, error: String): Future[SimpleResult] = {
implicit val implReq = request
error match {
case "InvalidJobId" => onHandlerNotFound(request)
case _ => {
Metrics.errors.e400()
- BadRequest(views.html.error._400(List(("error", error))))
+ Future.successful(BadRequest(views.html.error._400(List(("error", error)))))
}
}
}
View
@@ -0,0 +1 @@
+logLevel := Level.Warn
@@ -82,7 +82,7 @@ application {
vs {
akka{
loglevel = INFO
- event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
+ loggers = ["akka.event.slf4j.Slf4jLogger"]
}
jobactor-dispatcher {
mailbox-type = org.w3.vs.actor.JobActorMailbox
Oops, something went wrong.

0 comments on commit 16fbab7

Please sign in to comment.