[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 | |
---|
| 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) |
---|
[58] | 72 | |
---|
| 73 | //Person |
---|
[59] | 74 | def passwordEncoded = authenticateService.encodePassword("pass") |
---|
| 75 | def personInstance |
---|
[58] | 76 | |
---|
[59] | 77 | personInstance = new Person(loginName:"admin", |
---|
[58] | 78 | firstName:"Admin", |
---|
| 79 | lastName:"Powers", |
---|
[59] | 80 | password:passwordEncoded, |
---|
[58] | 81 | email:"admin@example.com") |
---|
| 82 | BootStrapSaveAndTest(personInstance) |
---|
[59] | 83 | personInstance.addToAuthorities(Authority.get(1)) |
---|
| 84 | personInstance.addToAuthorities(Authority.get(2)) |
---|
[64] | 85 | personInstance.addToPersonGroups(PersonGroup.findByName("gnuMims")) |
---|
[58] | 86 | |
---|
[59] | 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)) |
---|
[64] | 94 | personInstance.addToPersonGroups(PersonGroup.findByName("Electrical")) |
---|
[58] | 95 | |
---|
[59] | 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)) |
---|
[64] | 103 | personInstance.addToPersonGroups(PersonGroup.findByName("Electrical")) |
---|
[58] | 104 | |
---|
[59] | 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)) |
---|
[64] | 112 | personInstance.addToPersonGroups(PersonGroup.findByName("Mechanical")) |
---|
[58] | 113 | |
---|
[59] | 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)) |
---|
[64] | 121 | personInstance.addToPersonGroups(PersonGroup.findByName("Production")) |
---|
[58] | 122 | |
---|
| 123 | //TaskGroup |
---|
| 124 | // new TaskGroup(name:"Engineering", |
---|
| 125 | // description:"Engineering task group").save() |
---|
| 126 | // new TaskGroup(name:"Production", |
---|
| 127 | // description:"Production task group").save() |
---|
| 128 | // new TaskGroup(name:"NewProject(s)", |
---|
| 129 | // description:" ").save() |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | //Task |
---|
| 133 | // new Task(taskGroup:TaskGroup.findByName("Engineering"), |
---|
| 134 | // leadPerson:Person.get(3), |
---|
| 135 | // name:"Check specific level sensor", |
---|
| 136 | // description:"Has been noted as problematic, try recallibrating", |
---|
| 137 | // scheduledDate: new Date(), |
---|
| 138 | // targetDate: new Date() ).save() |
---|
| 139 | // new Task(taskGroup:TaskGroup.findByName("Production"), |
---|
| 140 | // leadPerson:Person.get(5), |
---|
| 141 | // name:"Production Report", |
---|
| 142 | // description:"Production report for specific production run or shift", |
---|
| 143 | // scheduledDate: new Date(), |
---|
| 144 | // targetDate: new Date() ).save() |
---|
| 145 | // new Task(taskGroup:TaskGroup.findByName("NewProject(s)"), |
---|
| 146 | // leadPerson:Person.get(1), |
---|
| 147 | // name:"Make killer CMMS app", |
---|
| 148 | // description:"Use Grails and get a move on!", |
---|
| 149 | // scheduledDate: new Date(), |
---|
| 150 | // targetDate: new Date() ).save() |
---|
| 151 | |
---|
| 152 | //EntryType |
---|
| 153 | // new EntryType(name:"Fault").save() |
---|
| 154 | // new EntryType(name:"WorkDone").save() |
---|
| 155 | // new EntryType(name:"Production Report").save() |
---|
| 156 | |
---|
| 157 | //ModificationType |
---|
| 158 | // new ModificationType(name:"Created").save() |
---|
| 159 | // new ModificationType(name:"Completed").save() |
---|
| 160 | // new ModificationType(name:"Closed").save() |
---|
| 161 | // new ModificationType(name:"Altered").save() |
---|
| 162 | // new ModificationType(name:"TargetDateModified").save() |
---|
| 163 | // new ModificationType(name:"ScheduledDateModified").save() |
---|
| 164 | // new ModificationType(name:"DescriptionModified").save() |
---|
| 165 | // new ModificationType(name:"AssignedToModified").save() |
---|
| 166 | // new ModificationType(name:"NameModified").save() |
---|
| 167 | |
---|
| 168 | if(BootStrapDemoDataSuccessful) { |
---|
| 169 | println "BootStrapping demo data...successful." |
---|
| 170 | } |
---|
| 171 | else println "BootStrapping demo data...failed." |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | void BootStrapSaveAndTest(object) { |
---|
| 175 | if(!object.save()) { |
---|
| 176 | BootStrapDemoDataSuccessful = false |
---|
| 177 | println "'${object}' failed to save!" |
---|
| 178 | println object.errors |
---|
| 179 | |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | } |
---|