[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 |
---|
| 36 | // new PersonGroupType(name:"Department").save() |
---|
| 37 | // new PersonGroupType(name:"Contractor").save() |
---|
| 38 | // new PersonGroupType(name:"ProjectTeam").save() |
---|
| 39 | |
---|
| 40 | //PersonGroup |
---|
| 41 | // new PersonGroup(personGroupType:PersonGroupType.findByName("Department"), |
---|
| 42 | // name:"Electrical").save() |
---|
| 43 | // new PersonGroup(personGroupType:PersonGroupType.get(2), |
---|
| 44 | // name:"Kewl AirCon Guys").save() |
---|
| 45 | // new PersonGroup(personGroupType:PersonGroupType.get(3), |
---|
| 46 | // name:"gnuMims").save() |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | //Person |
---|
| 50 | // def passwordEncoded = authenticateService.encodePassword("pass") |
---|
| 51 | |
---|
| 52 | def personInstance = new Person(loginName:"admin", |
---|
| 53 | firstName:"Admin", |
---|
| 54 | lastName:"Powers", |
---|
| 55 | password:authenticateService.encodePassword("pass"), |
---|
| 56 | email:"admin@example.com") |
---|
| 57 | BootStrapSaveAndTest(personInstance) |
---|
| 58 | |
---|
| 59 | //Role |
---|
| 60 | def authInstance = new Authority(description:"Application Admin", |
---|
| 61 | authority:"ROLE_ADMIN") |
---|
| 62 | authInstance.addToPersons(personInstance) |
---|
| 63 | authInstance.save() |
---|
| 64 | |
---|
| 65 | // new Person(username:"admin", |
---|
| 66 | // userRealName:"Admin Powers", |
---|
| 67 | // enabled:true, |
---|
| 68 | // |
---|
| 69 | // new Person(personGroup:PersonGroup.get(3), |
---|
| 70 | // firstName:"Admin", |
---|
| 71 | // lastName:"Powers", |
---|
| 72 | // userId:"admin", |
---|
| 73 | // password:"pass").save() |
---|
| 74 | // new Person(personGroup:PersonGroup.get(1), |
---|
| 75 | // firstName:"Demo", |
---|
| 76 | // lastName:"Danza", |
---|
| 77 | // userId:"user", |
---|
| 78 | // password:"pass").save() |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | // new Person(personGroup:PersonGroup.get(1), |
---|
| 82 | // firstName:"Craig", |
---|
| 83 | // lastName:"SuperTech", |
---|
| 84 | // userId:"craig", |
---|
| 85 | // password:"pass").save() |
---|
| 86 | // new Person(personGroup:PersonGroup.get(2), |
---|
| 87 | // firstName:"Joe", |
---|
| 88 | // lastName:"Samples", |
---|
| 89 | // userId:"joe", |
---|
| 90 | // password:"pass").save() |
---|
| 91 | // new Person(personGroup:PersonGroup.get(1), |
---|
| 92 | // firstName:"Production", |
---|
| 93 | // lastName:"Mann", |
---|
| 94 | // userId:"Mann", |
---|
| 95 | // password:"pass").save() |
---|
| 96 | |
---|
| 97 | //TaskGroup |
---|
| 98 | // new TaskGroup(name:"Engineering", |
---|
| 99 | // description:"Engineering task group").save() |
---|
| 100 | // new TaskGroup(name:"Production", |
---|
| 101 | // description:"Production task group").save() |
---|
| 102 | // new TaskGroup(name:"NewProject(s)", |
---|
| 103 | // description:" ").save() |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | //Task |
---|
| 107 | // new Task(taskGroup:TaskGroup.findByName("Engineering"), |
---|
| 108 | // leadPerson:Person.get(3), |
---|
| 109 | // name:"Check specific level sensor", |
---|
| 110 | // description:"Has been noted as problematic, try recallibrating", |
---|
| 111 | // scheduledDate: new Date(), |
---|
| 112 | // targetDate: new Date() ).save() |
---|
| 113 | // new Task(taskGroup:TaskGroup.findByName("Production"), |
---|
| 114 | // leadPerson:Person.get(5), |
---|
| 115 | // name:"Production Report", |
---|
| 116 | // description:"Production report for specific production run or shift", |
---|
| 117 | // scheduledDate: new Date(), |
---|
| 118 | // targetDate: new Date() ).save() |
---|
| 119 | // new Task(taskGroup:TaskGroup.findByName("NewProject(s)"), |
---|
| 120 | // leadPerson:Person.get(1), |
---|
| 121 | // name:"Make killer CMMS app", |
---|
| 122 | // description:"Use Grails and get a move on!", |
---|
| 123 | // scheduledDate: new Date(), |
---|
| 124 | // targetDate: new Date() ).save() |
---|
| 125 | |
---|
| 126 | //EntryType |
---|
| 127 | // new EntryType(name:"Fault").save() |
---|
| 128 | // new EntryType(name:"WorkDone").save() |
---|
| 129 | // new EntryType(name:"Production Report").save() |
---|
| 130 | |
---|
| 131 | //ModificationType |
---|
| 132 | // new ModificationType(name:"Created").save() |
---|
| 133 | // new ModificationType(name:"Completed").save() |
---|
| 134 | // new ModificationType(name:"Closed").save() |
---|
| 135 | // new ModificationType(name:"Altered").save() |
---|
| 136 | // new ModificationType(name:"TargetDateModified").save() |
---|
| 137 | // new ModificationType(name:"ScheduledDateModified").save() |
---|
| 138 | // new ModificationType(name:"DescriptionModified").save() |
---|
| 139 | // new ModificationType(name:"AssignedToModified").save() |
---|
| 140 | // new ModificationType(name:"NameModified").save() |
---|
| 141 | |
---|
| 142 | if(BootStrapDemoDataSuccessful) { |
---|
| 143 | println "BootStrapping demo data...successful." |
---|
| 144 | } |
---|
| 145 | else println "BootStrapping demo data...failed." |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | void BootStrapSaveAndTest(object) { |
---|
| 149 | if(!object.save()) { |
---|
| 150 | BootStrapDemoDataSuccessful = false |
---|
| 151 | println "'${object}' failed to save!" |
---|
| 152 | println object.errors |
---|
| 153 | |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | } |
---|