forked from timperrett/lift-in-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Boot.scala
95 lines (70 loc) · 3.17 KB
/
Boot.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package bootstrap.liftweb
// framework imports
import net.liftweb.common._
import net.liftweb.util._
import net.liftweb.util.Helpers._
import net.liftweb.http._
import net.liftweb.sitemap._
import net.liftweb.sitemap.Loc._
import net.liftweb.mapper.{DB,Schemifier,DefaultConnectionIdentifier,StandardDBVendor}
// app imports
import example.travel.model.{Auction,Supplier,Customer,Bid,Order,OrderAuction}
// import example.travel.lib.{Helpers}
class Boot extends Loggable {
def boot {
LiftRules.addToPackages("example.travel")
/**** database settings ****/
// set the JNDI name that we'll be using
DefaultConnectionIdentifier.jndiName = "jdbc/liftinaction"
// handle JNDI not being avalible
if (!DB.jndiJdbcConnAvailable_?){
logger.error("No JNDI configured - using the default in-memory database.")
DB.defineConnectionManager(DefaultConnectionIdentifier, Application.database)
// make sure cyote unloads database connections before shutting down
LiftRules.unloadHooks.append(() => Application.database.closeAllConnections_!())
}
// automatically create the tables
Schemifier.schemify(true, Schemifier.infoF _,
Bid, Auction, Supplier, Customer, Order, OrderAuction)
// setup the loan pattern
S.addAround(DB.buildLoanWrapper)
/**** user experience settings ****/
// set the time that notices should be displayed and then fadeout
LiftRules.noticesAutoFadeOut.default.set((notices: NoticeType.Value) => Full(2 seconds, 2 seconds))
LiftRules.loggedInTest = Full(() => Customer.loggedIn_?)
/**** request settings ****/
// set the application sitemap
LiftRules.setSiteMap(SiteMap(Application.sitemap:_*))
// setup the 404 handler
LiftRules.uriNotFound.prepend(NamedPF("404handler"){
case (req,failure) => NotFoundAsTemplate(ParsePath(List("404"),"html",false,false))
})
// make requests utf-8
LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
LiftRules.statelessRewrite.append {
case RewriteRequest(ParsePath("auction" :: key :: Nil,"",true,_),_,_) =>
RewriteResponse("auction" :: Nil, Map("id" -> key.split("-")(0)))
}
logger.debug("DEBUG MODE ENABLED!")
}
}
object Application {
val MustBeLoggedIn = If(() => Customer.loggedIn_?, "")
val sitemap = List(
Menu("Home") / "index" >> LocGroup("public"),
Menu("Auctions") / "auctions" >> LocGroup("public"),
Menu("Search") / "search" >> LocGroup("public") >> MustBeLoggedIn,
Menu("History") / "history" >> LocGroup("public") >> MustBeLoggedIn,
Menu("Auction Detail") / "auction" >> LocGroup("public") >> Hidden,
// admin
Menu("Admin") / "admin" / "index" >> LocGroup("admin"),
Menu("Suppliers") / "admin" / "suppliers" >> LocGroup("admin") submenus(Supplier.menus : _*),
Menu("Auction Admin") / "admin" / "auctions" >> LocGroup("admin") submenus(Auction.menus : _*)
) ::: Customer.menus
val database = DBVendor
object DBVendor extends StandardDBVendor(
Props.get("db.class").openOr("com.mysql.jdbc.Driver"),
Props.get("db.url").openOr("jdbc:mysql://localhost/liftinaction?user=root"),
Props.get("db.user"),
Props.get("db.pass"))
}