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