source: branches/TaskRewrite/src/grails-app/conf/BootStrap.groovy @ 59

Last change on this file since 59 was 59, checked in by gav, 15 years ago

Lots of changes to setup Acegi, should be complete with all current pages secured.
Added CSS and PersonGroup? and PersonGroupType?.
Adjust BootStrap? to suite.
Add Home and Admin pages.

File size: 6.4 KB
Line 
1import grails.util.GrailsUtil
2
3class BootStrap 
4{
5    //Required to be right here for Acegi plugin.
6    def authenticateService
7    Boolean BootStrapDemoDataSuccessful = true
8
9    def init = { servletContext ->
10
11    println "**** BootStrap GrailsUtil.environment = ${GrailsUtil.environment}"
12   
13        switch (GrailsUtil.environment)
14        {
15            case "development":
16                        bootStrapDemoData()
17                        break
18            case "test":
19                        break
20            case "production":
21                        bootStrapDemoData()
22                        break 
23        }
24   
25    }
26
27    def destroy = {
28    }
29
30    //Insert some demo/startup data.
31    void bootStrapDemoData()
32    {
33        println "BootStrapping demo data..."
34   
35        //TypeOfPersonGroup
36//         new PersonGroupType(name:"Department").save()
37//         new PersonGroupType(name:"Contractor").save()
38//         new PersonGroupType(name:"ProjectTeam").save()
39   
40        //PersonGroup
41//         new PersonGroup(personGroupType:PersonGroupType.findByName("Department"),
42//                         name:"Electrical").save()
43//         new PersonGroup(personGroupType:PersonGroupType.get(2),
44//                         name:"Kewl AirCon Guys").save()
45//         new PersonGroup(personGroupType:PersonGroupType.get(3),
46//                         name:"gnuMims").save()
47
48        //Authority
49        def authInstance
50
51        authInstance = new Authority(description:"Application Admin",
52                                        authority:"ROLE_ADMIN")
53        BootStrapSaveAndTest(authInstance)
54
55        authInstance = new Authority(description:"Application Admin",
56                                        authority:"ROLE_USER")
57        BootStrapSaveAndTest(authInstance)
58           
59        //Person
60        def passwordEncoded = authenticateService.encodePassword("pass")
61        def personInstance
62
63        personInstance = new Person(loginName:"admin",
64                                    firstName:"Admin",
65                                    lastName:"Powers",
66                                    password:passwordEncoded,
67                                    email:"admin@example.com")
68        BootStrapSaveAndTest(personInstance)
69        personInstance.addToAuthorities(Authority.get(1))
70        personInstance.addToAuthorities(Authority.get(2))
71
72        personInstance = new Person(loginName:"user",
73                                    firstName:"Demo",
74                                    lastName:"Danza",
75                                    password:passwordEncoded,
76                                    email:"user@example.com")
77        BootStrapSaveAndTest(personInstance)
78        personInstance.addToAuthorities(Authority.get(2))
79
80        personInstance = new Person(loginName:"craig",
81                                    firstName:"Craig",
82                                    lastName:"SuperTech",
83                                    password:passwordEncoded,
84                                    email:"user@example.com")
85        BootStrapSaveAndTest(personInstance)
86        personInstance.addToAuthorities(Authority.get(2))
87
88        personInstance = new Person(loginName:"joe",
89                                    firstName:"Joe",
90                                    lastName:"Samples",
91                                    password:passwordEncoded,
92                                    email:"user@example.com")
93        BootStrapSaveAndTest(personInstance)
94        personInstance.addToAuthorities(Authority.get(2))
95
96        personInstance = new Person(loginName:"mann",
97                                    firstName:"Production",
98                                    lastName:"Mann",
99                                    password:passwordEncoded,
100                                    email:"user@example.com")
101        BootStrapSaveAndTest(personInstance)
102        personInstance.addToAuthorities(Authority.get(2))
103
104               
105        //TaskGroup
106//         new TaskGroup(name:"Engineering",
107//                       description:"Engineering task group").save()
108//         new TaskGroup(name:"Production",
109//                       description:"Production task group").save()
110//         new TaskGroup(name:"NewProject(s)",
111//                       description:" ").save()
112                     
113       
114        //Task
115//         new Task(taskGroup:TaskGroup.findByName("Engineering"),
116//                  leadPerson:Person.get(3),
117//                  name:"Check specific level sensor",
118//                  description:"Has been noted as problematic, try recallibrating",
119//                  scheduledDate: new Date(),
120//                  targetDate: new Date() ).save()
121//         new Task(taskGroup:TaskGroup.findByName("Production"),
122//                  leadPerson:Person.get(5),
123//                  name:"Production Report",
124//                  description:"Production report for specific production run or shift",
125//                  scheduledDate: new Date(),
126//                  targetDate: new Date() ).save()
127//         new Task(taskGroup:TaskGroup.findByName("NewProject(s)"),
128//                  leadPerson:Person.get(1),
129//                  name:"Make killer CMMS app",
130//                  description:"Use Grails and get a move on!",
131//                  scheduledDate: new Date(),
132//                  targetDate: new Date() ).save()
133
134        //EntryType
135//         new EntryType(name:"Fault").save()
136//         new EntryType(name:"WorkDone").save()
137//         new EntryType(name:"Production Report").save()
138
139        //ModificationType
140//         new ModificationType(name:"Created").save()
141//         new ModificationType(name:"Completed").save()
142//         new ModificationType(name:"Closed").save()
143//         new ModificationType(name:"Altered").save()
144//         new ModificationType(name:"TargetDateModified").save()
145//         new ModificationType(name:"ScheduledDateModified").save()
146//         new ModificationType(name:"DescriptionModified").save()
147//         new ModificationType(name:"AssignedToModified").save()
148//         new ModificationType(name:"NameModified").save()
149       
150        if(BootStrapDemoDataSuccessful) {
151            println "BootStrapping demo data...successful."
152        }
153        else println "BootStrapping demo data...failed."
154    }
155   
156    void BootStrapSaveAndTest(object) {
157        if(!object.save()) {
158            BootStrapDemoDataSuccessful = false
159            println "'${object}' failed to save!"
160            println object.errors
161
162        }
163    } 
164}
Note: See TracBrowser for help on using the repository browser.