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 | //TaskStatus |
---|
124 | def taskStatusInstance |
---|
125 | |
---|
126 | taskStatusInstance = new TaskStatus(name:"Not Started") |
---|
127 | BootStrapSaveAndTest(taskStatusInstance) |
---|
128 | |
---|
129 | taskStatusInstance = new TaskStatus(name:"In Progress") |
---|
130 | BootStrapSaveAndTest(taskStatusInstance) |
---|
131 | |
---|
132 | taskStatusInstance = new TaskStatus(name:"Completed") |
---|
133 | BootStrapSaveAndTest(taskStatusInstance) |
---|
134 | |
---|
135 | //TaskGroup |
---|
136 | def taskGroupInstance |
---|
137 | |
---|
138 | taskGroupInstance = new TaskGroup(name:"Engineering Activites", |
---|
139 | description:"Engineering daily activities") |
---|
140 | BootStrapSaveAndTest(taskGroupInstance) |
---|
141 | |
---|
142 | taskGroupInstance = new TaskGroup(name:"Production Activites", |
---|
143 | description:"Production daily activities") |
---|
144 | BootStrapSaveAndTest(taskGroupInstance) |
---|
145 | |
---|
146 | taskGroupInstance = new TaskGroup(name:"NewProject(s)", |
---|
147 | description:" ") |
---|
148 | BootStrapSaveAndTest(taskGroupInstance) |
---|
149 | |
---|
150 | //Task |
---|
151 | def taskInstance |
---|
152 | |
---|
153 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
154 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
155 | leadPerson:Person.get(3), |
---|
156 | description:"Check specific level sensor", |
---|
157 | comment:"Has been noted as problematic, try recallibrating") |
---|
158 | BootStrapSaveAndTest(taskInstance) |
---|
159 | taskInstance.addToAssignedPersons(Person.get(1)) |
---|
160 | taskInstance.addToAssignedPersons(Person.get(2)) |
---|
161 | |
---|
162 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"), |
---|
163 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
164 | leadPerson:Person.get(5), |
---|
165 | description:"Production Report", |
---|
166 | comment:"Production report for specific production run or shift") |
---|
167 | BootStrapSaveAndTest(taskInstance) |
---|
168 | |
---|
169 | taskInstance = new Task(taskGroup:TaskGroup.findByName("NewProject(s)"), |
---|
170 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
171 | leadPerson:Person.get(1), |
---|
172 | description:"Make killer CMMS app", |
---|
173 | comment:"Use Grails and get a move on!") |
---|
174 | BootStrapSaveAndTest(taskInstance) |
---|
175 | |
---|
176 | //EntryType |
---|
177 | def entryTypeInstance |
---|
178 | |
---|
179 | entryTypeInstance = new EntryType(name:"Fault") |
---|
180 | BootStrapSaveAndTest(entryTypeInstance) |
---|
181 | |
---|
182 | entryTypeInstance = new EntryType(name:"WorkDone") |
---|
183 | BootStrapSaveAndTest(entryTypeInstance) |
---|
184 | |
---|
185 | entryTypeInstance = new EntryType(name:"Production Report") |
---|
186 | BootStrapSaveAndTest(entryTypeInstance) |
---|
187 | |
---|
188 | entryTypeInstance = new EntryType(name:"Work Request") |
---|
189 | BootStrapSaveAndTest(entryTypeInstance) |
---|
190 | |
---|
191 | //ModificationType |
---|
192 | def modificationTypeInstance |
---|
193 | modificationTypeInstance = new ModificationType(name:"Created").save() |
---|
194 | modificationTypeInstance = new ModificationType(name:"Completed").save() |
---|
195 | modificationTypeInstance = new ModificationType(name:"Closed").save() |
---|
196 | modificationTypeInstance = new ModificationType(name:"Altered").save() |
---|
197 | modificationTypeInstance = new ModificationType(name:"TargetDateModified").save() |
---|
198 | modificationTypeInstance = new ModificationType(name:"ScheduledDateModified").save() |
---|
199 | modificationTypeInstance = new ModificationType(name:"DescriptionModified").save() |
---|
200 | modificationTypeInstance = new ModificationType(name:"AssignedToModified").save() |
---|
201 | modificationTypeInstance = new ModificationType(name:"NameModified").save() |
---|
202 | |
---|
203 | if(BootStrapDemoDataSuccessful) { |
---|
204 | println "BootStrapping demo data...successful." |
---|
205 | } |
---|
206 | else println "BootStrapping demo data...failed." |
---|
207 | } |
---|
208 | |
---|
209 | void BootStrapSaveAndTest(object) { |
---|
210 | if(!object.save()) { |
---|
211 | BootStrapDemoDataSuccessful = false |
---|
212 | println "'${object}' failed to save!" |
---|
213 | println object.errors |
---|
214 | |
---|
215 | } |
---|
216 | } |
---|
217 | } |
---|