| [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 | |
|---|
| [71] | 65 | authInstance = new Authority(description:"Application Admin, grants full admin access to the application.", |
|---|
| 66 | authority:"ROLE_AppAdmin") |
|---|
| [59] | 67 | BootStrapSaveAndTest(authInstance) |
|---|
| 68 | |
|---|
| [71] | 69 | authInstance = new Authority(description:"Application User, all application users need this base role.", |
|---|
| 70 | authority:"ROLE_AppUser") |
|---|
| [59] | 71 | BootStrapSaveAndTest(authInstance) |
|---|
| [58] | 72 | |
|---|
| 73 | //Person |
|---|
| [73] | 74 | def passClearText = "pass" |
|---|
| 75 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
|---|
| [59] | 76 | def personInstance |
|---|
| [58] | 77 | |
|---|
| [59] | 78 | personInstance = new Person(loginName:"admin", |
|---|
| [58] | 79 | firstName:"Admin", |
|---|
| 80 | lastName:"Powers", |
|---|
| [73] | 81 | pass:passClearText, |
|---|
| [59] | 82 | password:passwordEncoded, |
|---|
| [58] | 83 | email:"admin@example.com") |
|---|
| 84 | BootStrapSaveAndTest(personInstance) |
|---|
| [59] | 85 | personInstance.addToAuthorities(Authority.get(1)) |
|---|
| 86 | personInstance.addToAuthorities(Authority.get(2)) |
|---|
| [66] | 87 | personInstance.addToPersonGroups(PersonGroup.findByName("gnuMims")) |
|---|
| [58] | 88 | |
|---|
| [73] | 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 | |
|---|
| [59] | 100 | personInstance = new Person(loginName:"user", |
|---|
| 101 | firstName:"Demo", |
|---|
| 102 | lastName:"Danza", |
|---|
| [73] | 103 | pass:passClearText, |
|---|
| [59] | 104 | password:passwordEncoded, |
|---|
| 105 | email:"user@example.com") |
|---|
| 106 | BootStrapSaveAndTest(personInstance) |
|---|
| 107 | personInstance.addToAuthorities(Authority.get(2)) |
|---|
| [66] | 108 | personInstance.addToPersonGroups(PersonGroup.findByName("Electrical")) |
|---|
| [58] | 109 | |
|---|
| [59] | 110 | personInstance = new Person(loginName:"craig", |
|---|
| 111 | firstName:"Craig", |
|---|
| 112 | lastName:"SuperTech", |
|---|
| [73] | 113 | pass:passClearText, |
|---|
| [59] | 114 | password:passwordEncoded, |
|---|
| 115 | email:"user@example.com") |
|---|
| 116 | BootStrapSaveAndTest(personInstance) |
|---|
| 117 | personInstance.addToAuthorities(Authority.get(2)) |
|---|
| [66] | 118 | personInstance.addToPersonGroups(PersonGroup.findByName("Electrical")) |
|---|
| [58] | 119 | |
|---|
| [73] | 120 | personInstance = new Person(loginName:"john", |
|---|
| 121 | firstName:"John", |
|---|
| [59] | 122 | lastName:"Samples", |
|---|
| [73] | 123 | pass:passClearText, |
|---|
| [59] | 124 | password:passwordEncoded, |
|---|
| 125 | email:"user@example.com") |
|---|
| 126 | BootStrapSaveAndTest(personInstance) |
|---|
| 127 | personInstance.addToAuthorities(Authority.get(2)) |
|---|
| [66] | 128 | personInstance.addToPersonGroups(PersonGroup.findByName("Mechanical")) |
|---|
| [58] | 129 | |
|---|
| [59] | 130 | personInstance = new Person(loginName:"mann", |
|---|
| 131 | firstName:"Production", |
|---|
| 132 | lastName:"Mann", |
|---|
| [73] | 133 | pass:passClearText, |
|---|
| [59] | 134 | password:passwordEncoded, |
|---|
| 135 | email:"user@example.com") |
|---|
| 136 | BootStrapSaveAndTest(personInstance) |
|---|
| 137 | personInstance.addToAuthorities(Authority.get(2)) |
|---|
| [66] | 138 | personInstance.addToPersonGroups(PersonGroup.findByName("Production")) |
|---|
| 139 | |
|---|
| [69] | 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 | |
|---|
| [66] | 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 | |
|---|
| [69] | 167 | //TaskPriority |
|---|
| 168 | def taskPriorityInstance |
|---|
| [66] | 169 | |
|---|
| [69] | 170 | taskPriorityInstance = new TaskPriority(name:"Low") |
|---|
| 171 | BootStrapSaveAndTest(taskPriorityInstance) |
|---|
| [66] | 172 | |
|---|
| [69] | 173 | taskPriorityInstance = new TaskPriority(name:"Normal") |
|---|
| 174 | BootStrapSaveAndTest(taskPriorityInstance) |
|---|
| [66] | 175 | |
|---|
| [69] | 176 | taskPriorityInstance = new TaskPriority(name:"High") |
|---|
| 177 | BootStrapSaveAndTest(taskPriorityInstance) |
|---|
| [66] | 178 | |
|---|
| [69] | 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 | |
|---|
| [58] | 200 | //Task |
|---|
| [66] | 201 | def taskInstance |
|---|
| [69] | 202 | def subTaskInstance |
|---|
| [58] | 203 | |
|---|
| [66] | 204 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
|---|
| 205 | taskStatus:TaskStatus.findByName("Not Started"), |
|---|
| [69] | 206 | taskPriority:TaskPriority.get(2), |
|---|
| 207 | taskType:TaskType.get(1), |
|---|
| [66] | 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 | |
|---|
| [69] | 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 | |
|---|
| [66] | 229 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"), |
|---|
| 230 | taskStatus:TaskStatus.findByName("Not Started"), |
|---|
| [69] | 231 | taskPriority:TaskPriority.get(2), |
|---|
| 232 | taskType:TaskType.get(5), |
|---|
| [66] | 233 | leadPerson:Person.get(5), |
|---|
| 234 | description:"Production Report", |
|---|
| 235 | comment:"Production report for specific production run or shift") |
|---|
| 236 | BootStrapSaveAndTest(taskInstance) |
|---|
| 237 | |
|---|
| [69] | 238 | taskInstance = new Task(taskGroup:TaskGroup.findByName("New Projects"), |
|---|
| [66] | 239 | taskStatus:TaskStatus.findByName("Not Started"), |
|---|
| [69] | 240 | taskPriority:TaskPriority.get(2), |
|---|
| 241 | taskType:TaskType.get(3), |
|---|
| [66] | 242 | leadPerson:Person.get(1), |
|---|
| 243 | description:"Make killer CMMS app", |
|---|
| 244 | comment:"Use Grails and get a move on!") |
|---|
| 245 | BootStrapSaveAndTest(taskInstance) |
|---|
| 246 | |
|---|
| [58] | 247 | //EntryType |
|---|
| [66] | 248 | def entryTypeInstance |
|---|
| [58] | 249 | |
|---|
| [66] | 250 | entryTypeInstance = new EntryType(name:"Fault") |
|---|
| 251 | BootStrapSaveAndTest(entryTypeInstance) |
|---|
| 252 | |
|---|
| 253 | entryTypeInstance = new EntryType(name:"WorkDone") |
|---|
| 254 | BootStrapSaveAndTest(entryTypeInstance) |
|---|
| 255 | |
|---|
| [69] | 256 | entryTypeInstance = new EntryType(name:"Production Note") |
|---|
| [66] | 257 | BootStrapSaveAndTest(entryTypeInstance) |
|---|
| 258 | |
|---|
| 259 | entryTypeInstance = new EntryType(name:"Work Request") |
|---|
| 260 | BootStrapSaveAndTest(entryTypeInstance) |
|---|
| 261 | |
|---|
| [58] | 262 | //ModificationType |
|---|
| [66] | 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() |
|---|
| [58] | 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 | } |
|---|