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:"Business manager, grants full management access.", |
---|
70 | authority:"ROLE_Manager") |
---|
71 | BootStrapSaveAndTest(authInstance) |
---|
72 | |
---|
73 | authInstance = new Authority(description:"Application User, all application users need this base role to allow login.", |
---|
74 | authority:"ROLE_AppUser") |
---|
75 | BootStrapSaveAndTest(authInstance) |
---|
76 | |
---|
77 | //Person |
---|
78 | def passClearText = "pass" |
---|
79 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
---|
80 | def personInstance |
---|
81 | |
---|
82 | personInstance = new Person(loginName:"admin", |
---|
83 | firstName:"Admin", |
---|
84 | lastName:"Powers", |
---|
85 | pass:passClearText, |
---|
86 | password:passwordEncoded, |
---|
87 | email:"admin@example.com") |
---|
88 | BootStrapSaveAndTest(personInstance) |
---|
89 | personInstance.addToAuthorities(Authority.get(1)) |
---|
90 | personInstance.addToAuthorities(Authority.get(2)) |
---|
91 | personInstance.addToAuthorities(Authority.get(3)) |
---|
92 | personInstance.addToPersonGroups(PersonGroup.findByName("gnuMims")) |
---|
93 | |
---|
94 | personInstance = new Person(loginName:"manager", |
---|
95 | firstName:"Meca", |
---|
96 | lastName:"Manager", |
---|
97 | pass:passClearText, |
---|
98 | password:passwordEncoded, |
---|
99 | email:"manager@example.com") |
---|
100 | BootStrapSaveAndTest(personInstance) |
---|
101 | personInstance.addToAuthorities(Authority.get(2)) |
---|
102 | personInstance.addToAuthorities(Authority.get(3)) |
---|
103 | personInstance.addToPersonGroups(PersonGroup.findByName("gnuMims")) |
---|
104 | |
---|
105 | personInstance = new Person(loginName:"user", |
---|
106 | firstName:"Demo", |
---|
107 | lastName:"Danza", |
---|
108 | pass:passClearText, |
---|
109 | password:passwordEncoded, |
---|
110 | email:"user@example.com") |
---|
111 | BootStrapSaveAndTest(personInstance) |
---|
112 | personInstance.addToAuthorities(Authority.get(3)) |
---|
113 | personInstance.addToPersonGroups(PersonGroup.findByName("Electrical")) |
---|
114 | |
---|
115 | personInstance = new Person(loginName:"craig", |
---|
116 | firstName:"Craig", |
---|
117 | lastName:"SuperTech", |
---|
118 | pass:passClearText, |
---|
119 | password:passwordEncoded, |
---|
120 | email:"user@example.com") |
---|
121 | BootStrapSaveAndTest(personInstance) |
---|
122 | personInstance.addToAuthorities(Authority.get(3)) |
---|
123 | personInstance.addToPersonGroups(PersonGroup.findByName("Electrical")) |
---|
124 | |
---|
125 | personInstance = new Person(loginName:"john", |
---|
126 | firstName:"John", |
---|
127 | lastName:"Samples", |
---|
128 | pass:passClearText, |
---|
129 | password:passwordEncoded, |
---|
130 | email:"user@example.com") |
---|
131 | BootStrapSaveAndTest(personInstance) |
---|
132 | personInstance.addToAuthorities(Authority.get(3)) |
---|
133 | personInstance.addToPersonGroups(PersonGroup.findByName("Mechanical")) |
---|
134 | |
---|
135 | personInstance = new Person(loginName:"mann", |
---|
136 | firstName:"Production", |
---|
137 | lastName:"Mann", |
---|
138 | pass:passClearText, |
---|
139 | password:passwordEncoded, |
---|
140 | email:"user@example.com") |
---|
141 | BootStrapSaveAndTest(personInstance) |
---|
142 | personInstance.addToAuthorities(Authority.get(3)) |
---|
143 | personInstance.addToPersonGroups(PersonGroup.findByName("Production")) |
---|
144 | |
---|
145 | //TaskGroup |
---|
146 | def taskGroupInstance |
---|
147 | |
---|
148 | taskGroupInstance = new TaskGroup(name:"Engineering Activites", |
---|
149 | description:"Engineering daily activities") |
---|
150 | BootStrapSaveAndTest(taskGroupInstance) |
---|
151 | |
---|
152 | taskGroupInstance = new TaskGroup(name:"Production Activites", |
---|
153 | description:"Production daily activities") |
---|
154 | BootStrapSaveAndTest(taskGroupInstance) |
---|
155 | |
---|
156 | taskGroupInstance = new TaskGroup(name:"New Projects", |
---|
157 | description:" ") |
---|
158 | BootStrapSaveAndTest(taskGroupInstance) |
---|
159 | |
---|
160 | //TaskStatus |
---|
161 | def taskStatusInstance |
---|
162 | |
---|
163 | taskStatusInstance = new TaskStatus(name:"Not Started") |
---|
164 | BootStrapSaveAndTest(taskStatusInstance) |
---|
165 | |
---|
166 | taskStatusInstance = new TaskStatus(name:"In Progress") |
---|
167 | BootStrapSaveAndTest(taskStatusInstance) |
---|
168 | |
---|
169 | taskStatusInstance = new TaskStatus(name:"Completed") |
---|
170 | BootStrapSaveAndTest(taskStatusInstance) |
---|
171 | |
---|
172 | //TaskPriority |
---|
173 | def taskPriorityInstance |
---|
174 | |
---|
175 | taskPriorityInstance = new TaskPriority(name:"Low") |
---|
176 | BootStrapSaveAndTest(taskPriorityInstance) |
---|
177 | |
---|
178 | taskPriorityInstance = new TaskPriority(name:"Normal") |
---|
179 | BootStrapSaveAndTest(taskPriorityInstance) |
---|
180 | |
---|
181 | taskPriorityInstance = new TaskPriority(name:"High") |
---|
182 | BootStrapSaveAndTest(taskPriorityInstance) |
---|
183 | |
---|
184 | taskPriorityInstance = new TaskPriority(name:"Immediate") |
---|
185 | BootStrapSaveAndTest(taskPriorityInstance) |
---|
186 | |
---|
187 | //TaskType |
---|
188 | def taskTypeInstance |
---|
189 | |
---|
190 | taskTypeInstance = new TaskType(name:"Unscheduled Breakin") |
---|
191 | BootStrapSaveAndTest(taskTypeInstance) |
---|
192 | |
---|
193 | taskTypeInstance = new TaskType(name:"Planned Maintenance") |
---|
194 | BootStrapSaveAndTest(taskTypeInstance) |
---|
195 | |
---|
196 | taskTypeInstance = new TaskType(name:"Project") |
---|
197 | BootStrapSaveAndTest(taskTypeInstance) |
---|
198 | |
---|
199 | taskTypeInstance = new TaskType(name:"Turnaround") |
---|
200 | BootStrapSaveAndTest(taskTypeInstance) |
---|
201 | |
---|
202 | taskTypeInstance = new TaskType(name:"Production Run") |
---|
203 | BootStrapSaveAndTest(taskTypeInstance) |
---|
204 | |
---|
205 | //Task |
---|
206 | def taskInstance |
---|
207 | def subTaskInstance |
---|
208 | |
---|
209 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
210 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
211 | taskPriority:TaskPriority.get(2), |
---|
212 | taskType:TaskType.get(1), |
---|
213 | leadPerson:Person.get(3), |
---|
214 | description:"Check specific level sensor", |
---|
215 | comment:"Has been noted as problematic, try recallibrating") |
---|
216 | BootStrapSaveAndTest(taskInstance) |
---|
217 | taskInstance.addToAssignedPersons(Person.get(1)) |
---|
218 | taskInstance.addToAssignedPersons(Person.get(2)) |
---|
219 | |
---|
220 | subTaskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
221 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
222 | taskPriority:TaskPriority.get(2), |
---|
223 | taskType:TaskType.get(1), |
---|
224 | leadPerson:Person.get(3), |
---|
225 | description:"Some follow up work", |
---|
226 | comment:"Some help required") |
---|
227 | BootStrapSaveAndTest(subTaskInstance) |
---|
228 | subTaskInstance.addToAssignedPersons(Person.get(1)) |
---|
229 | |
---|
230 | //Add task 2 as a subTask of task 1. |
---|
231 | taskInstance.addToSubTasks(Task.get(2)) |
---|
232 | subTaskInstance.parentTask = Task.get(1) |
---|
233 | |
---|
234 | subTaskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
235 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
236 | taskPriority:TaskPriority.get(2), |
---|
237 | taskType:TaskType.get(1), |
---|
238 | leadPerson:Person.get(3), |
---|
239 | description:"Replace sensor at next opportunity.", |
---|
240 | comment:"Nothing else has worked.") |
---|
241 | BootStrapSaveAndTest(subTaskInstance) |
---|
242 | subTaskInstance.addToAssignedPersons(Person.get(1)) |
---|
243 | |
---|
244 | //Add task 3 as a subTask of task 1. |
---|
245 | taskInstance.addToSubTasks(Task.get(3)) |
---|
246 | subTaskInstance.parentTask = Task.get(1) |
---|
247 | |
---|
248 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"), |
---|
249 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
250 | taskPriority:TaskPriority.get(2), |
---|
251 | taskType:TaskType.get(5), |
---|
252 | leadPerson:Person.get(5), |
---|
253 | description:"Production Report", |
---|
254 | comment:"Production report for specific production run or shift") |
---|
255 | BootStrapSaveAndTest(taskInstance) |
---|
256 | |
---|
257 | taskInstance = new Task(taskGroup:TaskGroup.findByName("New Projects"), |
---|
258 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
259 | taskPriority:TaskPriority.get(2), |
---|
260 | taskType:TaskType.get(3), |
---|
261 | leadPerson:Person.get(1), |
---|
262 | description:"Make killer CMMS app", |
---|
263 | comment:"Use Grails and get a move on!") |
---|
264 | BootStrapSaveAndTest(taskInstance) |
---|
265 | |
---|
266 | //EntryType |
---|
267 | def entryTypeInstance |
---|
268 | |
---|
269 | entryTypeInstance = new EntryType(name:"Fault") |
---|
270 | BootStrapSaveAndTest(entryTypeInstance) |
---|
271 | |
---|
272 | entryTypeInstance = new EntryType(name:"WorkDone") |
---|
273 | BootStrapSaveAndTest(entryTypeInstance) |
---|
274 | |
---|
275 | entryTypeInstance = new EntryType(name:"Production Note") |
---|
276 | BootStrapSaveAndTest(entryTypeInstance) |
---|
277 | |
---|
278 | entryTypeInstance = new EntryType(name:"Work Request") |
---|
279 | BootStrapSaveAndTest(entryTypeInstance) |
---|
280 | |
---|
281 | //Entry |
---|
282 | def entryInstance |
---|
283 | |
---|
284 | entryInstance = new Entry(enteredBy: Person.get(6), |
---|
285 | task: Task.get(1), |
---|
286 | entryType: EntryType.findByName("Fault"), |
---|
287 | comment: "This level sensor is causing us trouble.", |
---|
288 | durationMinute: 20) |
---|
289 | BootStrapSaveAndTest(entryInstance) |
---|
290 | |
---|
291 | entryInstance = new Entry(enteredBy: Person.get(4), |
---|
292 | task: Task.get(1), |
---|
293 | entryType: EntryType.findByName("WorkDone"), |
---|
294 | comment: "Cleaned sensor, see how it goes.", |
---|
295 | durationMinute: 30) |
---|
296 | BootStrapSaveAndTest(entryInstance) |
---|
297 | |
---|
298 | entryInstance = new Entry(enteredBy: Person.get(4), |
---|
299 | task: Task.get(1), |
---|
300 | entryType: EntryType.findByName("WorkDone"), |
---|
301 | comment: "Checked up on it later and sensor is dropping out intermittently, created subTask to replace sensor.", |
---|
302 | durationMinute: 20) |
---|
303 | BootStrapSaveAndTest(entryInstance) |
---|
304 | |
---|
305 | //ModificationType |
---|
306 | def taskModificationTypeInstance |
---|
307 | taskModificationTypeInstance = new TaskModificationType(name:"Created").save() |
---|
308 | taskModificationTypeInstance = new TaskModificationType(name:"Completed").save() |
---|
309 | taskModificationTypeInstance = new TaskModificationType(name:"Closed").save() |
---|
310 | taskModificationTypeInstance = new TaskModificationType(name:"Altered").save() |
---|
311 | taskModificationTypeInstance = new TaskModificationType(name:"TargetDateModified").save() |
---|
312 | taskModificationTypeInstance = new TaskModificationType(name:"ScheduledDateModified").save() |
---|
313 | taskModificationTypeInstance = new TaskModificationType(name:"DescriptionModified").save() |
---|
314 | taskModificationTypeInstance = new TaskModificationType(name:"AssignedToModified").save() |
---|
315 | taskModificationTypeInstance = new TaskModificationType(name:"NameModified").save() |
---|
316 | |
---|
317 | if(BootStrapDemoDataSuccessful) { |
---|
318 | println "BootStrapping demo data...successful." |
---|
319 | } |
---|
320 | else println "BootStrapping demo data...failed." |
---|
321 | } |
---|
322 | |
---|
323 | void BootStrapSaveAndTest(object) { |
---|
324 | if(!object.save()) { |
---|
325 | BootStrapDemoDataSuccessful = false |
---|
326 | println "'${object}' failed to save!" |
---|
327 | println object.errors |
---|
328 | |
---|
329 | } |
---|
330 | } |
---|
331 | } |
---|