| 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 | |
|---|
| 218 | subTaskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
|---|
| 219 | taskStatus:TaskStatus.findByName("Not Started"), |
|---|
| 220 | taskPriority:TaskPriority.get(2), |
|---|
| 221 | taskType:TaskType.get(1), |
|---|
| 222 | leadPerson:Person.get(3), |
|---|
| 223 | description:"Some follow up work", |
|---|
| 224 | comment:"Some help required") |
|---|
| 225 | BootStrapSaveAndTest(subTaskInstance) |
|---|
| 226 | |
|---|
| 227 | //Add task 2 as a subTask of task 1. |
|---|
| 228 | taskInstance.addToSubTasks(Task.get(2)) |
|---|
| 229 | subTaskInstance.parentTask = Task.get(1) |
|---|
| 230 | |
|---|
| 231 | subTaskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
|---|
| 232 | taskStatus:TaskStatus.findByName("Not Started"), |
|---|
| 233 | taskPriority:TaskPriority.get(2), |
|---|
| 234 | taskType:TaskType.get(1), |
|---|
| 235 | leadPerson:Person.get(3), |
|---|
| 236 | description:"Replace sensor at next opportunity.", |
|---|
| 237 | comment:"Nothing else has worked.") |
|---|
| 238 | BootStrapSaveAndTest(subTaskInstance) |
|---|
| 239 | |
|---|
| 240 | //Add task 3 as a subTask of task 1. |
|---|
| 241 | taskInstance.addToSubTasks(Task.get(3)) |
|---|
| 242 | subTaskInstance.parentTask = Task.get(1) |
|---|
| 243 | |
|---|
| 244 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"), |
|---|
| 245 | taskStatus:TaskStatus.findByName("Not Started"), |
|---|
| 246 | taskPriority:TaskPriority.get(2), |
|---|
| 247 | taskType:TaskType.get(5), |
|---|
| 248 | leadPerson:Person.get(5), |
|---|
| 249 | description:"Production Report", |
|---|
| 250 | comment:"Production report for specific production run or shift") |
|---|
| 251 | BootStrapSaveAndTest(taskInstance) |
|---|
| 252 | |
|---|
| 253 | taskInstance = new Task(taskGroup:TaskGroup.findByName("New Projects"), |
|---|
| 254 | taskStatus:TaskStatus.findByName("Not Started"), |
|---|
| 255 | taskPriority:TaskPriority.get(2), |
|---|
| 256 | taskType:TaskType.get(3), |
|---|
| 257 | leadPerson:Person.get(1), |
|---|
| 258 | description:"Make killer CMMS app", |
|---|
| 259 | comment:"Use Grails and get a move on!") |
|---|
| 260 | BootStrapSaveAndTest(taskInstance) |
|---|
| 261 | |
|---|
| 262 | //EntryType |
|---|
| 263 | def entryTypeInstance |
|---|
| 264 | |
|---|
| 265 | entryTypeInstance = new EntryType(name:"Fault") |
|---|
| 266 | BootStrapSaveAndTest(entryTypeInstance) |
|---|
| 267 | |
|---|
| 268 | entryTypeInstance = new EntryType(name:"WorkDone") |
|---|
| 269 | BootStrapSaveAndTest(entryTypeInstance) |
|---|
| 270 | |
|---|
| 271 | entryTypeInstance = new EntryType(name:"Production Note") |
|---|
| 272 | BootStrapSaveAndTest(entryTypeInstance) |
|---|
| 273 | |
|---|
| 274 | entryTypeInstance = new EntryType(name:"Work Request") |
|---|
| 275 | BootStrapSaveAndTest(entryTypeInstance) |
|---|
| 276 | |
|---|
| 277 | //Entry |
|---|
| 278 | def entryInstance |
|---|
| 279 | |
|---|
| 280 | entryInstance = new Entry(enteredBy: Person.get(6), |
|---|
| 281 | task: Task.get(1), |
|---|
| 282 | entryType: EntryType.findByName("Fault"), |
|---|
| 283 | comment: "This level sensor is causing us trouble.", |
|---|
| 284 | durationMinute: 20) |
|---|
| 285 | BootStrapSaveAndTest(entryInstance) |
|---|
| 286 | |
|---|
| 287 | entryInstance = new Entry(enteredBy: Person.get(4), |
|---|
| 288 | task: Task.get(1), |
|---|
| 289 | entryType: EntryType.findByName("WorkDone"), |
|---|
| 290 | comment: "Cleaned sensor, see how it goes.", |
|---|
| 291 | durationMinute: 30) |
|---|
| 292 | BootStrapSaveAndTest(entryInstance) |
|---|
| 293 | |
|---|
| 294 | entryInstance = new Entry(enteredBy: Person.get(4), |
|---|
| 295 | task: Task.get(1), |
|---|
| 296 | entryType: EntryType.findByName("WorkDone"), |
|---|
| 297 | comment: "Checked up on it later and sensor is dropping out intermittently, created subTask to replace sensor.", |
|---|
| 298 | durationMinute: 20) |
|---|
| 299 | BootStrapSaveAndTest(entryInstance) |
|---|
| 300 | |
|---|
| 301 | //ModificationType |
|---|
| 302 | def taskModificationTypeInstance |
|---|
| 303 | taskModificationTypeInstance = new TaskModificationType(name:"Created").save() |
|---|
| 304 | taskModificationTypeInstance = new TaskModificationType(name:"Completed").save() |
|---|
| 305 | taskModificationTypeInstance = new TaskModificationType(name:"Closed").save() |
|---|
| 306 | taskModificationTypeInstance = new TaskModificationType(name:"Altered").save() |
|---|
| 307 | taskModificationTypeInstance = new TaskModificationType(name:"TargetDateModified").save() |
|---|
| 308 | taskModificationTypeInstance = new TaskModificationType(name:"ScheduledDateModified").save() |
|---|
| 309 | taskModificationTypeInstance = new TaskModificationType(name:"DescriptionModified").save() |
|---|
| 310 | taskModificationTypeInstance = new TaskModificationType(name:"AssignedToModified").save() |
|---|
| 311 | taskModificationTypeInstance = new TaskModificationType(name:"NameModified").save() |
|---|
| 312 | |
|---|
| 313 | //AssignedPerson |
|---|
| 314 | def assignedPersonInstance |
|---|
| 315 | |
|---|
| 316 | assignedPersonInstance = new AssignedPerson(person: Person.get(4), |
|---|
| 317 | task: Task.get(1), |
|---|
| 318 | estimatedHour: 1, |
|---|
| 319 | estimatedMinute: 20) |
|---|
| 320 | BootStrapSaveAndTest(assignedPersonInstance) |
|---|
| 321 | |
|---|
| 322 | assignedPersonInstance = new AssignedPerson(person: Person.get(5), |
|---|
| 323 | task: Task.get(1), |
|---|
| 324 | estimatedHour: 3, |
|---|
| 325 | estimatedMinute: 30) |
|---|
| 326 | BootStrapSaveAndTest(assignedPersonInstance) |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | //Finally did it all work. |
|---|
| 330 | if(BootStrapDemoDataSuccessful) { |
|---|
| 331 | println "BootStrapping demo data...successful." |
|---|
| 332 | } |
|---|
| 333 | else println "BootStrapping demo data...failed." |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | void BootStrapSaveAndTest(object) { |
|---|
| 337 | if(!object.save()) { |
|---|
| 338 | BootStrapDemoDataSuccessful = false |
|---|
| 339 | println "'${object}' failed to save!" |
|---|
| 340 | println object.errors |
|---|
| 341 | |
|---|
| 342 | } |
|---|
| 343 | } |
|---|
| 344 | } |
|---|