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