diff options
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/Web.scala | 25 | ||||
-rw-r--r-- | src/main/scala/developerstream/Db.scala | 30 | ||||
-rw-r--r-- | src/main/scala/developerstream/DeveloperStreamPlan.scala | 48 |
3 files changed, 103 insertions, 0 deletions
diff --git a/src/main/scala/Web.scala b/src/main/scala/Web.scala new file mode 100644 index 0000000..b33e137 --- /dev/null +++ b/src/main/scala/Web.scala @@ -0,0 +1,25 @@ +import developerstream.DeveloperStreamPlan +import util.Properties + +object Web extends App { + val port = Properties.envOrElse("PORT", "1337").toInt + + unfiltered.jetty.Http.local(port).filter(new DeveloperStreamPlan()).run() + + + /* + val resources = new ResourceCollection( + Resource.newResource(new File("src/main/webapp")), + Resource.newClassPathResource("static/") + ) + + val server = new Server(port) + val context = new WebAppContext() + context.setContextPath("/") + context.setBaseResource(resources) + + server.setHandler(context) + server.setStopAtShutdown(true) + server.start() + */ +} diff --git a/src/main/scala/developerstream/Db.scala b/src/main/scala/developerstream/Db.scala new file mode 100644 index 0000000..4ddd129 --- /dev/null +++ b/src/main/scala/developerstream/Db.scala @@ -0,0 +1,30 @@ +package developerstream + +// Import the session management, including the implicit threadLocalSession +import org.scalaquery.session._ +import org.scalaquery.session.Database.threadLocalSession +import org.joda.time.DateTime +import java.util.UUID +import java.net.URL +import java.sql.Timestamp + +// Import the query language +import org.scalaquery.ql._ + +// Import the standard SQL types +import org.scalaquery.ql.TypeMapper._ + +// Use H2Driver which implements ExtendedProfile and thus requires ExtendedTables +import org.scalaquery.ql.extended.PostgresDriver.Implicit._ +import org.scalaquery.ql.extended.{ExtendedTable => Table} + +object Db { + val JenkinsServer = new Table[(UUID, Timestamp, String, Boolean)]("jenkins_server") { + def uuid = column[UUID]("uuid", O.PrimaryKey) + def created_date = column[Timestamp]("created_date") + def url = column[String]("url") + def enabled = column[Boolean]("enabled") + // Every table needs a * projection with the same type as the table's type parameter + def * = uuid ~ created_date ~ url ~ enabled + } +} diff --git a/src/main/scala/developerstream/DeveloperStreamPlan.scala b/src/main/scala/developerstream/DeveloperStreamPlan.scala new file mode 100644 index 0000000..ff36abc --- /dev/null +++ b/src/main/scala/developerstream/DeveloperStreamPlan.scala @@ -0,0 +1,48 @@ +package developerstream + +import unfiltered.request._ +import unfiltered.response._ +import unfiltered.filter.Plan +import unfiltered.filter.Plan._ +import org.scalaquery.session.{Database, Session} +import org.scalaquery.ql.Query +import org.scalaquery.ql._ +import org.scalaquery.ql.extended.PostgresDriver.Implicit._ +import org.scalaquery.ql.extended.{ExtendedTable => Table} +import xml.Elem + +class DeveloperStreamPlan extends Plan { + + def withSession[T](f: Session => T) = Database.forURL("jdbc:postgresql://localhost/esper", user = "esper", password = "esper") withSession { session => f(session) } + + def intent: Intent = { + case Path("/") => + Ok ~> Html5(<html> + <body> + <h1>Jenkins Servers</h1> + <table> + <thead> + <tr> + <th>URL</th> + <th>Enabled</th> + </tr> + </thead> + {withSession { + implicit session => + val q = for { + server <- Db.JenkinsServer + } yield server.url ~ server.enabled + + q.list map { case (url, enabled) => <tr><td>{url}</td><td>{enabled}</td></tr> } + }} + </table> + </body> + </html>) + } + + val url = "" + val enabled = false + + def server() = + <tr><td>{url}</td><td>{enabled}</td></tr> +} |