This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Global extends GlobalSettings { | |
def json(errorCode: String, message: String) = Json.obj("ERR" -> errorCode, "MESSAGE" -> message) | |
override def onError(request: RequestHeader, ex: Throwable) = { | |
Logger.error("Internal Error", ex) | |
Future.successful(InternalServerError(json("0001", ex.getStackTrace()))) | |
} | |
override def onHandlerNotFound(request: RequestHeader): Result = Future.successful(NotFound(json("0002", request.toString))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Composed action to handle logging and measuring in same request | |
object LoggedMeasured extends ActionBuilder[Request] { | |
def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[SimpleResult]) = block(request) | |
override def composeAction[A](action: Action[A]) = Logged(Measured(action)) | |
} | |
object Application extends Controller{ | |
def batch = LoggedMeasured { | |
val result = User.batchUpload | |
Ok(result.toString) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Stand-alone logging | |
def editUser = Logged { | |
val result = User.edit | |
Ok(result.toString) | |
} | |
//Stand-alone measured | |
def calc = Measured { | |
//calculate pi using taylor series | |
val result = Pi.calculate(1000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//atomic action to log requests | |
case class Logged[A](action: Action[A]) extends Action[A] { | |
def apply(request: Request[A]): Future[SimpleResult] = { | |
Logger.info("Calling action") | |
action(request) | |
} | |
lazy val parser = action.parser | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Application extends Controller { | |
//store data | |
def findById(id: String) = Action { | |
val user: User = Cache.getOrElse[User]("user." + id) { | |
User.find(id) | |
} | |
Ok(views.html.show(user)) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RESTful routes for Users collection | |
GET /users controllers.Users.list | |
POST /users controllers.Users.insert | |
DELETE /users controllers.Users.deleteAll | |
# RESTful routes by User | |
GET /users/:id controllers.Users.findById(id: String) | |
PUT /users/:id controllers.Users.update | |
DELETE /users/:id controllers.Users.delete(id: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object JS { | |
def default(js: JsValue): JsValue = js match { | |
case JsObject(fields) => JsObject(fields.map(f => f._1 -> default(f._2))) | |
case JsString(s) => JsString("") | |
case JsArray(a) => JsArray() | |
case JsNumber(n) => JsNumber(0.0) | |
case JsBoolean(b) => JsBoolean(false) | |
case _ => JsString("") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
case class Root(id: Int, name: String, children: Seq[Child]) | |
case class Child(id: Int, name: String) | |
object Application extends Controller with Secured{ | |
def test = Action { implicit req => | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val CustomPackage = config("custompackage") extend(Compile) describedAs("Custom package configuration") | |
mappings in (CustomPackage, packageBin) ~= { (ms: Seq[(File, String)]) => | |
ms filter { | |
case (file, toPath) => { | |
val shouldInclude = toPath.startsWith("models") | |
println("===========" + file + " " + toPath + " " + shouldInclude) | |
shouldInclude | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package npr | |
import puzzles.WordBank | |
/** | |
* User: jconley | |
* Date: 1/26/14 | |
* | |
* http://puzzles.blainesville.com/2014/01/npr-sunday-puzzle-jan-26-2014-remove.html | |
*/ |