summaryrefslogtreecommitdiff
path: root/src/main/scala
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-12-10 16:35:33 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-12-10 16:35:33 +0100
commit3e41859789c644a59334da6a07157aa0f1e0138f (patch)
tree952a0b6506aba50bf5143bd657a2cb872fb9ad55 /src/main/scala
downloaddeveloperstream-web-master.tar.gz
developerstream-web-master.tar.bz2
developerstream-web-master.tar.xz
developerstream-web-master.zip
Diffstat (limited to 'src/main/scala')
-rw-r--r--src/main/scala/Web.scala25
-rw-r--r--src/main/scala/developerstream/Db.scala30
-rw-r--r--src/main/scala/developerstream/DeveloperStreamPlan.scala48
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>
+}