1 | /** |
---|
2 | * Provides a data service to create base and demo data. |
---|
3 | */ |
---|
4 | class CreateDataService { |
---|
5 | |
---|
6 | def authenticateService |
---|
7 | boolean transactional = false |
---|
8 | |
---|
9 | /******************************************* |
---|
10 | Start of Group methods. |
---|
11 | Generally use these methods to create data. |
---|
12 | *******************************************/ |
---|
13 | |
---|
14 | /** |
---|
15 | * Always call this at startup to ensure admin access. |
---|
16 | */ |
---|
17 | def ensureAdminAccess() { |
---|
18 | if(!Authority.findByAuthority("ROLE_AppAdmin") ) { |
---|
19 | println "ROLE_AppAdmin not found, calling createAdminAuthority()." |
---|
20 | createAdminAuthority() |
---|
21 | } |
---|
22 | if(!Person.findByloginName("admin") ) { |
---|
23 | println "LoginName 'admin' not found, calling createAdminPerson()." |
---|
24 | createAdminPerson() |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | /** |
---|
29 | * Create the base data required for the application to function. |
---|
30 | */ |
---|
31 | def createBaseData() { |
---|
32 | println "Creating base data..." |
---|
33 | // Person and Utils |
---|
34 | createBaseAuthorities() |
---|
35 | createBasePersonGroups() |
---|
36 | createBasePersons() |
---|
37 | createBaseUnitsOfMeasure() |
---|
38 | createBasePeriods() |
---|
39 | createBaseSupplierType() |
---|
40 | createBaseManufacturerType() |
---|
41 | // Tasks |
---|
42 | createBaseTaskStatus() |
---|
43 | createBaseTaskPriorities() |
---|
44 | createBaseTaskTypes() |
---|
45 | createBaseEntryTypes() |
---|
46 | createBaseModificationTypes() |
---|
47 | // Inventory |
---|
48 | createBaseInventoryTypes() |
---|
49 | createBaseInventoryMovementTypes() |
---|
50 | createBaseMaintenancePolicies() |
---|
51 | // Assets |
---|
52 | createBaseAssetExtenededAttributeTypes() |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * Create demo data for some example sites. |
---|
58 | */ |
---|
59 | def createDemoData() { |
---|
60 | println "Creating demo data..." |
---|
61 | // Person and Utils |
---|
62 | createDemoPersons() |
---|
63 | createDemoSites() |
---|
64 | createDemoDepartments() |
---|
65 | createDemoSuppliers() |
---|
66 | createDemoManufacturers() |
---|
67 | // Tasks |
---|
68 | createDemoTaskGroups() /// @todo: Perhaps this should be BaseData? |
---|
69 | createDemoTasks() |
---|
70 | createDemoEntries() |
---|
71 | createDemoAssignedPersons() |
---|
72 | createDemoTaskRecurringSchedules() |
---|
73 | // Inventory |
---|
74 | createDemoInventoryStores() /// @todo: Perhaps a 'createQuickStartData' method? |
---|
75 | createDemoInventoryLocations() |
---|
76 | createDemoInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method? |
---|
77 | createDemoInventoryItems() |
---|
78 | // Assets |
---|
79 | createDemoLifePlan() |
---|
80 | createDemoTaskProcedure() |
---|
81 | createDemoMaintenanceActions() |
---|
82 | createDemoSystemSections() |
---|
83 | createDemoAssetTypes() |
---|
84 | createDemoAssemblies() |
---|
85 | createDemoSubAssemblies() |
---|
86 | createDemoComponentItems() |
---|
87 | createDemoAssets() |
---|
88 | createDemoAssetExtenedAttributes() |
---|
89 | } |
---|
90 | |
---|
91 | /****************** |
---|
92 | Start of Person |
---|
93 | *******************/ |
---|
94 | |
---|
95 | def createAdminAuthority() { |
---|
96 | def authInstance |
---|
97 | |
---|
98 | authInstance = new Authority(description:"Application Admin, not required for daily use! Grants full admin access to the application.", |
---|
99 | authority:"ROLE_AppAdmin") |
---|
100 | saveAndTest(authInstance) |
---|
101 | } |
---|
102 | |
---|
103 | def createBaseAuthorities() { |
---|
104 | |
---|
105 | def authInstance |
---|
106 | |
---|
107 | authInstance = new Authority(description:"Business manager, grants full management access.", |
---|
108 | authority:"ROLE_Manager") |
---|
109 | saveAndTest(authInstance) |
---|
110 | |
---|
111 | authInstance = new Authority(description:"Application User, all application users need this base role to allow login.", |
---|
112 | authority:"ROLE_AppUser") |
---|
113 | saveAndTest(authInstance) |
---|
114 | } |
---|
115 | |
---|
116 | void createBasePersonGroups() { |
---|
117 | //TypeOfPersonGroup |
---|
118 | def personGroupTypeInstance |
---|
119 | personGroupTypeInstance = new PersonGroupType(name:"Team") |
---|
120 | saveAndTest(personGroupTypeInstance) |
---|
121 | personGroupTypeInstance = new PersonGroupType(name:"Contractor") |
---|
122 | saveAndTest(personGroupTypeInstance) |
---|
123 | personGroupTypeInstance = new PersonGroupType(name:"ProjectTeam") |
---|
124 | saveAndTest(personGroupTypeInstance) |
---|
125 | |
---|
126 | //PersonGroup |
---|
127 | def personGroupInstance |
---|
128 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1), |
---|
129 | name:"Electrical") |
---|
130 | saveAndTest(personGroupInstance) |
---|
131 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1), |
---|
132 | name:"Mechanical") |
---|
133 | saveAndTest(personGroupInstance) |
---|
134 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1), |
---|
135 | name:"Production") |
---|
136 | saveAndTest(personGroupInstance) |
---|
137 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(2), |
---|
138 | name:"Kewl AirCon Guys") |
---|
139 | saveAndTest(personGroupInstance) |
---|
140 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(3), |
---|
141 | name:"gnuMims") |
---|
142 | saveAndTest(personGroupInstance) |
---|
143 | } |
---|
144 | |
---|
145 | def createAdminPerson() { |
---|
146 | //Person |
---|
147 | def passClearText = "pass" |
---|
148 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
---|
149 | def personInstance |
---|
150 | |
---|
151 | //Person #1 |
---|
152 | personInstance = new Person(loginName:"admin", |
---|
153 | firstName:"Admin", |
---|
154 | lastName:"Powers", |
---|
155 | pass:passClearText, |
---|
156 | password:passwordEncoded, |
---|
157 | email:"admin@example.com") |
---|
158 | saveAndTest(personInstance) |
---|
159 | personInstance.addToAuthorities(Authority.get(1)) |
---|
160 | } |
---|
161 | |
---|
162 | def createBasePersons() { |
---|
163 | //Person |
---|
164 | def passClearText = "pass" |
---|
165 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
---|
166 | def personInstance |
---|
167 | |
---|
168 | //Person #1 is admin. |
---|
169 | |
---|
170 | //Person #2 |
---|
171 | personInstance = new Person(loginName:"manager", |
---|
172 | firstName:"Demo", |
---|
173 | lastName:"Manager", |
---|
174 | pass:passClearText, |
---|
175 | password:passwordEncoded, |
---|
176 | email:"manager@example.com") |
---|
177 | saveAndTest(personInstance) |
---|
178 | personInstance.addToAuthorities(Authority.get(2)) |
---|
179 | personInstance.addToAuthorities(Authority.get(3)) |
---|
180 | personInstance.addToPersonGroups(PersonGroup.get(5)) |
---|
181 | |
---|
182 | //Person #3 |
---|
183 | personInstance = new Person(loginName:"user", |
---|
184 | firstName:"Demo", |
---|
185 | lastName:"User", |
---|
186 | pass:passClearText, |
---|
187 | password:passwordEncoded, |
---|
188 | email:"user@example.com") |
---|
189 | saveAndTest(personInstance) |
---|
190 | personInstance.addToAuthorities(Authority.get(3)) |
---|
191 | personInstance.addToPersonGroups(PersonGroup.get(1)) |
---|
192 | } |
---|
193 | |
---|
194 | def createDemoPersons() { |
---|
195 | //Person |
---|
196 | def passClearText = "pass" |
---|
197 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
---|
198 | def personInstance |
---|
199 | |
---|
200 | //Person #4 |
---|
201 | personInstance = new Person(loginName:"craig", |
---|
202 | firstName:"Craig", |
---|
203 | lastName:"SuperSparky", |
---|
204 | pass:passClearText, |
---|
205 | password:passwordEncoded, |
---|
206 | email:"user@example.com") |
---|
207 | saveAndTest(personInstance) |
---|
208 | personInstance.addToAuthorities(Authority.get(3)) |
---|
209 | personInstance.addToPersonGroups(PersonGroup.get(1)) |
---|
210 | |
---|
211 | //Person #5 |
---|
212 | personInstance = new Person(loginName:"john", |
---|
213 | firstName:"John", |
---|
214 | lastName:"SuperFitter", |
---|
215 | pass:passClearText, |
---|
216 | password:passwordEncoded, |
---|
217 | email:"user@example.com") |
---|
218 | saveAndTest(personInstance) |
---|
219 | personInstance.addToAuthorities(Authority.get(3)) |
---|
220 | personInstance.addToPersonGroups(PersonGroup.get(2)) |
---|
221 | |
---|
222 | //Person #6 |
---|
223 | personInstance = new Person(loginName:"mann", |
---|
224 | firstName:"Production", |
---|
225 | lastName:"Mann", |
---|
226 | pass:passClearText, |
---|
227 | password:passwordEncoded, |
---|
228 | email:"user@example.com") |
---|
229 | saveAndTest(personInstance) |
---|
230 | personInstance.addToAuthorities(Authority.get(3)) |
---|
231 | personInstance.addToPersonGroups(PersonGroup.get(3)) |
---|
232 | } |
---|
233 | |
---|
234 | /*********************** |
---|
235 | START OF UTILITIES |
---|
236 | ***********************/ |
---|
237 | |
---|
238 | def createDemoSites() { |
---|
239 | //Site |
---|
240 | def siteInstance |
---|
241 | |
---|
242 | siteInstance = new Site(name: "Creek Mill") |
---|
243 | saveAndTest(siteInstance) |
---|
244 | |
---|
245 | siteInstance = new Site(name: "Jasper Street Depot") |
---|
246 | saveAndTest(siteInstance) |
---|
247 | |
---|
248 | siteInstance = new Site(name: "River Press") |
---|
249 | saveAndTest(siteInstance) |
---|
250 | } |
---|
251 | |
---|
252 | def createDemoDepartments() { |
---|
253 | |
---|
254 | //Department |
---|
255 | def departmentInstance |
---|
256 | |
---|
257 | //Department #1 |
---|
258 | departmentInstance = new Department(name: "Print Centre", |
---|
259 | site: Site.get(1)) |
---|
260 | saveAndTest(departmentInstance) |
---|
261 | |
---|
262 | //Department #2 |
---|
263 | departmentInstance = new Department(name: "Pulp Mill 2", |
---|
264 | site: Site.get(2)) |
---|
265 | saveAndTest(departmentInstance) |
---|
266 | } |
---|
267 | |
---|
268 | def createBaseUnitsOfMeasure() { |
---|
269 | |
---|
270 | //UnitOfMeasure |
---|
271 | def unitOfMeasureInstance |
---|
272 | |
---|
273 | //UnitOfMeasure #1 |
---|
274 | unitOfMeasureInstance = new UnitOfMeasure(name: "each") |
---|
275 | saveAndTest(unitOfMeasureInstance) |
---|
276 | |
---|
277 | //UnitOfMeasure #2 |
---|
278 | unitOfMeasureInstance = new UnitOfMeasure(name: "meter(s)") |
---|
279 | saveAndTest(unitOfMeasureInstance) |
---|
280 | |
---|
281 | //UnitOfMeasure #3 |
---|
282 | unitOfMeasureInstance = new UnitOfMeasure(name: "box(es)") |
---|
283 | saveAndTest(unitOfMeasureInstance) |
---|
284 | |
---|
285 | //UnitOfMeasure #4 |
---|
286 | unitOfMeasureInstance = new UnitOfMeasure(name: "litre(s)") |
---|
287 | saveAndTest(unitOfMeasureInstance) |
---|
288 | |
---|
289 | //UnitOfMeasure #5 |
---|
290 | unitOfMeasureInstance = new UnitOfMeasure(name: "kilogram(s)") |
---|
291 | saveAndTest(unitOfMeasureInstance) |
---|
292 | } |
---|
293 | |
---|
294 | def createBasePeriods() { |
---|
295 | |
---|
296 | //Period |
---|
297 | def periodInstance |
---|
298 | |
---|
299 | //Period #1 |
---|
300 | periodInstance = new Period(period: "Day(s)") |
---|
301 | saveAndTest(periodInstance) |
---|
302 | |
---|
303 | //Period #2 |
---|
304 | periodInstance = new Period(period: "Week(s)") |
---|
305 | saveAndTest(periodInstance) |
---|
306 | |
---|
307 | //Period #3 |
---|
308 | periodInstance = new Period(period: "Month(s)") |
---|
309 | saveAndTest(periodInstance) |
---|
310 | |
---|
311 | //Period #4 |
---|
312 | periodInstance = new Period(period: "Year(s)") |
---|
313 | saveAndTest(periodInstance) |
---|
314 | } |
---|
315 | |
---|
316 | def createBaseSupplierType() { |
---|
317 | |
---|
318 | // SupplierType |
---|
319 | def supplierTypeInstance |
---|
320 | |
---|
321 | // SupplierType #1 |
---|
322 | supplierTypeInstance = new SupplierType(name: "OEM", |
---|
323 | description: "Original equipment supplier") |
---|
324 | saveAndTest(supplierTypeInstance) |
---|
325 | |
---|
326 | // SupplierType #2 |
---|
327 | supplierTypeInstance = new SupplierType(name: "Local", |
---|
328 | description: "Local supplier") |
---|
329 | saveAndTest(supplierTypeInstance) |
---|
330 | } |
---|
331 | |
---|
332 | def createBaseManufacturerType() { |
---|
333 | |
---|
334 | // ManufacturerType |
---|
335 | def manufacturerTypeInstance |
---|
336 | |
---|
337 | // ManufacturerType #1 |
---|
338 | manufacturerTypeInstance = new ManufacturerType(name: "OEM", |
---|
339 | description: "Original equipment manufacturer") |
---|
340 | saveAndTest(manufacturerTypeInstance) |
---|
341 | |
---|
342 | // ManufacturerType #2 |
---|
343 | manufacturerTypeInstance = new ManufacturerType(name: "Alternate", |
---|
344 | description: "Not original equipment manufacturer") |
---|
345 | saveAndTest(manufacturerTypeInstance) |
---|
346 | |
---|
347 | } |
---|
348 | |
---|
349 | def createDemoSuppliers() { |
---|
350 | |
---|
351 | // Supplier |
---|
352 | def supplierInstance |
---|
353 | |
---|
354 | // Supplier #1 |
---|
355 | supplierInstance = new Supplier(name: "OEM Distributors", |
---|
356 | supplierType: SupplierType.get(1)) |
---|
357 | saveAndTest(supplierInstance) |
---|
358 | |
---|
359 | // Supplier #2 |
---|
360 | supplierInstance = new Supplier(name: "Mex Holdings", |
---|
361 | supplierType: SupplierType.get(2)) |
---|
362 | saveAndTest(supplierInstance) |
---|
363 | } |
---|
364 | |
---|
365 | def createDemoManufacturers() { |
---|
366 | |
---|
367 | // Manufacturer |
---|
368 | def manufacturerInstance |
---|
369 | |
---|
370 | // Manufacturer #1 |
---|
371 | manufacturerInstance = new Manufacturer(name: "OEM Manufacturer", |
---|
372 | manufacturerType: ManufacturerType.get(1)) |
---|
373 | saveAndTest(manufacturerInstance) |
---|
374 | |
---|
375 | // Manufacturer #2 |
---|
376 | manufacturerInstance = new Manufacturer(name: "Laser Cutting Services Pty", |
---|
377 | manufacturerType: ManufacturerType.get(2)) |
---|
378 | saveAndTest(manufacturerInstance) |
---|
379 | } |
---|
380 | |
---|
381 | /********************* |
---|
382 | START OF TASK |
---|
383 | *********************/ |
---|
384 | |
---|
385 | def createDemoTaskGroups() { |
---|
386 | //TaskGroup |
---|
387 | def taskGroupInstance |
---|
388 | |
---|
389 | taskGroupInstance = new TaskGroup(name:"Engineering Activites", |
---|
390 | description:"Engineering daily activities") |
---|
391 | saveAndTest(taskGroupInstance) |
---|
392 | |
---|
393 | taskGroupInstance = new TaskGroup(name:"Production Activites", |
---|
394 | description:"Production daily activities") |
---|
395 | saveAndTest(taskGroupInstance) |
---|
396 | |
---|
397 | taskGroupInstance = new TaskGroup(name:"New Projects", |
---|
398 | description:" ") |
---|
399 | saveAndTest(taskGroupInstance) |
---|
400 | } |
---|
401 | |
---|
402 | def createBaseTaskStatus() { |
---|
403 | |
---|
404 | //TaskStatus |
---|
405 | def taskStatusInstance |
---|
406 | |
---|
407 | taskStatusInstance = new TaskStatus(name:"Not Started") |
---|
408 | saveAndTest(taskStatusInstance) |
---|
409 | |
---|
410 | taskStatusInstance = new TaskStatus(name:"In Progress") |
---|
411 | saveAndTest(taskStatusInstance) |
---|
412 | |
---|
413 | taskStatusInstance = new TaskStatus(name:"Completed") |
---|
414 | saveAndTest(taskStatusInstance) |
---|
415 | } |
---|
416 | |
---|
417 | def createBaseTaskPriorities() { |
---|
418 | |
---|
419 | //TaskPriority |
---|
420 | def taskPriorityInstance |
---|
421 | |
---|
422 | taskPriorityInstance = new TaskPriority(name:"Normal") |
---|
423 | saveAndTest(taskPriorityInstance) |
---|
424 | |
---|
425 | taskPriorityInstance = new TaskPriority(name:"Low") |
---|
426 | saveAndTest(taskPriorityInstance) |
---|
427 | |
---|
428 | taskPriorityInstance = new TaskPriority(name:"High") |
---|
429 | saveAndTest(taskPriorityInstance) |
---|
430 | |
---|
431 | taskPriorityInstance = new TaskPriority(name:"Immediate") |
---|
432 | saveAndTest(taskPriorityInstance) |
---|
433 | } |
---|
434 | |
---|
435 | def createBaseTaskTypes() { |
---|
436 | |
---|
437 | //TaskType |
---|
438 | def taskTypeInstance |
---|
439 | |
---|
440 | taskTypeInstance = new TaskType(name:"Unscheduled Breakin") |
---|
441 | saveAndTest(taskTypeInstance) |
---|
442 | |
---|
443 | taskTypeInstance = new TaskType(name:"Preventative Maintenance") |
---|
444 | saveAndTest(taskTypeInstance) |
---|
445 | |
---|
446 | taskTypeInstance = new TaskType(name:"Project") |
---|
447 | saveAndTest(taskTypeInstance) |
---|
448 | |
---|
449 | taskTypeInstance = new TaskType(name:"Turnaround") |
---|
450 | saveAndTest(taskTypeInstance) |
---|
451 | |
---|
452 | taskTypeInstance = new TaskType(name:"Production Run") |
---|
453 | saveAndTest(taskTypeInstance) |
---|
454 | } |
---|
455 | |
---|
456 | def createDemoTasks() { |
---|
457 | |
---|
458 | //Task |
---|
459 | def taskInstance |
---|
460 | |
---|
461 | //Task #1 |
---|
462 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
463 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
464 | taskPriority:TaskPriority.get(2), |
---|
465 | taskType:TaskType.get(1), |
---|
466 | leadPerson:Person.get(2), |
---|
467 | description:"Check specific level sensor", |
---|
468 | comment:"Has been noted as problematic, try recalibrating.", |
---|
469 | targetStartDate:new Date()) |
---|
470 | saveAndTest(taskInstance) |
---|
471 | |
---|
472 | //Task #2 |
---|
473 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
474 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
475 | taskPriority:TaskPriority.get(2), |
---|
476 | taskType:TaskType.get(1), |
---|
477 | leadPerson:Person.get(5), |
---|
478 | description:"Some follow-up work", |
---|
479 | comment:"Some help required", |
---|
480 | targetStartDate:new Date()+1, |
---|
481 | parentTask: Task.get(1)) |
---|
482 | saveAndTest(taskInstance) |
---|
483 | |
---|
484 | //Task #3 |
---|
485 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
486 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
487 | taskPriority:TaskPriority.get(2), |
---|
488 | taskType:TaskType.get(1), |
---|
489 | leadPerson:Person.get(5), |
---|
490 | description:"A Sub Task can be created by setting the Parent Task value", |
---|
491 | comment:"Some help required", |
---|
492 | targetStartDate:new Date()-1, |
---|
493 | parentTask: Task.get(1)) |
---|
494 | saveAndTest(taskInstance) |
---|
495 | |
---|
496 | //Task #4 |
---|
497 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
498 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
499 | taskPriority:TaskPriority.get(2), |
---|
500 | taskType:TaskType.get(1), |
---|
501 | leadPerson:Person.get(4), |
---|
502 | description:"Replace sensor at next opportunity.", |
---|
503 | comment:"Nothing else has worked.", |
---|
504 | targetStartDate:new Date()+7, |
---|
505 | parentTask: Task.get(1)) |
---|
506 | saveAndTest(taskInstance) |
---|
507 | |
---|
508 | //Task #5 |
---|
509 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"), |
---|
510 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
511 | taskPriority:TaskPriority.get(2), |
---|
512 | taskType:TaskType.get(5), |
---|
513 | leadPerson:Person.get(6), |
---|
514 | description:"Production Report", |
---|
515 | comment:"Production report for specific production run or shift", |
---|
516 | targetStartDate:new Date()-7) |
---|
517 | saveAndTest(taskInstance) |
---|
518 | |
---|
519 | //Task #6 |
---|
520 | taskInstance = new Task(taskGroup:TaskGroup.findByName("New Projects"), |
---|
521 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
522 | taskPriority:TaskPriority.get(2), |
---|
523 | taskType:TaskType.get(3), |
---|
524 | leadPerson:Person.get(1), |
---|
525 | description:"Make killer CMMS app", |
---|
526 | comment:"Use Grails and get a move on!", |
---|
527 | targetStartDate:new Date()-6) |
---|
528 | saveAndTest(taskInstance) |
---|
529 | } |
---|
530 | |
---|
531 | def createBaseEntryTypes() { |
---|
532 | |
---|
533 | //EntryType |
---|
534 | def entryTypeInstance |
---|
535 | |
---|
536 | entryTypeInstance = new EntryType(name:"Fault") |
---|
537 | saveAndTest(entryTypeInstance) |
---|
538 | |
---|
539 | entryTypeInstance = new EntryType(name:"WorkDone") |
---|
540 | saveAndTest(entryTypeInstance) |
---|
541 | |
---|
542 | entryTypeInstance = new EntryType(name:"Production Note") |
---|
543 | saveAndTest(entryTypeInstance) |
---|
544 | |
---|
545 | entryTypeInstance = new EntryType(name:"Work Request") |
---|
546 | saveAndTest(entryTypeInstance) |
---|
547 | } |
---|
548 | |
---|
549 | def createDemoEntries() { |
---|
550 | |
---|
551 | //Entry |
---|
552 | def entryInstance |
---|
553 | |
---|
554 | //Entry #1 |
---|
555 | entryInstance = new Entry(enteredBy: Person.get(3), |
---|
556 | task: Task.get(1), |
---|
557 | entryType: EntryType.findByName("Fault"), |
---|
558 | comment: "This level sensor is causing us trouble.", |
---|
559 | durationMinute: 20) |
---|
560 | saveAndTest(entryInstance) |
---|
561 | |
---|
562 | //Entry #2 |
---|
563 | entryInstance = new Entry(enteredBy: Person.get(4), |
---|
564 | task: Task.get(1), |
---|
565 | entryType: EntryType.findByName("WorkDone"), |
---|
566 | comment: "Cleaned sensor, see how it goes.", |
---|
567 | durationMinute: 30) |
---|
568 | saveAndTest(entryInstance) |
---|
569 | |
---|
570 | //Entry #3 |
---|
571 | entryInstance = new Entry(enteredBy: Person.get(4), |
---|
572 | task: Task.get(1), |
---|
573 | entryType: EntryType.findByName("WorkDone"), |
---|
574 | comment: "Checked up on it later and sensor is dropping out intermittently, created subTask to replace sensor.", |
---|
575 | durationMinute: 20) |
---|
576 | saveAndTest(entryInstance) |
---|
577 | } |
---|
578 | |
---|
579 | def createBaseModificationTypes() { |
---|
580 | |
---|
581 | //ModificationType |
---|
582 | def taskModificationTypeInstance |
---|
583 | taskModificationTypeInstance = new TaskModificationType(name:"Created").save() |
---|
584 | taskModificationTypeInstance = new TaskModificationType(name:"Completed").save() |
---|
585 | taskModificationTypeInstance = new TaskModificationType(name:"Closed").save() |
---|
586 | taskModificationTypeInstance = new TaskModificationType(name:"Altered").save() |
---|
587 | taskModificationTypeInstance = new TaskModificationType(name:"TargetDateModified").save() |
---|
588 | taskModificationTypeInstance = new TaskModificationType(name:"ScheduledDateModified").save() |
---|
589 | taskModificationTypeInstance = new TaskModificationType(name:"DescriptionModified").save() |
---|
590 | taskModificationTypeInstance = new TaskModificationType(name:"AssignedToModified").save() |
---|
591 | taskModificationTypeInstance = new TaskModificationType(name:"NameModified").save() |
---|
592 | } |
---|
593 | |
---|
594 | def createDemoAssignedPersons() { |
---|
595 | |
---|
596 | //AssignedPerson |
---|
597 | def assignedPersonInstance |
---|
598 | |
---|
599 | //AssignedPerson #1 |
---|
600 | assignedPersonInstance = new AssignedPerson(person: Person.get(4), |
---|
601 | task: Task.get(1), |
---|
602 | estimatedHour: 1, |
---|
603 | estimatedMinute: 20) |
---|
604 | saveAndTest(assignedPersonInstance) |
---|
605 | |
---|
606 | //AssignedPerson #2 |
---|
607 | assignedPersonInstance = new AssignedPerson(person: Person.get(5), |
---|
608 | task: Task.get(1), |
---|
609 | estimatedHour: 3, |
---|
610 | estimatedMinute: 30) |
---|
611 | saveAndTest(assignedPersonInstance) |
---|
612 | } |
---|
613 | |
---|
614 | def createDemoTaskRecurringSchedules() { |
---|
615 | |
---|
616 | //TaskRecurringSchedule |
---|
617 | def taskRecurringScheduleInstance |
---|
618 | |
---|
619 | //TaskRecurringSchedule #1 |
---|
620 | taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1), |
---|
621 | recurEvery: 1, |
---|
622 | recurPeriod: Period.get(1), |
---|
623 | startDate: new Date(), |
---|
624 | generateAhead: 1, |
---|
625 | generateAheadPeriod: Period.get(1), |
---|
626 | taskDuration: 1, |
---|
627 | taskDurationPeriod: Period.get(1)) |
---|
628 | saveAndTest(taskRecurringScheduleInstance) |
---|
629 | |
---|
630 | //TaskRecurringSchedule #2 |
---|
631 | taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(2), |
---|
632 | recurEvery: 1, |
---|
633 | recurPeriod: Period.get(1), |
---|
634 | startDate: new Date(), |
---|
635 | generateAhead: 1, |
---|
636 | generateAheadPeriod: Period.get(1), |
---|
637 | taskDuration: 1, |
---|
638 | taskDurationPeriod: Period.get(1)) |
---|
639 | saveAndTest(taskRecurringScheduleInstance) |
---|
640 | } |
---|
641 | |
---|
642 | /************************* |
---|
643 | START OF INVENTORY |
---|
644 | **************************/ |
---|
645 | |
---|
646 | def createDemoInventoryStores() { |
---|
647 | |
---|
648 | //InventoryStore |
---|
649 | def inventoryStoreInstance |
---|
650 | |
---|
651 | inventoryStoreInstance = new InventoryStore(site: Site.get(1), name: "Store #1") |
---|
652 | saveAndTest(inventoryStoreInstance) |
---|
653 | |
---|
654 | inventoryStoreInstance = new InventoryStore(site: Site.get(2), name: "Store #2") |
---|
655 | saveAndTest(inventoryStoreInstance) |
---|
656 | } |
---|
657 | |
---|
658 | def createDemoInventoryLocations() { |
---|
659 | |
---|
660 | // InventoryLocation |
---|
661 | def inventoryLocation |
---|
662 | |
---|
663 | inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(1), name: "A1-2") |
---|
664 | saveAndTest(inventoryLocation) |
---|
665 | |
---|
666 | inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(1), name: "C55") |
---|
667 | saveAndTest(inventoryLocation) |
---|
668 | } |
---|
669 | |
---|
670 | def createDemoInventoryGroups() { |
---|
671 | |
---|
672 | //InventoryGroup |
---|
673 | def inventoryGroupInstance |
---|
674 | |
---|
675 | //InventoryGroup #1 |
---|
676 | inventoryGroupInstance = new InventoryGroup(name: "Misc") |
---|
677 | saveAndTest(inventoryGroupInstance) |
---|
678 | |
---|
679 | //InventoryGroup #2 |
---|
680 | inventoryGroupInstance = new InventoryGroup(name: "Electrical") |
---|
681 | saveAndTest(inventoryGroupInstance) |
---|
682 | |
---|
683 | //InventoryGroup #3 |
---|
684 | inventoryGroupInstance = new InventoryGroup(name: "Mechanical") |
---|
685 | saveAndTest(inventoryGroupInstance) |
---|
686 | |
---|
687 | //InventoryGroup #4 |
---|
688 | inventoryGroupInstance = new InventoryGroup(name: "Production") |
---|
689 | saveAndTest(inventoryGroupInstance) |
---|
690 | } |
---|
691 | |
---|
692 | def createBaseInventoryTypes() { |
---|
693 | |
---|
694 | //InventoryType |
---|
695 | def inventoryTypeInstance |
---|
696 | |
---|
697 | inventoryTypeInstance = new InventoryType(name: "Consumable") |
---|
698 | saveAndTest(inventoryTypeInstance) |
---|
699 | |
---|
700 | inventoryTypeInstance = new InventoryType(name: "Repairable") |
---|
701 | saveAndTest(inventoryTypeInstance) |
---|
702 | } |
---|
703 | |
---|
704 | def createBaseInventoryMovementTypes() { |
---|
705 | |
---|
706 | // InventoryMovementType |
---|
707 | def inventoryMovementTypeInstance |
---|
708 | |
---|
709 | // InventoryMovementType #1 |
---|
710 | inventoryMovementTypeInstance = new InventoryMovementType(name: "Used") |
---|
711 | saveAndTest(inventoryMovementTypeInstance) |
---|
712 | |
---|
713 | // InventoryMovementType #2 |
---|
714 | inventoryMovementTypeInstance = new InventoryMovementType(name: "Repaired") |
---|
715 | saveAndTest(inventoryMovementTypeInstance) |
---|
716 | |
---|
717 | // InventoryMovementType #3 |
---|
718 | inventoryMovementTypeInstance = new InventoryMovementType(name: "Purchased") |
---|
719 | saveAndTest(inventoryMovementTypeInstance) |
---|
720 | } |
---|
721 | |
---|
722 | def createDemoInventoryItems() { |
---|
723 | |
---|
724 | //InventoryItem |
---|
725 | def inventoryItemInstance |
---|
726 | |
---|
727 | //InventoryItem #1 |
---|
728 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1), |
---|
729 | inventoryType: InventoryType.get(1), |
---|
730 | unitOfMeasure: UnitOfMeasure.get(2), |
---|
731 | inventoryLocation: InventoryLocation.get(1), |
---|
732 | name: "J-Rope", |
---|
733 | description: "Twine wound J-Rope", |
---|
734 | unitsInStock: 2, |
---|
735 | reorderPoint: 0) |
---|
736 | saveAndTest(inventoryItemInstance) |
---|
737 | |
---|
738 | //InventoryItem #2 |
---|
739 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1), |
---|
740 | inventoryType: InventoryType.get(1), |
---|
741 | unitOfMeasure: UnitOfMeasure.get(2), |
---|
742 | inventoryLocation: InventoryLocation.get(1), |
---|
743 | name: "L-Rope", |
---|
744 | description: "Twine wound L-Rope", |
---|
745 | alternateItems: InventoryItem.get(1), |
---|
746 | unitsInStock: 2, |
---|
747 | reorderPoint: 0) |
---|
748 | saveAndTest(inventoryItemInstance) |
---|
749 | |
---|
750 | //InventoryItem #3 |
---|
751 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3), |
---|
752 | inventoryType: InventoryType.get(1), |
---|
753 | unitOfMeasure: UnitOfMeasure.get(1), |
---|
754 | inventoryLocation: InventoryLocation.get(2), |
---|
755 | name: "2305-2RS", |
---|
756 | description: "Bearing 25x62x24mm double row self aligning ball", |
---|
757 | unitsInStock: 3, |
---|
758 | reorderPoint: 2) |
---|
759 | saveAndTest(inventoryItemInstance) |
---|
760 | |
---|
761 | //InventoryItem #4 |
---|
762 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2), |
---|
763 | inventoryType: InventoryType.get(1), |
---|
764 | unitOfMeasure: UnitOfMeasure.get(1), |
---|
765 | inventoryLocation: InventoryLocation.get(2), |
---|
766 | name: "L1592-K10", |
---|
767 | description: "10kW contactor", |
---|
768 | unitsInStock: 4, |
---|
769 | reorderPoint: 0) |
---|
770 | saveAndTest(inventoryItemInstance) |
---|
771 | |
---|
772 | //InventoryItem #5 |
---|
773 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3), |
---|
774 | inventoryType: InventoryType.get(1), |
---|
775 | unitOfMeasure: UnitOfMeasure.get(1), |
---|
776 | inventoryLocation: InventoryLocation.get(2), |
---|
777 | name: "6205-ZZ", |
---|
778 | description: "Bearing 25x52x15mm single row ball shielded", |
---|
779 | unitsInStock: 5, |
---|
780 | reorderPoint: 2) |
---|
781 | saveAndTest(inventoryItemInstance) |
---|
782 | } |
---|
783 | |
---|
784 | /******************* |
---|
785 | START OF ASSET |
---|
786 | *******************/ |
---|
787 | |
---|
788 | def createDemoLifePlan() { |
---|
789 | |
---|
790 | //LifePlan |
---|
791 | def lifeplanInstance |
---|
792 | |
---|
793 | lifeplanInstance = new LifePlan(name: "Initial Plan") |
---|
794 | saveAndTest(lifeplanInstance) |
---|
795 | } |
---|
796 | |
---|
797 | def createBaseMaintenancePolicies() { |
---|
798 | |
---|
799 | //MaintenancePolicy |
---|
800 | def maintenancePolicyInstance |
---|
801 | |
---|
802 | //MaintenancePolicy #1 |
---|
803 | maintenancePolicyInstance = new MaintenancePolicy(name: "Fixed Time") |
---|
804 | saveAndTest(maintenancePolicyInstance) |
---|
805 | |
---|
806 | //MaintenancePolicy #2 |
---|
807 | maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Online") |
---|
808 | saveAndTest(maintenancePolicyInstance) |
---|
809 | |
---|
810 | //MaintenancePolicy #3 |
---|
811 | maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Offline") |
---|
812 | saveAndTest(maintenancePolicyInstance) |
---|
813 | |
---|
814 | //MaintenancePolicy #4 |
---|
815 | maintenancePolicyInstance = new MaintenancePolicy(name: "Design Out") |
---|
816 | saveAndTest(maintenancePolicyInstance) |
---|
817 | |
---|
818 | //MaintenancePolicy #5 |
---|
819 | maintenancePolicyInstance = new MaintenancePolicy(name: "Operate To Failure") |
---|
820 | saveAndTest(maintenancePolicyInstance) |
---|
821 | } |
---|
822 | |
---|
823 | def createDemoTaskProcedure() { |
---|
824 | |
---|
825 | //TaskProcedure |
---|
826 | def taskProcedureInstance |
---|
827 | |
---|
828 | taskProcedureInstance = new TaskProcedure(name: "Daily check") |
---|
829 | saveAndTest(taskProcedureInstance) |
---|
830 | taskProcedureInstance.addToTasks(Task.get(1)) |
---|
831 | } |
---|
832 | |
---|
833 | def createDemoMaintenanceActions() { |
---|
834 | |
---|
835 | //MaintenanceAction |
---|
836 | def maintenanceActionInstance |
---|
837 | |
---|
838 | //MaintenanceAction #1 |
---|
839 | maintenanceActionInstance = new MaintenanceAction(description: "Check all E-stops, activate E-stops S1-S12 and ensure machine cannot run", |
---|
840 | procedureStepNumber: 1, |
---|
841 | maintenancePolicy: MaintenancePolicy.get(1), |
---|
842 | taskProcedure: TaskProcedure.get(1)) |
---|
843 | saveAndTest(maintenanceActionInstance) |
---|
844 | |
---|
845 | //MaintenanceAction #2 |
---|
846 | maintenanceActionInstance = new MaintenanceAction(description: "Do more pushups", |
---|
847 | procedureStepNumber: 2, |
---|
848 | maintenancePolicy: MaintenancePolicy.get(1), |
---|
849 | taskProcedure: TaskProcedure.get(1)) |
---|
850 | saveAndTest(maintenanceActionInstance) |
---|
851 | |
---|
852 | //MaintenanceAction #3 |
---|
853 | maintenanceActionInstance = new MaintenanceAction(description: "Ok just one more pushup", |
---|
854 | procedureStepNumber: 3, |
---|
855 | maintenancePolicy: MaintenancePolicy.get(1), |
---|
856 | taskProcedure: TaskProcedure.get(1)) |
---|
857 | saveAndTest(maintenanceActionInstance) |
---|
858 | } |
---|
859 | |
---|
860 | def createDemoSystemSections() { |
---|
861 | |
---|
862 | //SystemSection |
---|
863 | def systemSectionInstance |
---|
864 | |
---|
865 | //SystemSection #1 |
---|
866 | systemSectionInstance = new SystemSection(name: "Press Section", |
---|
867 | site: Site.get(1), |
---|
868 | department: Department.get(1)) |
---|
869 | saveAndTest(systemSectionInstance) |
---|
870 | |
---|
871 | //SystemSection #2 |
---|
872 | systemSectionInstance = new SystemSection(name: "RO System", |
---|
873 | site: Site.get(2), |
---|
874 | department: Department.get(2)) |
---|
875 | saveAndTest(systemSectionInstance) |
---|
876 | |
---|
877 | //SystemSection #3 |
---|
878 | systemSectionInstance = new SystemSection(name: "Auxilliray Section", |
---|
879 | site: Site.get(1), |
---|
880 | department: Department.get(1)) |
---|
881 | saveAndTest(systemSectionInstance) |
---|
882 | } |
---|
883 | |
---|
884 | def createDemoAssetTypes() { |
---|
885 | |
---|
886 | //AssetType |
---|
887 | def assetTypeInstance |
---|
888 | |
---|
889 | //AssetType #1 |
---|
890 | assetTypeInstance = new AssetType(name: "Print Unit") |
---|
891 | saveAndTest(assetTypeInstance) |
---|
892 | |
---|
893 | //AssetType #2 |
---|
894 | assetTypeInstance = new AssetType(name: "Reactor Tower") |
---|
895 | saveAndTest(assetTypeInstance) |
---|
896 | } |
---|
897 | |
---|
898 | def createDemoAssemblies() { |
---|
899 | |
---|
900 | //Assembly |
---|
901 | def assemblyInstance |
---|
902 | |
---|
903 | //Assembly #1 |
---|
904 | assemblyInstance = new Assembly(name: "Print Couple", |
---|
905 | assetType: AssetType.get(1)) |
---|
906 | saveAndTest(assemblyInstance) |
---|
907 | // assemblyInstance.addToMaintenanceActions(MaintenanceAction.get(1)) |
---|
908 | |
---|
909 | //Assembly #2 |
---|
910 | assemblyInstance = new Assembly(name: "Agitator", |
---|
911 | assetType: AssetType.get(2)) |
---|
912 | saveAndTest(assemblyInstance) |
---|
913 | } |
---|
914 | |
---|
915 | def createDemoSubAssemblies() { |
---|
916 | |
---|
917 | //SubAssembly |
---|
918 | def subAssemblyInstance |
---|
919 | |
---|
920 | //SubAssembly #1 |
---|
921 | subAssemblyInstance = new SubAssembly(name: "Cylinder", |
---|
922 | assembly: Assembly.get(1)) |
---|
923 | saveAndTest(subAssemblyInstance) |
---|
924 | |
---|
925 | //SubAssembly #2 |
---|
926 | subAssemblyInstance = new SubAssembly(name: "Gearmotor", |
---|
927 | assembly: Assembly.get(2)) |
---|
928 | saveAndTest(subAssemblyInstance) |
---|
929 | } |
---|
930 | |
---|
931 | def createDemoComponentItems() { |
---|
932 | |
---|
933 | //ComponentItem |
---|
934 | def componentItemInstance |
---|
935 | |
---|
936 | //ComponentItem #1 |
---|
937 | componentItemInstance = new ComponentItem(name: "Bearing", |
---|
938 | subAssembly: SubAssembly.get(1)) |
---|
939 | saveAndTest(componentItemInstance) |
---|
940 | |
---|
941 | //ComponentItem #2 |
---|
942 | componentItemInstance = new ComponentItem(name: "Drive shaft oil seal", |
---|
943 | subAssembly: SubAssembly.get(2)) |
---|
944 | saveAndTest(componentItemInstance) |
---|
945 | } |
---|
946 | |
---|
947 | def createDemoAssets() { |
---|
948 | |
---|
949 | //Asset |
---|
950 | def assetInstance |
---|
951 | |
---|
952 | //Asset #1 |
---|
953 | assetInstance = new Asset(name: "Print Unit 22", |
---|
954 | assetType: AssetType.get(1), |
---|
955 | systemSection: SystemSection.get(1)) |
---|
956 | saveAndTest(assetInstance) |
---|
957 | // assetInstance.addToMaintenanceActions(MaintenanceAction.get(1)) |
---|
958 | |
---|
959 | //Asset #2 |
---|
960 | assetInstance = new Asset(name: "Print Unit 21", |
---|
961 | assetType: AssetType.get(1), |
---|
962 | systemSection: SystemSection.get(1)) |
---|
963 | saveAndTest(assetInstance) |
---|
964 | |
---|
965 | //Asset #3 |
---|
966 | assetInstance = new Asset(name: "Print Unit 23", |
---|
967 | assetType: AssetType.get(1), |
---|
968 | systemSection: SystemSection.get(1)) |
---|
969 | saveAndTest(assetInstance) |
---|
970 | |
---|
971 | //Asset #4 |
---|
972 | assetInstance = new Asset(name: "RO 1", |
---|
973 | assetType: AssetType.get(2), |
---|
974 | systemSection: SystemSection.get(2)) |
---|
975 | saveAndTest(assetInstance) |
---|
976 | } |
---|
977 | |
---|
978 | def createBaseAssetExtenededAttributeTypes() { |
---|
979 | |
---|
980 | //AssetExtendedAttributeType |
---|
981 | def assetExtendedAttributeInstanceType |
---|
982 | |
---|
983 | //AssetExtendedAttributeType #1 |
---|
984 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Model Number") |
---|
985 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
986 | |
---|
987 | //AssetExtendedAttributeType #2 |
---|
988 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Purchase Cost") |
---|
989 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
990 | |
---|
991 | //AssetExtendedAttributeType #3 |
---|
992 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Serial Number") |
---|
993 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
994 | |
---|
995 | //AssetExtendedAttributeType #4 |
---|
996 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Manufactured Date") |
---|
997 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
998 | |
---|
999 | //AssetExtendedAttributeType #5 |
---|
1000 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Location Description") |
---|
1001 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
1002 | } |
---|
1003 | |
---|
1004 | def createDemoAssetExtenedAttributes() { |
---|
1005 | |
---|
1006 | //AssetExtendedAttribute |
---|
1007 | def assetExtendedAttributeInstance |
---|
1008 | |
---|
1009 | //AssetExtendedAttribute #1 |
---|
1010 | assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "PU Mark 2", |
---|
1011 | asset: Asset.get(1), |
---|
1012 | assetExtendedAttributeType: AssetExtendedAttributeType.get(1)) |
---|
1013 | saveAndTest(assetExtendedAttributeInstance) |
---|
1014 | |
---|
1015 | //AssetExtendedAttribute #2 |
---|
1016 | assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5", |
---|
1017 | asset: Asset.get(1), |
---|
1018 | assetExtendedAttributeType: AssetExtendedAttributeType.get(5)) |
---|
1019 | saveAndTest(assetExtendedAttributeInstance) |
---|
1020 | } |
---|
1021 | |
---|
1022 | |
---|
1023 | /**************************************** |
---|
1024 | Call this function instead of .save() |
---|
1025 | *****************************************/ |
---|
1026 | private boolean saveAndTest(object) { |
---|
1027 | if(!object.save()) { |
---|
1028 | // DemoDataSuccessful = false |
---|
1029 | println "'${object}' failed to save!" |
---|
1030 | println object.errors |
---|
1031 | return false |
---|
1032 | } |
---|
1033 | return true |
---|
1034 | } |
---|
1035 | } |
---|