1 | import grails.util.GrailsUtil |
---|
2 | |
---|
3 | class 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 | def personGroupTypeInstance |
---|
37 | personGroupTypeInstance = new PersonGroupType(name:"Department") |
---|
38 | BootStrapSaveAndTest(personGroupTypeInstance) |
---|
39 | personGroupTypeInstance = new PersonGroupType(name:"Contractor") |
---|
40 | BootStrapSaveAndTest(personGroupTypeInstance) |
---|
41 | personGroupTypeInstance = new PersonGroupType(name:"ProjectTeam") |
---|
42 | BootStrapSaveAndTest(personGroupTypeInstance) |
---|
43 | |
---|
44 | //PersonGroup |
---|
45 | def personGroupInstance |
---|
46 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.findByName("Department"), |
---|
47 | name:"Electrical") |
---|
48 | BootStrapSaveAndTest(personGroupInstance) |
---|
49 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.findByName("Department"), |
---|
50 | name:"Mechanical") |
---|
51 | BootStrapSaveAndTest(personGroupInstance) |
---|
52 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.findByName("Department"), |
---|
53 | name:"Production") |
---|
54 | BootStrapSaveAndTest(personGroupInstance) |
---|
55 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(2), |
---|
56 | name:"Kewl AirCon Guys") |
---|
57 | BootStrapSaveAndTest(personGroupInstance) |
---|
58 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(3), |
---|
59 | name:"gnuMims") |
---|
60 | BootStrapSaveAndTest(personGroupInstance) |
---|
61 | |
---|
62 | //Authority |
---|
63 | def authInstance |
---|
64 | |
---|
65 | authInstance = new Authority(description:"Application Admin, grants full admin access to the application.", |
---|
66 | authority:"ROLE_AppAdmin") |
---|
67 | BootStrapSaveAndTest(authInstance) |
---|
68 | |
---|
69 | authInstance = new Authority(description:"Application User, all application users need this base role.", |
---|
70 | authority:"ROLE_AppUser") |
---|
71 | BootStrapSaveAndTest(authInstance) |
---|
72 | |
---|
73 | //Person |
---|
74 | def passClearText = "pass" |
---|
75 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
---|
76 | def personInstance |
---|
77 | |
---|
78 | personInstance = new Person(loginName:"admin", |
---|
79 | firstName:"Admin", |
---|
80 | lastName:"Powers", |
---|
81 | pass:passClearText, |
---|
82 | password:passwordEncoded, |
---|
83 | email:"admin@example.com") |
---|
84 | BootStrapSaveAndTest(personInstance) |
---|
85 | personInstance.addToAuthorities(Authority.get(1)) |
---|
86 | personInstance.addToAuthorities(Authority.get(2)) |
---|
87 | personInstance.addToPersonGroups(PersonGroup.findByName("gnuMims")) |
---|
88 | |
---|
89 | personInstance = new Person(loginName:"admin2", |
---|
90 | firstName:"Admin2", |
---|
91 | lastName:"Powers2", |
---|
92 | pass:passClearText, |
---|
93 | password:passwordEncoded, |
---|
94 | email:"admin2@example.com") |
---|
95 | BootStrapSaveAndTest(personInstance) |
---|
96 | personInstance.addToAuthorities(Authority.get(1)) |
---|
97 | personInstance.addToAuthorities(Authority.get(2)) |
---|
98 | personInstance.addToPersonGroups(PersonGroup.findByName("gnuMims")) |
---|
99 | |
---|
100 | personInstance = new Person(loginName:"user", |
---|
101 | firstName:"Demo", |
---|
102 | lastName:"Danza", |
---|
103 | pass:passClearText, |
---|
104 | password:passwordEncoded, |
---|
105 | email:"user@example.com") |
---|
106 | BootStrapSaveAndTest(personInstance) |
---|
107 | personInstance.addToAuthorities(Authority.get(2)) |
---|
108 | personInstance.addToPersonGroups(PersonGroup.findByName("Electrical")) |
---|
109 | |
---|
110 | personInstance = new Person(loginName:"craig", |
---|
111 | firstName:"Craig", |
---|
112 | lastName:"SuperTech", |
---|
113 | pass:passClearText, |
---|
114 | password:passwordEncoded, |
---|
115 | email:"user@example.com") |
---|
116 | BootStrapSaveAndTest(personInstance) |
---|
117 | personInstance.addToAuthorities(Authority.get(2)) |
---|
118 | personInstance.addToPersonGroups(PersonGroup.findByName("Electrical")) |
---|
119 | |
---|
120 | personInstance = new Person(loginName:"john", |
---|
121 | firstName:"John", |
---|
122 | lastName:"Samples", |
---|
123 | pass:passClearText, |
---|
124 | password:passwordEncoded, |
---|
125 | email:"user@example.com") |
---|
126 | BootStrapSaveAndTest(personInstance) |
---|
127 | personInstance.addToAuthorities(Authority.get(2)) |
---|
128 | personInstance.addToPersonGroups(PersonGroup.findByName("Mechanical")) |
---|
129 | |
---|
130 | personInstance = new Person(loginName:"mann", |
---|
131 | firstName:"Production", |
---|
132 | lastName:"Mann", |
---|
133 | pass:passClearText, |
---|
134 | password:passwordEncoded, |
---|
135 | email:"user@example.com") |
---|
136 | BootStrapSaveAndTest(personInstance) |
---|
137 | personInstance.addToAuthorities(Authority.get(2)) |
---|
138 | personInstance.addToPersonGroups(PersonGroup.findByName("Production")) |
---|
139 | |
---|
140 | //TaskGroup |
---|
141 | def taskGroupInstance |
---|
142 | |
---|
143 | taskGroupInstance = new TaskGroup(name:"Engineering Activites", |
---|
144 | description:"Engineering daily activities") |
---|
145 | BootStrapSaveAndTest(taskGroupInstance) |
---|
146 | |
---|
147 | taskGroupInstance = new TaskGroup(name:"Production Activites", |
---|
148 | description:"Production daily activities") |
---|
149 | BootStrapSaveAndTest(taskGroupInstance) |
---|
150 | |
---|
151 | taskGroupInstance = new TaskGroup(name:"New Projects", |
---|
152 | description:" ") |
---|
153 | BootStrapSaveAndTest(taskGroupInstance) |
---|
154 | |
---|
155 | //TaskStatus |
---|
156 | def taskStatusInstance |
---|
157 | |
---|
158 | taskStatusInstance = new TaskStatus(name:"Not Started") |
---|
159 | BootStrapSaveAndTest(taskStatusInstance) |
---|
160 | |
---|
161 | taskStatusInstance = new TaskStatus(name:"In Progress") |
---|
162 | BootStrapSaveAndTest(taskStatusInstance) |
---|
163 | |
---|
164 | taskStatusInstance = new TaskStatus(name:"Completed") |
---|
165 | BootStrapSaveAndTest(taskStatusInstance) |
---|
166 | |
---|
167 | //TaskPriority |
---|
168 | def taskPriorityInstance |
---|
169 | |
---|
170 | taskPriorityInstance = new TaskPriority(name:"Low") |
---|
171 | BootStrapSaveAndTest(taskPriorityInstance) |
---|
172 | |
---|
173 | taskPriorityInstance = new TaskPriority(name:"Normal") |
---|
174 | BootStrapSaveAndTest(taskPriorityInstance) |
---|
175 | |
---|
176 | taskPriorityInstance = new TaskPriority(name:"High") |
---|
177 | BootStrapSaveAndTest(taskPriorityInstance) |
---|
178 | |
---|
179 | taskPriorityInstance = new TaskPriority(name:"Immediate") |
---|
180 | BootStrapSaveAndTest(taskPriorityInstance) |
---|
181 | |
---|
182 | //TaskType |
---|
183 | def taskTypeInstance |
---|
184 | |
---|
185 | taskTypeInstance = new TaskType(name:"Unscheduled Breakin") |
---|
186 | BootStrapSaveAndTest(taskTypeInstance) |
---|
187 | |
---|
188 | taskTypeInstance = new TaskType(name:"Planned Maintenance") |
---|
189 | BootStrapSaveAndTest(taskTypeInstance) |
---|
190 | |
---|
191 | taskTypeInstance = new TaskType(name:"Project") |
---|
192 | BootStrapSaveAndTest(taskTypeInstance) |
---|
193 | |
---|
194 | taskTypeInstance = new TaskType(name:"Turnaround") |
---|
195 | BootStrapSaveAndTest(taskTypeInstance) |
---|
196 | |
---|
197 | taskTypeInstance = new TaskType(name:"Production Run") |
---|
198 | BootStrapSaveAndTest(taskTypeInstance) |
---|
199 | |
---|
200 | //Task |
---|
201 | def taskInstance |
---|
202 | def subTaskInstance |
---|
203 | |
---|
204 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
205 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
206 | taskPriority:TaskPriority.get(2), |
---|
207 | taskType:TaskType.get(1), |
---|
208 | leadPerson:Person.get(3), |
---|
209 | description:"Check specific level sensor", |
---|
210 | comment:"Has been noted as problematic, try recallibrating") |
---|
211 | BootStrapSaveAndTest(taskInstance) |
---|
212 | taskInstance.addToAssignedPersons(Person.get(1)) |
---|
213 | taskInstance.addToAssignedPersons(Person.get(2)) |
---|
214 | |
---|
215 | subTaskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
216 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
217 | taskPriority:TaskPriority.get(2), |
---|
218 | taskType:TaskType.get(1), |
---|
219 | leadPerson:Person.get(3), |
---|
220 | description:"Some follow up work", |
---|
221 | comment:"Some help required") |
---|
222 | BootStrapSaveAndTest(subTaskInstance) |
---|
223 | subTaskInstance.addToAssignedPersons(Person.get(1)) |
---|
224 | |
---|
225 | //Add task 2 as a subTask of task 1. |
---|
226 | taskInstance.addToSubTasks(Task.get(2)) |
---|
227 | subTaskInstance.parentTask = Task.get(1) |
---|
228 | |
---|
229 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"), |
---|
230 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
231 | taskPriority:TaskPriority.get(2), |
---|
232 | taskType:TaskType.get(5), |
---|
233 | leadPerson:Person.get(5), |
---|
234 | description:"Production Report", |
---|
235 | comment:"Production report for specific production run or shift") |
---|
236 | BootStrapSaveAndTest(taskInstance) |
---|
237 | |
---|
238 | taskInstance = new Task(taskGroup:TaskGroup.findByName("New Projects"), |
---|
239 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
240 | taskPriority:TaskPriority.get(2), |
---|
241 | taskType:TaskType.get(3), |
---|
242 | leadPerson:Person.get(1), |
---|
243 | description:"Make killer CMMS app", |
---|
244 | comment:"Use Grails and get a move on!") |
---|
245 | BootStrapSaveAndTest(taskInstance) |
---|
246 | |
---|
247 | //EntryType |
---|
248 | def entryTypeInstance |
---|
249 | |
---|
250 | entryTypeInstance = new EntryType(name:"Fault") |
---|
251 | BootStrapSaveAndTest(entryTypeInstance) |
---|
252 | |
---|
253 | entryTypeInstance = new EntryType(name:"WorkDone") |
---|
254 | BootStrapSaveAndTest(entryTypeInstance) |
---|
255 | |
---|
256 | entryTypeInstance = new EntryType(name:"Production Note") |
---|
257 | BootStrapSaveAndTest(entryTypeInstance) |
---|
258 | |
---|
259 | entryTypeInstance = new EntryType(name:"Work Request") |
---|
260 | BootStrapSaveAndTest(entryTypeInstance) |
---|
261 | |
---|
262 | //ModificationType |
---|
263 | def modificationTypeInstance |
---|
264 | modificationTypeInstance = new ModificationType(name:"Created").save() |
---|
265 | modificationTypeInstance = new ModificationType(name:"Completed").save() |
---|
266 | modificationTypeInstance = new ModificationType(name:"Closed").save() |
---|
267 | modificationTypeInstance = new ModificationType(name:"Altered").save() |
---|
268 | modificationTypeInstance = new ModificationType(name:"TargetDateModified").save() |
---|
269 | modificationTypeInstance = new ModificationType(name:"ScheduledDateModified").save() |
---|
270 | modificationTypeInstance = new ModificationType(name:"DescriptionModified").save() |
---|
271 | modificationTypeInstance = new ModificationType(name:"AssignedToModified").save() |
---|
272 | modificationTypeInstance = new ModificationType(name:"NameModified").save() |
---|
273 | |
---|
274 | if(BootStrapDemoDataSuccessful) { |
---|
275 | println "BootStrapping demo data...successful." |
---|
276 | } |
---|
277 | else println "BootStrapping demo data...failed." |
---|
278 | } |
---|
279 | |
---|
280 | void BootStrapSaveAndTest(object) { |
---|
281 | if(!object.save()) { |
---|
282 | BootStrapDemoDataSuccessful = false |
---|
283 | println "'${object}' failed to save!" |
---|
284 | println object.errors |
---|
285 | |
---|
286 | } |
---|
287 | } |
---|
288 | } |
---|