source: trunk/grails-app/services/CreateDataService.groovy @ 433

Last change on this file since 433 was 433, checked in by gav, 14 years ago

Add create unsheduled task feature.
Refactor task priorities.
Limit task types and priorites during task creation.
Add work around for show and edit navigation links in task views.

File size: 62.4 KB
Line 
1/**
2* Provides a data service to create base and demo data.
3* Beware that most, if not all, base data is referenced by "Id" throughout the program.
4* This allows changing the text of the 'name' property to something of the same meaning.
5* But be sure to maintain the correct Id during creation, indicated by #1, #2 etc.
6*/
7class  CreateDataService {
8
9    boolean transactional = false
10
11    def authService
12    def taskService
13    def dateUtilService
14    def appConfigService
15    def assignedGroupService
16    def assignedPersonService
17
18/*******************************************
19Start of Group methods.
20Generally use these methods to create data.
21*******************************************/
22
23    /**
24    * Always call this at startup to ensure that we have admin access
25    * and that the system pseudo person is available.
26    */
27    def ensureSystemAndAdminAccess() {
28        if(!Authority.findByAuthority("ROLE_AppAdmin") ) {
29            log.warn "ROLE_AppAdmin not found, calling createAdminAuthority()."
30            createAdminAuthority()
31        }
32        if(!Person.findByloginName("system") ) {
33            log.warn "LoginName 'system' not found, calling createSystemPerson()."
34            createSystemPerson()
35        }
36        if(!Person.findByloginName("admin") ) {
37            log.warn "LoginName 'admin' not found, calling createAdminPerson()."
38            createAdminPerson()
39        }
40    }
41
42    /**
43    * Create the base data required for the application to function.
44    */
45    def createBaseData() {
46
47        if(appConfigService.exists("baseDataCreated")) {
48            log.error "Base data has already been created, will NOT recreate."
49            return false
50        }
51
52        log.info "Creating base data..."
53
54        // Person and Utils
55        createBaseAuthorities()
56        createBasePersonGroups()
57        createBaseDefinitions()
58        createBaseUnitsOfMeasure()
59        createBasePeriods()
60        createBaseSupplierTypes()
61        createBaseManufacturerTypes()
62        createBaseAddressTypes()
63        createBaseContactTypes()
64
65        // Tasks
66        createBaseTaskGroups()
67        createBaseTaskStatus()
68        createBaseTaskPriorities()
69        createBaseTaskBudgetStatus()
70        createBaseTaskTypes()
71        createBaseTaskModificationTypes()
72        createBaseEntryTypes()
73
74        // Inventory
75        createBaseInventoryTypes()
76        createBaseInventoryMovementTypes()
77
78        // Assets
79        createBaseExtenededAttributeTypes()
80        createBaseMaintenancePolicies()
81
82        // Record that data has been created.
83        appConfigService.set("baseDataCreated")
84    }
85
86    /**
87    * Create demo data for some example sites.
88    */
89    def createDemoData() {
90
91        if(!appConfigService.exists("baseDataCreated")) {
92            log.error "Demo data cannot be created until base data has been created."
93            return false
94        }
95
96        if(appConfigService.exists("demoDataCreated")) {
97            log.error "Demo data has already been created, will NOT recreate."
98            return false
99        }
100
101        if(appConfigService.exists("demoDataCreationDisabled")) {
102            log.error "Demo data creation has been disabled, will NOT create."
103            return false
104        }
105
106        log.info "Creating demo data..."
107
108        // Person and Utils
109        createDemoPersons()
110        createDemoSites()
111        createDemoDepartments()
112        createDemoSuppliers()
113        createDemoManufacturers()
114        createDemoProductionReference()
115
116        // Tasks
117        createDemoTasks()
118        createDemoEntries()
119        createDemoAssignedGroups()
120        createDemoAssignedPersons()
121        createDemoTaskRecurringSchedules()
122
123        // Inventory
124        createDemoInventoryStores()  /// @todo: Perhaps a 'createQuickStartData' method?
125        createDemoInventoryLocations()
126        createDemoInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method?
127        createDemoInventoryItems()
128
129        // Assets
130        createDemoLifePlan()
131        createDemoTaskProcedure()
132        createDemoMaintenanceActions()
133        createDemoSections()
134        createDemoAssetTree()
135        createDemoAssetExtenedAttributes()
136
137        // Record that data has been created.
138        appConfigService.set("demoDataCreated")
139    }
140
141/******************
142Start of Person
143*******************/
144
145    def createAdminAuthority() {
146        def authInstance
147
148        // Authority #1
149        authInstance = new Authority(description:"Application Admin, not required for daily use! \
150                                                                                Grants full admin access to the application.",
151                                        authority:"ROLE_AppAdmin")
152        saveAndTest(authInstance)
153    }
154
155    def createBaseAuthorities() {
156
157        def authInstance
158
159        // Authority #2
160        authInstance = new Authority(description:"Business Manager, grants full management access.",
161                                                            authority:"ROLE_Manager")
162        saveAndTest(authInstance)
163
164        // Authority #3
165        authInstance = new Authority(description:"Application User, all application users need this base role \
166                                                                                    to allow login.",
167                                                            authority:"ROLE_AppUser")
168        saveAndTest(authInstance)
169
170        // Authority #4
171        authInstance = new Authority(description:"Task Manager",
172                                                            authority:"ROLE_TaskManager")
173        saveAndTest(authInstance)
174
175        // Authority #5
176        authInstance = new Authority(description:"Task User",
177                                                            authority:"ROLE_TaskUser")
178        saveAndTest(authInstance)
179
180        // Authority #6
181        authInstance = new Authority(description:"Inventory Manager",
182                                                            authority:"ROLE_InventoryManager")
183        saveAndTest(authInstance)
184
185        // Authority #7
186        authInstance = new Authority(description:"Inventory User",
187                                                            authority:"ROLE_InventoryUser")
188        saveAndTest(authInstance)
189
190        // Authority #8
191        authInstance = new Authority(description:"Asset Manager",
192                                                            authority:"ROLE_AssetManager")
193        saveAndTest(authInstance)
194
195        // Authority #9
196        authInstance = new Authority(description:"Asset User",
197                                                            authority:"ROLE_AssetUser")
198        saveAndTest(authInstance)
199
200        // Authority #10
201        authInstance = new Authority(description:"Production Manager",
202                                                            authority:"ROLE_ProductionManager")
203        saveAndTest(authInstance)
204
205        // Authority #11
206        authInstance = new Authority(description:"Production User",
207                                                            authority:"ROLE_ProductionUser")
208        saveAndTest(authInstance)
209    }
210
211    void createBasePersonGroups() {
212        //TypeOfPersonGroup
213        def personGroupTypeInstance
214            personGroupTypeInstance = new PersonGroupType(name:"Team")
215        saveAndTest(personGroupTypeInstance)
216            personGroupTypeInstance = new PersonGroupType(name:"Contractor")
217        saveAndTest(personGroupTypeInstance)
218            personGroupTypeInstance = new PersonGroupType(name:"ProjectTeam")
219        saveAndTest(personGroupTypeInstance)
220
221        //PersonGroup
222        def personGroupInstance
223            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
224                            name:"Electrical")
225        saveAndTest(personGroupInstance)
226            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
227                            name:"Mechanical")
228        saveAndTest(personGroupInstance)
229            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
230                            name:"Production")
231        saveAndTest(personGroupInstance)
232            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(2),
233                            name:"Kewl AirCon Guys")
234        saveAndTest(personGroupInstance)
235            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(3),
236                            name:"gnuMims")
237        saveAndTest(personGroupInstance)
238    }
239
240    def createSystemPerson() {
241        //Person
242        def passClearText = "pass"
243        def passwordEncoded = authService.encodePassword(passClearText)
244        def personInstance
245
246        //Person #1
247        personInstance = new Person(loginName:"system",
248                                    firstName:"gnuMims",
249                                    lastName:"System",
250                                    description:'''This is a pseudo person that the application uses to insert data. DO NOT
251                                                        assign login authorities or change the details of this person.''',
252                                    pass:passClearText,
253                                    password:passwordEncoded)
254        saveAndTest(personInstance)
255    }
256
257    def createAdminPerson() {
258        //Person
259        def passClearText = "pass"
260        def passwordEncoded = authService.encodePassword(passClearText)
261        def personInstance
262
263        //Person #2
264        personInstance = new Person(loginName:"admin",
265                                    firstName:"Admin",
266                                    lastName:"Powers",
267                                    description:'''Every time the application starts it ensures that the 'admin' login name is available.
268                                                        DO update the password and other details but keep the login name as 'admin'. ''',
269                                    pass:passClearText,
270                                    password:passwordEncoded)
271        saveAndTest(personInstance)
272        personInstance.addToAuthorities(Authority.get(1))
273    }
274
275    def createBasePersons() {
276    }
277
278    def createDemoPersons() {
279        //Person
280        def passClearText = "pass"
281        def passwordEncoded = authService.encodePassword(passClearText)
282        def personInstance
283
284        //Person #1 is system.
285        //Person #2 is admin.
286
287        //Person #3
288        personInstance = new Person(loginName:"manager",
289                                    firstName:"Demo",
290                                    lastName:"Manager",
291                                    pass:passClearText,
292                                    password:passwordEncoded)
293        saveAndTest(personInstance)
294        personInstance.addToAuthorities(Authority.get(2)) // ROLE_Manager.
295        personInstance.addToAuthorities(Authority.get(3)) // ROLE_AppUser.
296
297        //Person #4
298        personInstance = new Person(loginName:"user",
299                                    firstName:"Demo",
300                                    lastName:"User",
301                                    pass:passClearText,
302                                    password:passwordEncoded)
303        saveAndTest(personInstance)
304        personInstance.addToAuthorities(Authority.get(3)) // ROLE_AppUser.
305        personInstance.addToAuthorities(Authority.get(5)) // ROLE_TaskManager.
306        personInstance.addToAuthorities(Authority.get(7)) // ROLE_InventoryUser.
307        personInstance.addToAuthorities(Authority.get(9)) // ROLE_AssetUser.
308        personInstance.addToPersonGroups(PersonGroup.get(1))
309
310        //Person #5
311        personInstance = new Person(loginName:"craig",
312                                    firstName:"Craig",
313                                    lastName:"SuperSparky",
314                                    pass:passClearText,
315                                    password:passwordEncoded)
316        saveAndTest(personInstance)
317        personInstance.addToAuthorities(Authority.get(3))
318        personInstance.addToAuthorities(Authority.get(5))
319        personInstance.addToAuthorities(Authority.get(7))
320        personInstance.addToAuthorities(Authority.get(9))
321        personInstance.addToPersonGroups(PersonGroup.get(1))
322
323        //Person #6
324        personInstance = new Person(loginName:"john",
325                                    firstName:"John",
326                                    lastName:"SuperFitter",
327                                    pass:passClearText,
328                                    password:passwordEncoded)
329        saveAndTest(personInstance)
330        personInstance.addToAuthorities(Authority.get(3))
331        personInstance.addToAuthorities(Authority.get(5))
332        personInstance.addToAuthorities(Authority.get(7))
333        personInstance.addToAuthorities(Authority.get(9))
334        personInstance.addToPersonGroups(PersonGroup.get(2))
335
336        //Person #7
337        personInstance = new Person(loginName:"production manager",
338                                    firstName:"Production",
339                                    lastName:"Manager",
340                                    pass:passClearText,
341                                    password:passwordEncoded)
342        saveAndTest(personInstance)
343        personInstance.addToAuthorities(Authority.get(3)) // ROLE_AppUser.
344        personInstance.addToAuthorities(Authority.get(10)) // ROLE_ProductionManager.
345        personInstance.addToPersonGroups(PersonGroup.get(3))
346
347        //Person #8
348        personInstance = new Person(loginName:"production",
349                                    firstName:"Production",
350                                    lastName:"User",
351                                    pass:passClearText,
352                                    password:passwordEncoded)
353        saveAndTest(personInstance)
354        personInstance.addToAuthorities(Authority.get(3)) // ROLE_AppUser.
355        personInstance.addToAuthorities(Authority.get(11)) // ROLE_ProductionUser.
356        personInstance.addToPersonGroups(PersonGroup.get(3))
357
358        //Person #9
359        personInstance = new Person(loginName:"testmanager",
360                                    firstName:"Test",
361                                    lastName:"Manager",
362                                    pass:passClearText,
363                                    password:passwordEncoded)
364        saveAndTest(personInstance)
365        personInstance.addToAuthorities(Authority.get(3)) // ROLE_AppUser.
366        personInstance.addToAuthorities(Authority.get(4)) // ROLE_TaskManager.
367        personInstance.addToAuthorities(Authority.get(6)) // ROLE_InventoryManager.
368        personInstance.addToAuthorities(Authority.get(8)) // ROLE_AssetManager.
369        personInstance.addToPersonGroups(PersonGroup.get(3))
370    }
371
372/***********************
373START OF UTILITIES
374***********************/
375
376    //These can redefined by the site at deployment time.
377    /// @todo: build an admin view so that only the value (definition) can be changed.
378    def createBaseDefinitions() {
379        appConfigService.set("Department Definition", "A department as recongised by accounting.")
380        appConfigService.set("Site Definition", "The plant, work or production site.")
381        appConfigService.set("Section Definition", "A logical grouping of assets, which may be an area, system or process \
382                                            as determined by design.")
383        appConfigService.set("Asset Definition",
384                                            "The complete asset as it is known on the site. \
385                                            Often purchased as a whole with the primary purpose of returning value by performing a function. \
386                                            An asset is made up of 1 or more sub assets and performs a complete function as specified by the designer.")
387        appConfigService.set("Asset Sub Item 1 Name",
388                                            "Sub Asset")
389        appConfigService.set("Asset Sub Item 1 Definition",
390                                            "A machine that performs part of a complete asset's function and often has a model number.")
391        appConfigService.set("Asset Sub Item 2 Name",
392                                            "Functional Assembly")
393        appConfigService.set("Asset Sub Item 2 Definition",
394                                            "Functional Assemblies are taken from the designer's functional list for the sub asset and are made up of sub \
395                                            assemblies that together perform that function.")
396        appConfigService.set("Asset Sub Item 3 Name",
397                                            "Sub Assembly Group")
398        appConfigService.set("Asset Sub Item 3 Definition",
399                                            "Group or type of part.")
400        appConfigService.set("Asset Sub Item 4 Name",
401                                            "Component Item")
402        appConfigService.set("Asset Sub Item 4 Definition",
403                                            "The smallest part that would be analysed for failure.")
404    }
405
406    def createDemoSites() {
407        //Site
408        def siteInstance
409
410        siteInstance = new Site(name: "CSM",
411                                                    description: "Creek Side Mill")
412        saveAndTest(siteInstance)
413
414        siteInstance = new Site(name: "Jasper Street Depot",
415                                                    description: "Storage depot on Jasper Street.")
416        saveAndTest(siteInstance)
417
418        siteInstance = new Site(name: "River Press",
419                                                    description: "Printing press site")
420        saveAndTest(siteInstance)
421    }
422
423    def createDemoDepartments() {
424
425        //Department
426        def departmentInstance
427
428        //Department #1
429        departmentInstance = new Department(name: "Print Centre",
430                                                                                description: "Printing Department",
431                                                                                site: Site.get(1))
432        saveAndTest(departmentInstance)
433
434        //Department #2
435        departmentInstance = new Department(name: "Pulp Mill",
436                                                                                description: "Business Department",
437                                                                                site: Site.get(2))
438        saveAndTest(departmentInstance)
439    }
440
441    def createBaseUnitsOfMeasure() {
442
443        //UnitOfMeasure
444        def unitOfMeasureInstance
445
446        //UnitOfMeasure #1
447        unitOfMeasureInstance = new UnitOfMeasure(name: "each")
448        saveAndTest(unitOfMeasureInstance)
449
450        //UnitOfMeasure #2
451        unitOfMeasureInstance = new UnitOfMeasure(name: "meter(s)")
452        saveAndTest(unitOfMeasureInstance)
453
454        //UnitOfMeasure #3
455        unitOfMeasureInstance = new UnitOfMeasure(name: "box(es)")
456        saveAndTest(unitOfMeasureInstance)
457
458        //UnitOfMeasure #4
459        unitOfMeasureInstance = new UnitOfMeasure(name: "litre(s)")
460        saveAndTest(unitOfMeasureInstance)
461
462        //UnitOfMeasure #5
463        unitOfMeasureInstance = new UnitOfMeasure(name: "kilogram(s)")
464        saveAndTest(unitOfMeasureInstance)
465    }
466
467    def createBasePeriods() {
468
469        //Period
470        def periodInstance
471
472        //Period #1
473        periodInstance = new Period(period: "Day(s)")
474        saveAndTest(periodInstance)
475
476        //Period #2
477        periodInstance = new Period(period: "Week(s)")
478        saveAndTest(periodInstance)
479
480        //Period #3
481        periodInstance = new Period(period: "Month(s)")
482        saveAndTest(periodInstance)
483
484        //Period #4
485        periodInstance = new Period(period: "Year(s)")
486        saveAndTest(periodInstance)
487    }
488
489    def createBaseSupplierTypes() {
490
491        // SupplierType
492        def supplierTypeInstance
493
494        // SupplierType #1
495        supplierTypeInstance = new SupplierType(name: "Unknown",
496                                                                    description: "Unknown supplier type")
497        saveAndTest(supplierTypeInstance)
498
499        // SupplierType #2
500        supplierTypeInstance = new SupplierType(name: "OEM",
501                                                                    description: "Original equipment supplier")
502        saveAndTest(supplierTypeInstance)
503
504        // SupplierType #3
505        supplierTypeInstance = new SupplierType(name: "Local",
506                                                                    description: "Local supplier")
507        saveAndTest(supplierTypeInstance)
508    }
509
510    def createBaseManufacturerTypes() {
511
512        // ManufacturerType
513        def manufacturerTypeInstance
514
515        // ManufacturerType #1
516        manufacturerTypeInstance = new ManufacturerType(name: "Unknown",
517                                                                        description: "Unknown manufacturer type")
518        saveAndTest(manufacturerTypeInstance)
519
520        // ManufacturerType #2
521        manufacturerTypeInstance = new ManufacturerType(name: "OEM",
522                                                                        description: "Original equipment manufacturer")
523        saveAndTest(manufacturerTypeInstance)
524
525        // ManufacturerType #3
526        manufacturerTypeInstance = new ManufacturerType(name: "Alternate",
527                                                                        description: "Not original equipment manufacturer")
528        saveAndTest(manufacturerTypeInstance)
529
530    }
531
532    def createBaseAddressTypes() {
533
534        // AddressType
535        def addressTypeInstance
536
537        // AddressType #1
538        addressTypeInstance = new AddressType(name: "Postal",
539                                                                                description: "A postal address.")
540        saveAndTest(addressTypeInstance)
541
542        // AddressType #2
543        addressTypeInstance = new AddressType(name: "Physical",
544                                                                                description: "A physical address.")
545        saveAndTest(addressTypeInstance)
546
547        // AddressType #3
548        addressTypeInstance = new AddressType(name: "Postal & Physical",
549                                                                                description: "An address that is both the postal and physical address.")
550        saveAndTest(addressTypeInstance)
551
552        // AddressType #4
553        addressTypeInstance = new AddressType(name: "Invoice",
554                                                                                description: "An address to send invoices to.")
555        saveAndTest(addressTypeInstance)
556
557        // AddressType #5
558        addressTypeInstance = new AddressType(name: "Delivery",
559                                                                                description: "An address to send deliveries to.")
560        saveAndTest(addressTypeInstance)
561    }
562
563    def createBaseContactTypes() {
564
565        // ContactType
566        def contactTypeInstance
567
568        // ContactType #1
569        contactTypeInstance = new ContactType(name: "Email",
570                                                                                description: "Email address.")
571        saveAndTest(contactTypeInstance)
572
573        // ContactType #2
574        contactTypeInstance = new ContactType(name: "Alternate Email",
575                                                                                description: "Alternate email address.")
576        saveAndTest(contactTypeInstance)
577
578        // ContactType #3
579        contactTypeInstance = new ContactType(name: "Mobile",
580                                                                                description: "Modile phone number.")
581        saveAndTest(contactTypeInstance)
582
583        // ContactType #4
584        contactTypeInstance = new ContactType(name: "Work Phone",
585                                                                                description: "Work phone number.")
586        saveAndTest(contactTypeInstance)
587
588        // ContactType #5
589        contactTypeInstance = new ContactType(name: "Home Phone",
590                                                                                description: "Home phone number.")
591        saveAndTest(contactTypeInstance)
592
593        // ContactType #6
594        contactTypeInstance = new ContactType(name: "Work Fax",
595                                                                                description: "Work fax number.")
596        saveAndTest(contactTypeInstance)
597
598        // ContactType #7
599        contactTypeInstance = new ContactType(name: "Home Fax",
600                                                                                description: "Home fax number.")
601        saveAndTest(contactTypeInstance)
602
603        // ContactType #8
604        contactTypeInstance = new ContactType(name: "Web Site",
605                                                                                description: "Web site address.")
606        saveAndTest(contactTypeInstance)
607
608        // ContactType #9
609        contactTypeInstance = new ContactType(name: "Person",
610                                                                                description: "Contact person.")
611        saveAndTest(contactTypeInstance)
612    }
613
614    def createDemoSuppliers() {
615
616        // Supplier
617        def supplierInstance
618
619        // Supplier #1
620        supplierInstance = new Supplier(name: "OEM Distributors",
621                                                                        supplierType: SupplierType.get(2))
622        saveAndTest(supplierInstance)
623
624        // Supplier #2
625        supplierInstance = new Supplier(name: "Mex Holdings",
626                                                                        supplierType: SupplierType.get(3))
627        saveAndTest(supplierInstance)
628    }
629
630    def createDemoManufacturers() {
631
632        // Manufacturer
633        def manufacturerInstance
634
635        // Manufacturer #1
636        manufacturerInstance = new Manufacturer(name: "OEM Manufacturer",
637                                                                        manufacturerType: ManufacturerType.get(2))
638        saveAndTest(manufacturerInstance)
639
640        // Manufacturer #2
641        manufacturerInstance = new Manufacturer(name: "Laser Cutting Services Pty",
642                                                                        manufacturerType: ManufacturerType.get(3))
643        saveAndTest(manufacturerInstance)
644    }
645
646    def createDemoProductionReference() {
647
648        // ProductionReference
649        def productionReferenceInstance
650
651        // ProductionReference #1
652        productionReferenceInstance = new ProductionReference(name: "Monday Production")
653        saveAndTest(productionReferenceInstance)
654
655        // ProductionReference #2
656        productionReferenceInstance = new ProductionReference(name: "Tuesday Production")
657        saveAndTest(productionReferenceInstance)
658    }
659
660/*********************
661START OF TASK
662*********************/
663
664    def createBaseTaskGroups() {
665        //TaskGroup
666        def taskGroupInstance
667
668        //TaskGroup #1
669        taskGroupInstance = new TaskGroup(name:"Engineering Activites",
670                                                                            description:"Engineering daily activities")
671        saveAndTest(taskGroupInstance)
672
673        //TaskGroup #2
674        taskGroupInstance = new TaskGroup(name:"Production Activites",
675                                                                            description:"Production daily activities")
676        saveAndTest(taskGroupInstance)
677
678        //TaskGroup #3
679        taskGroupInstance = new TaskGroup(name:"New Projects",
680                                                                            description:" ")
681        saveAndTest(taskGroupInstance)
682    }
683
684    def createBaseTaskStatus() {
685
686        //TaskStatus
687        def taskStatusInstance
688
689        taskStatusInstance = new TaskStatus(name:"Not Started") // #1
690        saveAndTest(taskStatusInstance)
691
692        taskStatusInstance = new TaskStatus(name:"In Progress") // #2
693        saveAndTest(taskStatusInstance)
694
695        taskStatusInstance = new TaskStatus(name:"Complete") // #3
696        saveAndTest(taskStatusInstance)
697    }
698
699    def createBaseTaskPriorities() {
700
701        //TaskPriority
702        def taskPriorityInstance
703
704        taskPriorityInstance = new TaskPriority(name:"0 - Immediate") // #1
705        saveAndTest(taskPriorityInstance)
706
707        taskPriorityInstance = new TaskPriority(name:"1 - Very High") // #2
708        saveAndTest(taskPriorityInstance)
709
710        taskPriorityInstance = new TaskPriority(name:"2 - High") // #3
711        saveAndTest(taskPriorityInstance)
712
713        taskPriorityInstance = new TaskPriority(name:"3 - Normal") // #4
714        saveAndTest(taskPriorityInstance)
715
716        taskPriorityInstance = new TaskPriority(name:"4 - Low") // #5
717        saveAndTest(taskPriorityInstance)
718
719        taskPriorityInstance = new TaskPriority(name:"5 - Minor") //  #6
720        saveAndTest(taskPriorityInstance)
721    }
722
723    def createBaseTaskBudgetStatus() {
724
725        //TaskBudgetStatus
726        def taskBudgetStatusInstance
727
728        taskBudgetStatusInstance = new TaskBudgetStatus(name:"Unplanned") // #1
729        saveAndTest(taskBudgetStatusInstance)
730
731        taskBudgetStatusInstance = new TaskBudgetStatus(name:"Planned") // #2
732        saveAndTest(taskBudgetStatusInstance)
733    }
734
735    def createBaseTaskTypes() {
736
737        //TaskType
738        def taskTypeInstance
739
740        taskTypeInstance = new TaskType(name:"Immediate Callout") // #1
741        saveAndTest(taskTypeInstance)
742
743        taskTypeInstance = new TaskType(name:"Unscheduled Breakin") // #2
744        saveAndTest(taskTypeInstance)
745
746        taskTypeInstance = new TaskType(name:"Scheduled") // #3
747        saveAndTest(taskTypeInstance)
748
749        taskTypeInstance = new TaskType(name:"Preventative Maintenance") // #4
750        saveAndTest(taskTypeInstance)
751
752        taskTypeInstance = new TaskType(name:"Predictive Maintenance") // #5
753        saveAndTest(taskTypeInstance)
754
755        taskTypeInstance = new TaskType(name:"Project") // #6
756        saveAndTest(taskTypeInstance)
757    }
758
759    def createBaseTaskModificationTypes() {
760
761        //ModificationType
762        def taskModificationTypeInstance
763        taskModificationTypeInstance = new TaskModificationType(name:"Created").save()  // #1
764        taskModificationTypeInstance = new TaskModificationType(name:"Started").save()  // #2
765        taskModificationTypeInstance = new TaskModificationType(name:"Modified").save()  // #3
766        taskModificationTypeInstance = new TaskModificationType(name:"Completed").save()  // #4
767        taskModificationTypeInstance = new TaskModificationType(name:"Reopened").save()  // #5
768        taskModificationTypeInstance = new TaskModificationType(name:"Trashed").save()  // #6
769        taskModificationTypeInstance = new TaskModificationType(name:"Restored").save()  // #7
770        taskModificationTypeInstance = new TaskModificationType(name:"Approved").save()  // #8
771        taskModificationTypeInstance = new TaskModificationType(name:"Renege approval").save()  // #9
772        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Groups)").save()  // #10
773        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Persons)").save()  // #11
774        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Flagged for attention)").save()  // #12
775        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Attention flag cleared)").save()  // #13
776    }
777
778    def createDemoTasks() {
779
780        def taskResult
781        def p = [:]
782
783        //Task #1
784        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
785                taskPriority:TaskPriority.get(2),
786                taskType:TaskType.get(1),
787                leadPerson:Person.get(2),
788                description:"Level sensor not working",
789                comment:"Has been noted as problematic, try recalibrating.",
790                targetStartDate: dateUtilService.today]
791
792        taskResult = taskService.save(p)
793
794        //Task #2
795        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
796                taskPriority:TaskPriority.get(2),
797                taskType:TaskType.get(3),
798                leadPerson:Person.get(5),
799                description:"Some follow-up work",
800                comment:"Some help required",
801                targetStartDate: dateUtilService.tomorrow,
802                parentTask: Task.get(1)]
803
804        taskResult = taskService.save(p)
805
806        //Task #3
807        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
808                taskPriority:TaskPriority.get(2),
809                taskType:TaskType.get(3),
810                leadPerson:Person.get(5),
811                description:"A Sub Task can be created from the 'Sub Task' tab.",
812                comment:"Some help required",
813                targetStartDate: dateUtilService.yesterday,
814                parentTask: Task.get(1)]
815
816        taskResult = taskService.save(p)
817
818        //Task #4
819        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
820                 taskPriority:TaskPriority.get(2),
821                 taskType:TaskType.get(2),
822                 leadPerson:Person.get(4),
823                 description:"Please replace sensor at next available opportunity.",
824                 comment:"Nothing else has worked. So we now require the part to be replaced.",
825                targetStartDate: dateUtilService.oneWeekFromNow,
826                parentTask: Task.get(1)]
827
828        taskResult = taskService.save(p)
829
830        //Task #5
831        p = [taskGroup:TaskGroup.findByName("Production Activites"),
832                 taskPriority:TaskPriority.get(2),
833                 taskType:TaskType.get(3),
834                 leadPerson:Person.get(6),
835                 description:"Production Task",
836                 comment:"Production task for specific production run or shift",
837                targetStartDate: dateUtilService.today - 6]
838
839        taskResult = taskService.save(p)
840
841        //Task #6
842        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
843                 taskPriority:TaskPriority.get(4),
844                 taskType:TaskType.get(3),
845                 leadPerson:Person.get(4),
846                 description:"This is a recurring preventative maintenance task.",
847                 comment:"If there is a parent task specified then this is a generated sub task, if there is a recurring schedule specified then this is a parent task.",
848                targetStartDate: dateUtilService.today]
849
850        taskResult = taskService.save(p)
851    }
852
853    def createBaseEntryTypes() {
854
855        //EntryType
856        def entryTypeInstance
857
858        entryTypeInstance = new EntryType(name:"Fault") // #1
859        saveAndTest(entryTypeInstance)
860
861        entryTypeInstance = new EntryType(name:"Cause") // #2
862        saveAndTest(entryTypeInstance)
863
864        entryTypeInstance = new EntryType(name:"Work Done") // #3
865        saveAndTest(entryTypeInstance)
866
867        entryTypeInstance = new EntryType(name:"Production Note") // #4
868        saveAndTest(entryTypeInstance)
869
870        entryTypeInstance = new EntryType(name:"Work Request") // #5
871        saveAndTest(entryTypeInstance)
872    }
873
874    def createDemoEntries() {
875
876        def entryResult
877        def p = [:]
878
879        //Entry #1
880        p = [task: Task.get(1),
881                entryType: EntryType.get(1),
882                comment: "This level sensor is causing us trouble.",
883                durationMinute: 20]
884
885        entryResult = taskService.saveEntry(p)
886
887        //Entry #2
888        p = [task: Task.get(1),
889                entryType: EntryType.get(3),
890                comment: "Cleaned sensor, see how it goes.",
891                durationMinute: 30]
892
893        entryResult = taskService.saveEntry(p)
894
895        //Entry #3
896        p = [task: Task.get(1),
897                entryType: EntryType.get(3),
898                comment: "Checked up on it later and sensor is dropping out intermittently, created sub task to replace sensor.",
899                durationMinute: 20]
900
901        entryResult = taskService.saveEntry(p)
902    }
903
904    def createDemoAssignedGroups() {
905
906        def result
907        def p = [:]
908
909        //AssignedGroup #1
910        p = [personGroup: PersonGroup.get(1),
911                task: Task.get(1),
912                estimatedHour: 2,
913                estimatedMinute: 30]
914        result = assignedGroupService.save(p)
915
916        //AssignedGroup #2
917        p = [personGroup: PersonGroup.get(2),
918                task: Task.get(1),
919                estimatedHour: 1,
920                estimatedMinute: 0]
921        result = assignedGroupService.save(p)
922    }
923
924    def createDemoAssignedPersons() {
925
926        def result
927        def p = [:]
928
929        //AssignedPerson #1
930        p = [person: Person.get(4),
931                task: Task.get(1),
932                estimatedHour: 1,
933                estimatedMinute: 20]
934        result = assignedPersonService.save(p)
935
936        //AssignedPerson #2
937        p = [person: Person.get(5),
938                task: Task.get(1),
939                estimatedHour: 3,
940                estimatedMinute: 30]
941        result = assignedPersonService.save(p)
942    }
943
944    def createDemoTaskRecurringSchedules() {
945
946        //TaskRecurringSchedule
947        def taskRecurringScheduleInstance
948
949        //TaskRecurringSchedule #1
950        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1),
951                                                                                                    recurEvery: 1,
952                                                                                                    recurPeriod: Period.get(2),
953                                                                                                    nextTargetStartDate: dateUtilService.today,
954                                                                                                    generateAhead: 1,
955                                                                                                    taskDuration: 2,
956                                                                                                    taskDurationPeriod: Period.get(1),
957                                                                                                    enabled: false)
958        saveAndTest(taskRecurringScheduleInstance)
959
960        //TaskRecurringSchedule #2
961        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(6),
962                                                                                                    recurEvery: 1,
963                                                                                                    recurPeriod: Period.get(1),
964                                                                                                    nextTargetStartDate: dateUtilService.today,
965                                                                                                    generateAhead: 1,
966                                                                                                    taskDuration: 1,
967                                                                                                    taskDurationPeriod: Period.get(1),
968                                                                                                    enabled: true)
969        saveAndTest(taskRecurringScheduleInstance)
970    }
971
972/*************************
973START OF INVENTORY
974**************************/
975
976    def createDemoInventoryStores() {
977
978        //InventoryStore
979        def inventoryStoreInstance
980
981        inventoryStoreInstance = new InventoryStore(site: Site.get(1), name: "Store #1")
982        saveAndTest(inventoryStoreInstance)
983
984        inventoryStoreInstance = new InventoryStore(site: Site.get(2), name: "Store #2")
985        saveAndTest(inventoryStoreInstance)
986    }
987
988    def createDemoInventoryLocations() {
989
990        // InventoryLocation
991        def inventoryLocation
992
993        inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(1), name: "A1-2")
994        saveAndTest(inventoryLocation)
995
996        inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(2), name: "C55")
997        saveAndTest(inventoryLocation)
998    }
999
1000    def createDemoInventoryGroups() {
1001
1002        //InventoryGroup
1003        def inventoryGroupInstance
1004
1005        //InventoryGroup #1
1006        inventoryGroupInstance = new InventoryGroup(name: "Misc")
1007        saveAndTest(inventoryGroupInstance)
1008
1009        //InventoryGroup #2
1010        inventoryGroupInstance = new InventoryGroup(name: "Electrical")
1011        saveAndTest(inventoryGroupInstance)
1012
1013        //InventoryGroup #3
1014        inventoryGroupInstance = new InventoryGroup(name: "Mechanical")
1015        saveAndTest(inventoryGroupInstance)
1016
1017        //InventoryGroup #4
1018        inventoryGroupInstance = new InventoryGroup(name: "Production")
1019        saveAndTest(inventoryGroupInstance)
1020    }
1021
1022    def createBaseInventoryTypes() {
1023
1024        //InventoryType
1025        def inventoryTypeInstance
1026
1027        inventoryTypeInstance = new InventoryType(name: "Consumable")
1028        saveAndTest(inventoryTypeInstance)
1029
1030        inventoryTypeInstance = new InventoryType(name: "Repairable")
1031        saveAndTest(inventoryTypeInstance)
1032    }
1033
1034    def createBaseInventoryMovementTypes() {
1035
1036        // InventoryMovementType
1037        def inventoryMovementTypeInstance
1038
1039        // InventoryMovementType #1
1040        inventoryMovementTypeInstance = new InventoryMovementType(name: "Used",
1041                                                                                                                        incrementsInventory: false)
1042        saveAndTest(inventoryMovementTypeInstance)
1043
1044        // InventoryMovementType #2
1045        inventoryMovementTypeInstance = new InventoryMovementType(name: "Repaired",
1046                                                                                                                        incrementsInventory: true)
1047        saveAndTest(inventoryMovementTypeInstance)
1048
1049        // InventoryMovementType #3
1050        inventoryMovementTypeInstance = new InventoryMovementType(name: "Purchase Received",
1051                                                                                                                        incrementsInventory: true)
1052        saveAndTest(inventoryMovementTypeInstance)
1053
1054        // InventoryMovementType #4
1055        inventoryMovementTypeInstance = new InventoryMovementType(name: "Correction Increase",
1056                                                                                                                        incrementsInventory: true)
1057        saveAndTest(inventoryMovementTypeInstance)
1058
1059        // InventoryMovementType #5
1060        inventoryMovementTypeInstance = new InventoryMovementType(name: "Correction Decrease",
1061                                                                                                                        incrementsInventory: false)
1062        saveAndTest(inventoryMovementTypeInstance)
1063    }
1064
1065    def createDemoInventoryItems() {
1066
1067        //InventoryItem
1068        def inventoryItemInstance
1069
1070        //InventoryItem #1
1071        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
1072                                                                                    inventoryType: InventoryType.get(1),
1073                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
1074                                                                                    inventoryLocation: InventoryLocation.get(1),
1075                                                                                    name: "Hemp rope",
1076                                                                                    description: "Natural hemp rope.",
1077                                                                                    unitsInStock: 2,
1078                                                                                    reorderPoint: 0)
1079        saveAndTest(inventoryItemInstance)
1080
1081        //InventoryItem #2
1082        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
1083                                                                                    inventoryType: InventoryType.get(1),
1084                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
1085                                                                                    inventoryLocation: InventoryLocation.get(1),
1086                                                                                    name: "Cotton Rope 12mm",
1087                                                                                    description: "A soft natural rope made from cotton.",
1088                                                                                    alternateItems: InventoryItem.get(1),
1089                                                                                    unitsInStock: 2,
1090                                                                                    reorderPoint: 0)
1091        saveAndTest(inventoryItemInstance)
1092
1093        //InventoryItem #3
1094        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1095                                                                                    inventoryType: InventoryType.get(1),
1096                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1097                                                                                    inventoryLocation: InventoryLocation.get(2),
1098                                                                                    name: "2305-2RS",
1099                                                                                    description: "Bearing 25x62x24mm double row self aligning ball",
1100                                                                                    unitsInStock: 3,
1101                                                                                    reorderPoint: 2)
1102        saveAndTest(inventoryItemInstance)
1103
1104        //InventoryItem #4
1105        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2),
1106                                                                                    inventoryType: InventoryType.get(1),
1107                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1108                                                                                    inventoryLocation: InventoryLocation.get(2),
1109                                                                                    name: "L1592-K10",
1110                                                                                    description: "10kW contactor",
1111                                                                                    unitsInStock: 4,
1112                                                                                    reorderPoint: 0)
1113        saveAndTest(inventoryItemInstance)
1114
1115        //InventoryItem #5
1116        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1117                                                                                    inventoryType: InventoryType.get(1),
1118                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1119                                                                                    inventoryLocation: InventoryLocation.get(2),
1120                                                                                    name: "6205-ZZ",
1121                                                                                    description: "Bearing 25x52x15mm single row ball shielded",
1122                                                                                    unitsInStock: 5,
1123                                                                                    reorderPoint: 2)
1124        saveAndTest(inventoryItemInstance)
1125    }
1126
1127/*******************
1128START OF ASSET
1129*******************/
1130
1131    def createDemoLifePlan() {
1132
1133        //LifePlan
1134        def lifeplanInstance
1135
1136        lifeplanInstance = new LifePlan(name: "Initial Plan")
1137        saveAndTest(lifeplanInstance)
1138    }
1139
1140    def createBaseExtenededAttributeTypes() {
1141
1142        //ExtendedAttributeType
1143        def extendedAttributeTypeInstance
1144
1145        //ExtendedAttributeType #1
1146        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Model Number")
1147        saveAndTest(extendedAttributeTypeInstance)
1148
1149        //ExtendedAttributeType #2
1150        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Purchase Cost")
1151        saveAndTest(extendedAttributeTypeInstance)
1152
1153        //ExtendedAttributeType #3
1154        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Serial Number")
1155        saveAndTest(extendedAttributeTypeInstance)
1156
1157        //ExtendedAttributeType #4
1158        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufactured Date")
1159        saveAndTest(extendedAttributeTypeInstance)
1160
1161        //ExtendedAttributeType #5
1162        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Location Description")
1163        saveAndTest(extendedAttributeTypeInstance)
1164
1165        //ExtendedAttributeType #6
1166        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Cost Centre")
1167        saveAndTest(extendedAttributeTypeInstance)
1168
1169        //ExtendedAttributeType #7
1170        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Cost Code")
1171        saveAndTest(extendedAttributeTypeInstance)
1172
1173        //ExtendedAttributeType #8
1174        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufacturer's Number")
1175        saveAndTest(extendedAttributeTypeInstance)
1176
1177        //ExtendedAttributeType #9
1178        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Inventory Number")
1179        saveAndTest(extendedAttributeTypeInstance)
1180    }
1181
1182    def createBaseMaintenancePolicies() {
1183
1184        //MaintenancePolicy
1185        def maintenancePolicyInstance
1186
1187        //MaintenancePolicy #1
1188        maintenancePolicyInstance = new MaintenancePolicy(name: "Fixed Time")
1189        saveAndTest(maintenancePolicyInstance)
1190
1191        //MaintenancePolicy #2
1192        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Online")
1193        saveAndTest(maintenancePolicyInstance)
1194
1195        //MaintenancePolicy #3
1196        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Offline")
1197        saveAndTest(maintenancePolicyInstance)
1198
1199        //MaintenancePolicy #4
1200        maintenancePolicyInstance = new MaintenancePolicy(name: "Design Out")
1201        saveAndTest(maintenancePolicyInstance)
1202
1203        //MaintenancePolicy #5
1204        maintenancePolicyInstance = new MaintenancePolicy(name: "Operate To Failure")
1205        saveAndTest(maintenancePolicyInstance)
1206
1207        //MaintenancePolicy #6
1208        maintenancePolicyInstance = new MaintenancePolicy(name: "Regulatory Requirement")
1209        saveAndTest(maintenancePolicyInstance)
1210
1211        //MaintenancePolicy #7
1212        maintenancePolicyInstance = new MaintenancePolicy(name: "Hidden Function Test")
1213        saveAndTest(maintenancePolicyInstance)
1214    }
1215
1216    def createDemoTaskProcedure() {
1217
1218        //TaskProcedure
1219        def taskProcedureInstance
1220
1221        taskProcedureInstance = new TaskProcedure(name: "Daily check")
1222        saveAndTest(taskProcedureInstance)
1223        taskProcedureInstance.addToTasks(Task.get(1))
1224    }
1225
1226    def createDemoMaintenanceActions() {
1227
1228        //MaintenanceAction
1229        def maintenanceActionInstance
1230
1231        //MaintenanceAction #1
1232        maintenanceActionInstance = new MaintenanceAction(description: "Check all E-stops, activate E-stops S1-S12 and ensure machine cannot run",
1233                                                                                                        procedureStepNumber: 1,
1234                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1235                                                                                                        taskProcedure: TaskProcedure.get(1))
1236        saveAndTest(maintenanceActionInstance)
1237
1238        //MaintenanceAction #2
1239        maintenanceActionInstance = new MaintenanceAction(description: "Do more pushups",
1240                                                                                                        procedureStepNumber: 2,
1241                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1242                                                                                                        taskProcedure: TaskProcedure.get(1))
1243        saveAndTest(maintenanceActionInstance)
1244
1245        //MaintenanceAction #3
1246        maintenanceActionInstance = new MaintenanceAction(description: "Ok just one more pushup",
1247                                                                                                        procedureStepNumber: 3,
1248                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1249                                                                                                        taskProcedure: TaskProcedure.get(1))
1250        saveAndTest(maintenanceActionInstance)
1251    }
1252
1253    def createDemoSections() {
1254
1255        //Section
1256        def sectionInstance
1257
1258        //Section #1
1259        sectionInstance = new Section(name: "Press",
1260                                                                description: "Press Section",
1261                                                                site: Site.get(3),
1262                                                                department: Department.get(1))
1263        saveAndTest(sectionInstance)
1264
1265        //Section #2
1266        sectionInstance = new Section(name: "CSM-Delig",
1267                                                                description: "Pulp Delignification",
1268                                                                site: Site.get(1),
1269                                                                department: Department.get(2))
1270        saveAndTest(sectionInstance)
1271
1272        //Section #3
1273        sectionInstance = new Section(name: "CSM-Aux",
1274                                                                description: "Auxilliary Section",
1275                                                                site: Site.get(1),
1276                                                                department: Department.get(1))
1277        saveAndTest(sectionInstance)
1278    }
1279
1280    def createDemoAssetTree() {
1281
1282        //Asset
1283        def assetInstance
1284
1285        //Asset #1
1286        def assetInstance1 = new Asset(name: "Print Tower 22",
1287                                                                description: "Complete Printing Asset #22",
1288                                                                section: Section.get(1))
1289        saveAndTest(assetInstance1)
1290//        assetInstance.addToMaintenanceActions(MaintenanceAction.get(1))
1291
1292        //Asset #2
1293        def assetInstance2 = new Asset(name: "Print Tower 21",
1294                                                                description: "Complete Printing Asset #21",
1295                                                                section: Section.get(1))
1296        saveAndTest(assetInstance2)
1297
1298        //Asset #3
1299        def assetInstance3 = new Asset(name: "Print Tower 23",
1300                                                                description: "Complete Printing Asset #23",
1301                                                                section: Section.get(1))
1302        saveAndTest(assetInstance3)
1303
1304        //Asset #4
1305        def assetInstance4 = new Asset(name: "C579",
1306                                                                description: "RO #1",
1307                                                                section: Section.get(2))
1308        saveAndTest(assetInstance4)
1309
1310        //AssetSubItem
1311        def assetSubItemInstance
1312
1313        //AssetSubItem #1 Level1
1314        def assetSubItemInstance1 = new AssetSubItem(name: "Print Tower",
1315                                                                                            description: "Common sub asset.")
1316        saveAndTest(assetSubItemInstance1)
1317
1318        // Add assetSubItemInstance1 to some assets.
1319        assetInstance1.addToAssetSubItems(assetSubItemInstance1)
1320        assetInstance2.addToAssetSubItems(assetSubItemInstance1)
1321        assetInstance3.addToAssetSubItems(assetSubItemInstance1)
1322
1323        //AssetSubItem #2 Level1
1324        def assetSubItemInstance2 = new AssetSubItem(name: "C579-44",
1325                                                                                            description: "Tanks and towers")
1326        saveAndTest(assetSubItemInstance2)
1327
1328        // Add assetSubItemInstance2 to some assets.
1329        assetInstance4.addToAssetSubItems(assetSubItemInstance2)
1330
1331        //AssetSubItem #3 Level1
1332        def assetSubItemInstance3 = new AssetSubItem(name: "C579-20",
1333                                                                                            description: "Control Loops")
1334        saveAndTest(assetSubItemInstance3)
1335
1336        // Add assetSubItemInstance3 to some assets.
1337        assetInstance4.addToAssetSubItems(assetSubItemInstance3)
1338
1339        //AssetSubItem #4 Level2
1340        assetSubItemInstance = new AssetSubItem(name: "C579-TK-0022",
1341                                                                                            description: "Blow Tank",
1342                                                                                            parentItem: AssetSubItem.get(2))
1343        saveAndTest(assetSubItemInstance)
1344
1345        //AssetSubItem #5 Level2
1346        assetSubItemInstance = new AssetSubItem(name: "C579-TK-0023",
1347                                                                                            description: "Reactor Tower",
1348                                                                                            parentItem: AssetSubItem.get(2))
1349        saveAndTest(assetSubItemInstance)
1350
1351        //AssetSubItem #6 Level2
1352        assetSubItemInstance = new AssetSubItem(name: "Print Unit",
1353                                                                                    description: "Print Unit - Common Level 2 sub item.",
1354                                                                                    parentItem: AssetSubItem.get(1))
1355        saveAndTest(assetSubItemInstance)
1356
1357        //AssetSubItem #7 Level2
1358        assetSubItemInstance = new AssetSubItem(name: "1925365",
1359                                                                                    description: "Agitator",
1360                                                                                    parentItem: AssetSubItem.get(4))
1361        saveAndTest(assetSubItemInstance)
1362
1363        //AssetSubItem #8 Level2
1364        assetSubItemInstance = new AssetSubItem(name: "1925366",
1365                                                                                    description: "Scraper",
1366                                                                                    parentItem: AssetSubItem.get(4))
1367        saveAndTest(assetSubItemInstance)
1368
1369        //AssetSubItem #9 Level3
1370        assetSubItemInstance = new AssetSubItem(name: "Motor",
1371                                                                                    description: "Motor - Level 3 sub item",
1372                                                                                    parentItem: AssetSubItem.get(6))
1373        saveAndTest(assetSubItemInstance)
1374
1375        //AssetSubItem #10 Level3
1376        assetSubItemInstance = new AssetSubItem(name: "Gearbox",
1377                                                                                    description: "Gearbox - Level 3 sub item, gearbox",
1378                                                                                    parentItem: AssetSubItem.get(6))
1379        saveAndTest(assetSubItemInstance)
1380
1381        //AssetSubItem #11 Level4
1382        assetSubItemInstance = new AssetSubItem(name: "DS Bearing",
1383                                                                                    description: "Drive Side Bearing",
1384                                                                                    parentItem: AssetSubItem.get(9))
1385        saveAndTest(assetSubItemInstance)
1386
1387        //AssetSubItem #12 Level4
1388        assetSubItemInstance = new AssetSubItem(name: "NDS Bearing",
1389                                                                                    description: "Non Drive Side Bearing",
1390                                                                                    parentItem: AssetSubItem.get(9))
1391        saveAndTest(assetSubItemInstance)
1392
1393        //AssetSubItem #13 Level2
1394        assetSubItemInstance = new AssetSubItem(name: "C579-F-0001",
1395                                                                                    description: "Weak Caustic Flow",
1396                                                                                    parentItem: AssetSubItem.get(3))
1397        saveAndTest(assetSubItemInstance)
1398
1399        //AssetSubItem #14 Level3
1400        assetSubItemInstance = new AssetSubItem(name: "C579-FT-0002",
1401                                                                                    description: "Weak Caustic Flow Transmitter",
1402                                                                                    parentItem: AssetSubItem.get(13))
1403        saveAndTest(assetSubItemInstance)
1404
1405        //AssetSubItem #15 Level3
1406        assetSubItemInstance = new AssetSubItem(name: "C579-PT-0003",
1407                                                                                    description: "Weak Caustic Pressure Transmitter",
1408                                                                                    parentItem: AssetSubItem.get(13))
1409        saveAndTest(assetSubItemInstance)
1410    } // createDemoAssetTree()
1411
1412    def createDemoAssetExtenedAttributes() {
1413
1414        //AssetExtendedAttribute
1415        def assetExtendedAttributeInstance
1416
1417        //AssetExtendedAttribute #1
1418        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "PU Mark 2",
1419                                                                                                                    asset: Asset.get(1),
1420                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(1))
1421        saveAndTest(assetExtendedAttributeInstance)
1422
1423        //AssetExtendedAttribute #2
1424        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5",
1425                                                                                                                    asset: Asset.get(1),
1426                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(5))
1427        saveAndTest(assetExtendedAttributeInstance)
1428    }
1429
1430
1431/****************************************
1432Call this function instead of .save()
1433*****************************************/
1434    private boolean saveAndTest(object) {
1435        if(!object.save()) {
1436//             DemoDataSuccessful = false
1437            log.error "'${object}' failed to save!"
1438            log.error object.errors
1439            return false
1440        }
1441        return true
1442    }
1443}
Note: See TracBrowser for help on using the repository browser.