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