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

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

Add ProductionReference.
Add ProductionManager and ProductionUser roles.
Update immediate callout help definitions, roll errors into one ul.
Add help definitions for resolved and unresolved.

File size: 62.1 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:"Normal") // #1
705        saveAndTest(taskPriorityInstance)
706
707        taskPriorityInstance = new TaskPriority(name:"Low") // #2
708        saveAndTest(taskPriorityInstance)
709
710        taskPriorityInstance = new TaskPriority(name:"High") // #3
711        saveAndTest(taskPriorityInstance)
712
713        taskPriorityInstance = new TaskPriority(name:"Immediate") // #4
714        saveAndTest(taskPriorityInstance)
715    }
716
717    def createBaseTaskBudgetStatus() {
718
719        //TaskBudgetStatus
720        def taskBudgetStatusInstance
721
722        taskBudgetStatusInstance = new TaskBudgetStatus(name:"Unplanned") // #1
723        saveAndTest(taskBudgetStatusInstance)
724
725        taskBudgetStatusInstance = new TaskBudgetStatus(name:"Planned") // #2
726        saveAndTest(taskBudgetStatusInstance)
727    }
728
729    def createBaseTaskTypes() {
730
731        //TaskType
732        def taskTypeInstance
733
734        taskTypeInstance = new TaskType(name:"Immediate Callout") // #1
735        saveAndTest(taskTypeInstance)
736
737        taskTypeInstance = new TaskType(name:"Unscheduled Breakin") // #2
738        saveAndTest(taskTypeInstance)
739
740        taskTypeInstance = new TaskType(name:"Scheduled") // #3
741        saveAndTest(taskTypeInstance)
742
743        taskTypeInstance = new TaskType(name:"Preventative Maintenance") // #4
744        saveAndTest(taskTypeInstance)
745
746        taskTypeInstance = new TaskType(name:"Predictive Maintenance") // #5
747        saveAndTest(taskTypeInstance)
748
749        taskTypeInstance = new TaskType(name:"Project") // #6
750        saveAndTest(taskTypeInstance)
751    }
752
753    def createBaseTaskModificationTypes() {
754
755        //ModificationType
756        def taskModificationTypeInstance
757        taskModificationTypeInstance = new TaskModificationType(name:"Created").save()  // #1
758        taskModificationTypeInstance = new TaskModificationType(name:"Started").save()  // #2
759        taskModificationTypeInstance = new TaskModificationType(name:"Modified").save()  // #3
760        taskModificationTypeInstance = new TaskModificationType(name:"Completed").save()  // #4
761        taskModificationTypeInstance = new TaskModificationType(name:"Reopened").save()  // #5
762        taskModificationTypeInstance = new TaskModificationType(name:"Trashed").save()  // #6
763        taskModificationTypeInstance = new TaskModificationType(name:"Restored").save()  // #7
764        taskModificationTypeInstance = new TaskModificationType(name:"Approved").save()  // #8
765        taskModificationTypeInstance = new TaskModificationType(name:"Renege approval").save()  // #9
766        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Groups)").save()  // #10
767        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Persons)").save()  // #11
768        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Flagged for attention)").save()  // #12
769        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Attention flag cleared)").save()  // #13
770    }
771
772    def createDemoTasks() {
773
774        def taskResult
775        def p = [:]
776
777        //Task #1
778        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
779                taskPriority:TaskPriority.get(2),
780                taskType:TaskType.get(1),
781                leadPerson:Person.get(2),
782                description:"Level sensor not working",
783                comment:"Has been noted as problematic, try recalibrating.",
784                targetStartDate: dateUtilService.today]
785
786        taskResult = taskService.save(p)
787
788        //Task #2
789        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
790                taskPriority:TaskPriority.get(2),
791                taskType:TaskType.get(3),
792                leadPerson:Person.get(5),
793                description:"Some follow-up work",
794                comment:"Some help required",
795                targetStartDate: dateUtilService.tomorrow,
796                parentTask: Task.get(1)]
797
798        taskResult = taskService.save(p)
799
800        //Task #3
801        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
802                taskPriority:TaskPriority.get(2),
803                taskType:TaskType.get(3),
804                leadPerson:Person.get(5),
805                description:"A Sub Task can be created from the 'Sub Task' tab.",
806                comment:"Some help required",
807                targetStartDate: dateUtilService.yesterday,
808                parentTask: Task.get(1)]
809
810        taskResult = taskService.save(p)
811
812        //Task #4
813        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
814                 taskPriority:TaskPriority.get(2),
815                 taskType:TaskType.get(2),
816                 leadPerson:Person.get(4),
817                 description:"Please replace sensor at next available opportunity.",
818                 comment:"Nothing else has worked. So we now require the part to be replaced.",
819                targetStartDate: dateUtilService.oneWeekFromNow,
820                parentTask: Task.get(1)]
821
822        taskResult = taskService.save(p)
823
824        //Task #5
825        p = [taskGroup:TaskGroup.findByName("Production Activites"),
826                 taskPriority:TaskPriority.get(2),
827                 taskType:TaskType.get(3),
828                 leadPerson:Person.get(6),
829                 description:"Production Task",
830                 comment:"Production task for specific production run or shift",
831                targetStartDate: dateUtilService.today - 6]
832
833        taskResult = taskService.save(p)
834
835        //Task #6
836        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
837                 taskPriority:TaskPriority.get(4),
838                 taskType:TaskType.get(3),
839                 leadPerson:Person.get(4),
840                 description:"This is a recurring preventative maintenance task.",
841                 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.",
842                targetStartDate: dateUtilService.today]
843
844        taskResult = taskService.save(p)
845    }
846
847    def createBaseEntryTypes() {
848
849        //EntryType
850        def entryTypeInstance
851
852        entryTypeInstance = new EntryType(name:"Fault") // #1
853        saveAndTest(entryTypeInstance)
854
855        entryTypeInstance = new EntryType(name:"Cause") // #2
856        saveAndTest(entryTypeInstance)
857
858        entryTypeInstance = new EntryType(name:"Work Done") // #3
859        saveAndTest(entryTypeInstance)
860
861        entryTypeInstance = new EntryType(name:"Production Note") // #4
862        saveAndTest(entryTypeInstance)
863
864        entryTypeInstance = new EntryType(name:"Work Request") // #5
865        saveAndTest(entryTypeInstance)
866    }
867
868    def createDemoEntries() {
869
870        def entryResult
871        def p = [:]
872
873        //Entry #1
874        p = [task: Task.get(1),
875                entryType: EntryType.get(1),
876                comment: "This level sensor is causing us trouble.",
877                durationMinute: 20]
878
879        entryResult = taskService.saveEntry(p)
880
881        //Entry #2
882        p = [task: Task.get(1),
883                entryType: EntryType.get(3),
884                comment: "Cleaned sensor, see how it goes.",
885                durationMinute: 30]
886
887        entryResult = taskService.saveEntry(p)
888
889        //Entry #3
890        p = [task: Task.get(1),
891                entryType: EntryType.get(3),
892                comment: "Checked up on it later and sensor is dropping out intermittently, created sub task to replace sensor.",
893                durationMinute: 20]
894
895        entryResult = taskService.saveEntry(p)
896    }
897
898    def createDemoAssignedGroups() {
899
900        def result
901        def p = [:]
902
903        //AssignedGroup #1
904        p = [personGroup: PersonGroup.get(1),
905                task: Task.get(1),
906                estimatedHour: 2,
907                estimatedMinute: 30]
908        result = assignedGroupService.save(p)
909
910        //AssignedGroup #2
911        p = [personGroup: PersonGroup.get(2),
912                task: Task.get(1),
913                estimatedHour: 1,
914                estimatedMinute: 0]
915        result = assignedGroupService.save(p)
916    }
917
918    def createDemoAssignedPersons() {
919
920        def result
921        def p = [:]
922
923        //AssignedPerson #1
924        p = [person: Person.get(4),
925                task: Task.get(1),
926                estimatedHour: 1,
927                estimatedMinute: 20]
928        result = assignedPersonService.save(p)
929
930        //AssignedPerson #2
931        p = [person: Person.get(5),
932                task: Task.get(1),
933                estimatedHour: 3,
934                estimatedMinute: 30]
935        result = assignedPersonService.save(p)
936    }
937
938    def createDemoTaskRecurringSchedules() {
939
940        //TaskRecurringSchedule
941        def taskRecurringScheduleInstance
942
943        //TaskRecurringSchedule #1
944        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1),
945                                                                                                    recurEvery: 1,
946                                                                                                    recurPeriod: Period.get(2),
947                                                                                                    nextTargetStartDate: dateUtilService.today,
948                                                                                                    generateAhead: 1,
949                                                                                                    taskDuration: 2,
950                                                                                                    taskDurationPeriod: Period.get(1),
951                                                                                                    enabled: false)
952        saveAndTest(taskRecurringScheduleInstance)
953
954        //TaskRecurringSchedule #2
955        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(6),
956                                                                                                    recurEvery: 1,
957                                                                                                    recurPeriod: Period.get(1),
958                                                                                                    nextTargetStartDate: dateUtilService.today,
959                                                                                                    generateAhead: 1,
960                                                                                                    taskDuration: 1,
961                                                                                                    taskDurationPeriod: Period.get(1),
962                                                                                                    enabled: true)
963        saveAndTest(taskRecurringScheduleInstance)
964    }
965
966/*************************
967START OF INVENTORY
968**************************/
969
970    def createDemoInventoryStores() {
971
972        //InventoryStore
973        def inventoryStoreInstance
974
975        inventoryStoreInstance = new InventoryStore(site: Site.get(1), name: "Store #1")
976        saveAndTest(inventoryStoreInstance)
977
978        inventoryStoreInstance = new InventoryStore(site: Site.get(2), name: "Store #2")
979        saveAndTest(inventoryStoreInstance)
980    }
981
982    def createDemoInventoryLocations() {
983
984        // InventoryLocation
985        def inventoryLocation
986
987        inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(1), name: "A1-2")
988        saveAndTest(inventoryLocation)
989
990        inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(2), name: "C55")
991        saveAndTest(inventoryLocation)
992    }
993
994    def createDemoInventoryGroups() {
995
996        //InventoryGroup
997        def inventoryGroupInstance
998
999        //InventoryGroup #1
1000        inventoryGroupInstance = new InventoryGroup(name: "Misc")
1001        saveAndTest(inventoryGroupInstance)
1002
1003        //InventoryGroup #2
1004        inventoryGroupInstance = new InventoryGroup(name: "Electrical")
1005        saveAndTest(inventoryGroupInstance)
1006
1007        //InventoryGroup #3
1008        inventoryGroupInstance = new InventoryGroup(name: "Mechanical")
1009        saveAndTest(inventoryGroupInstance)
1010
1011        //InventoryGroup #4
1012        inventoryGroupInstance = new InventoryGroup(name: "Production")
1013        saveAndTest(inventoryGroupInstance)
1014    }
1015
1016    def createBaseInventoryTypes() {
1017
1018        //InventoryType
1019        def inventoryTypeInstance
1020
1021        inventoryTypeInstance = new InventoryType(name: "Consumable")
1022        saveAndTest(inventoryTypeInstance)
1023
1024        inventoryTypeInstance = new InventoryType(name: "Repairable")
1025        saveAndTest(inventoryTypeInstance)
1026    }
1027
1028    def createBaseInventoryMovementTypes() {
1029
1030        // InventoryMovementType
1031        def inventoryMovementTypeInstance
1032
1033        // InventoryMovementType #1
1034        inventoryMovementTypeInstance = new InventoryMovementType(name: "Used",
1035                                                                                                                        incrementsInventory: false)
1036        saveAndTest(inventoryMovementTypeInstance)
1037
1038        // InventoryMovementType #2
1039        inventoryMovementTypeInstance = new InventoryMovementType(name: "Repaired",
1040                                                                                                                        incrementsInventory: true)
1041        saveAndTest(inventoryMovementTypeInstance)
1042
1043        // InventoryMovementType #3
1044        inventoryMovementTypeInstance = new InventoryMovementType(name: "Purchase Received",
1045                                                                                                                        incrementsInventory: true)
1046        saveAndTest(inventoryMovementTypeInstance)
1047
1048        // InventoryMovementType #4
1049        inventoryMovementTypeInstance = new InventoryMovementType(name: "Correction Increase",
1050                                                                                                                        incrementsInventory: true)
1051        saveAndTest(inventoryMovementTypeInstance)
1052
1053        // InventoryMovementType #5
1054        inventoryMovementTypeInstance = new InventoryMovementType(name: "Correction Decrease",
1055                                                                                                                        incrementsInventory: false)
1056        saveAndTest(inventoryMovementTypeInstance)
1057    }
1058
1059    def createDemoInventoryItems() {
1060
1061        //InventoryItem
1062        def inventoryItemInstance
1063
1064        //InventoryItem #1
1065        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
1066                                                                                    inventoryType: InventoryType.get(1),
1067                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
1068                                                                                    inventoryLocation: InventoryLocation.get(1),
1069                                                                                    name: "Hemp rope",
1070                                                                                    description: "Natural hemp rope.",
1071                                                                                    unitsInStock: 2,
1072                                                                                    reorderPoint: 0)
1073        saveAndTest(inventoryItemInstance)
1074
1075        //InventoryItem #2
1076        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
1077                                                                                    inventoryType: InventoryType.get(1),
1078                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
1079                                                                                    inventoryLocation: InventoryLocation.get(1),
1080                                                                                    name: "Cotton Rope 12mm",
1081                                                                                    description: "A soft natural rope made from cotton.",
1082                                                                                    alternateItems: InventoryItem.get(1),
1083                                                                                    unitsInStock: 2,
1084                                                                                    reorderPoint: 0)
1085        saveAndTest(inventoryItemInstance)
1086
1087        //InventoryItem #3
1088        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1089                                                                                    inventoryType: InventoryType.get(1),
1090                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1091                                                                                    inventoryLocation: InventoryLocation.get(2),
1092                                                                                    name: "2305-2RS",
1093                                                                                    description: "Bearing 25x62x24mm double row self aligning ball",
1094                                                                                    unitsInStock: 3,
1095                                                                                    reorderPoint: 2)
1096        saveAndTest(inventoryItemInstance)
1097
1098        //InventoryItem #4
1099        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2),
1100                                                                                    inventoryType: InventoryType.get(1),
1101                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1102                                                                                    inventoryLocation: InventoryLocation.get(2),
1103                                                                                    name: "L1592-K10",
1104                                                                                    description: "10kW contactor",
1105                                                                                    unitsInStock: 4,
1106                                                                                    reorderPoint: 0)
1107        saveAndTest(inventoryItemInstance)
1108
1109        //InventoryItem #5
1110        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1111                                                                                    inventoryType: InventoryType.get(1),
1112                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1113                                                                                    inventoryLocation: InventoryLocation.get(2),
1114                                                                                    name: "6205-ZZ",
1115                                                                                    description: "Bearing 25x52x15mm single row ball shielded",
1116                                                                                    unitsInStock: 5,
1117                                                                                    reorderPoint: 2)
1118        saveAndTest(inventoryItemInstance)
1119    }
1120
1121/*******************
1122START OF ASSET
1123*******************/
1124
1125    def createDemoLifePlan() {
1126
1127        //LifePlan
1128        def lifeplanInstance
1129
1130        lifeplanInstance = new LifePlan(name: "Initial Plan")
1131        saveAndTest(lifeplanInstance)
1132    }
1133
1134    def createBaseExtenededAttributeTypes() {
1135
1136        //ExtendedAttributeType
1137        def extendedAttributeTypeInstance
1138
1139        //ExtendedAttributeType #1
1140        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Model Number")
1141        saveAndTest(extendedAttributeTypeInstance)
1142
1143        //ExtendedAttributeType #2
1144        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Purchase Cost")
1145        saveAndTest(extendedAttributeTypeInstance)
1146
1147        //ExtendedAttributeType #3
1148        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Serial Number")
1149        saveAndTest(extendedAttributeTypeInstance)
1150
1151        //ExtendedAttributeType #4
1152        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufactured Date")
1153        saveAndTest(extendedAttributeTypeInstance)
1154
1155        //ExtendedAttributeType #5
1156        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Location Description")
1157        saveAndTest(extendedAttributeTypeInstance)
1158
1159        //ExtendedAttributeType #6
1160        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Cost Centre")
1161        saveAndTest(extendedAttributeTypeInstance)
1162
1163        //ExtendedAttributeType #7
1164        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Cost Code")
1165        saveAndTest(extendedAttributeTypeInstance)
1166
1167        //ExtendedAttributeType #8
1168        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufacturer's Number")
1169        saveAndTest(extendedAttributeTypeInstance)
1170
1171        //ExtendedAttributeType #9
1172        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Inventory Number")
1173        saveAndTest(extendedAttributeTypeInstance)
1174    }
1175
1176    def createBaseMaintenancePolicies() {
1177
1178        //MaintenancePolicy
1179        def maintenancePolicyInstance
1180
1181        //MaintenancePolicy #1
1182        maintenancePolicyInstance = new MaintenancePolicy(name: "Fixed Time")
1183        saveAndTest(maintenancePolicyInstance)
1184
1185        //MaintenancePolicy #2
1186        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Online")
1187        saveAndTest(maintenancePolicyInstance)
1188
1189        //MaintenancePolicy #3
1190        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Offline")
1191        saveAndTest(maintenancePolicyInstance)
1192
1193        //MaintenancePolicy #4
1194        maintenancePolicyInstance = new MaintenancePolicy(name: "Design Out")
1195        saveAndTest(maintenancePolicyInstance)
1196
1197        //MaintenancePolicy #5
1198        maintenancePolicyInstance = new MaintenancePolicy(name: "Operate To Failure")
1199        saveAndTest(maintenancePolicyInstance)
1200
1201        //MaintenancePolicy #6
1202        maintenancePolicyInstance = new MaintenancePolicy(name: "Regulatory Requirement")
1203        saveAndTest(maintenancePolicyInstance)
1204
1205        //MaintenancePolicy #7
1206        maintenancePolicyInstance = new MaintenancePolicy(name: "Hidden Function Test")
1207        saveAndTest(maintenancePolicyInstance)
1208    }
1209
1210    def createDemoTaskProcedure() {
1211
1212        //TaskProcedure
1213        def taskProcedureInstance
1214
1215        taskProcedureInstance = new TaskProcedure(name: "Daily check")
1216        saveAndTest(taskProcedureInstance)
1217        taskProcedureInstance.addToTasks(Task.get(1))
1218    }
1219
1220    def createDemoMaintenanceActions() {
1221
1222        //MaintenanceAction
1223        def maintenanceActionInstance
1224
1225        //MaintenanceAction #1
1226        maintenanceActionInstance = new MaintenanceAction(description: "Check all E-stops, activate E-stops S1-S12 and ensure machine cannot run",
1227                                                                                                        procedureStepNumber: 1,
1228                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1229                                                                                                        taskProcedure: TaskProcedure.get(1))
1230        saveAndTest(maintenanceActionInstance)
1231
1232        //MaintenanceAction #2
1233        maintenanceActionInstance = new MaintenanceAction(description: "Do more pushups",
1234                                                                                                        procedureStepNumber: 2,
1235                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1236                                                                                                        taskProcedure: TaskProcedure.get(1))
1237        saveAndTest(maintenanceActionInstance)
1238
1239        //MaintenanceAction #3
1240        maintenanceActionInstance = new MaintenanceAction(description: "Ok just one more pushup",
1241                                                                                                        procedureStepNumber: 3,
1242                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1243                                                                                                        taskProcedure: TaskProcedure.get(1))
1244        saveAndTest(maintenanceActionInstance)
1245    }
1246
1247    def createDemoSections() {
1248
1249        //Section
1250        def sectionInstance
1251
1252        //Section #1
1253        sectionInstance = new Section(name: "Press",
1254                                                                description: "Press Section",
1255                                                                site: Site.get(3),
1256                                                                department: Department.get(1))
1257        saveAndTest(sectionInstance)
1258
1259        //Section #2
1260        sectionInstance = new Section(name: "CSM-Delig",
1261                                                                description: "Pulp Delignification",
1262                                                                site: Site.get(1),
1263                                                                department: Department.get(2))
1264        saveAndTest(sectionInstance)
1265
1266        //Section #3
1267        sectionInstance = new Section(name: "CSM-Aux",
1268                                                                description: "Auxilliary Section",
1269                                                                site: Site.get(1),
1270                                                                department: Department.get(1))
1271        saveAndTest(sectionInstance)
1272    }
1273
1274    def createDemoAssetTree() {
1275
1276        //Asset
1277        def assetInstance
1278
1279        //Asset #1
1280        def assetInstance1 = new Asset(name: "Print Tower 22",
1281                                                                description: "Complete Printing Asset #22",
1282                                                                section: Section.get(1))
1283        saveAndTest(assetInstance1)
1284//        assetInstance.addToMaintenanceActions(MaintenanceAction.get(1))
1285
1286        //Asset #2
1287        def assetInstance2 = new Asset(name: "Print Tower 21",
1288                                                                description: "Complete Printing Asset #21",
1289                                                                section: Section.get(1))
1290        saveAndTest(assetInstance2)
1291
1292        //Asset #3
1293        def assetInstance3 = new Asset(name: "Print Tower 23",
1294                                                                description: "Complete Printing Asset #23",
1295                                                                section: Section.get(1))
1296        saveAndTest(assetInstance3)
1297
1298        //Asset #4
1299        def assetInstance4 = new Asset(name: "C579",
1300                                                                description: "RO #1",
1301                                                                section: Section.get(2))
1302        saveAndTest(assetInstance4)
1303
1304        //AssetSubItem
1305        def assetSubItemInstance
1306
1307        //AssetSubItem #1 Level1
1308        def assetSubItemInstance1 = new AssetSubItem(name: "Print Tower",
1309                                                                                            description: "Common sub asset.")
1310        saveAndTest(assetSubItemInstance1)
1311
1312        // Add assetSubItemInstance1 to some assets.
1313        assetInstance1.addToAssetSubItems(assetSubItemInstance1)
1314        assetInstance2.addToAssetSubItems(assetSubItemInstance1)
1315        assetInstance3.addToAssetSubItems(assetSubItemInstance1)
1316
1317        //AssetSubItem #2 Level1
1318        def assetSubItemInstance2 = new AssetSubItem(name: "C579-44",
1319                                                                                            description: "Tanks and towers")
1320        saveAndTest(assetSubItemInstance2)
1321
1322        // Add assetSubItemInstance2 to some assets.
1323        assetInstance4.addToAssetSubItems(assetSubItemInstance2)
1324
1325        //AssetSubItem #3 Level1
1326        def assetSubItemInstance3 = new AssetSubItem(name: "C579-20",
1327                                                                                            description: "Control Loops")
1328        saveAndTest(assetSubItemInstance3)
1329
1330        // Add assetSubItemInstance3 to some assets.
1331        assetInstance4.addToAssetSubItems(assetSubItemInstance3)
1332
1333        //AssetSubItem #4 Level2
1334        assetSubItemInstance = new AssetSubItem(name: "C579-TK-0022",
1335                                                                                            description: "Blow Tank",
1336                                                                                            parentItem: AssetSubItem.get(2))
1337        saveAndTest(assetSubItemInstance)
1338
1339        //AssetSubItem #5 Level2
1340        assetSubItemInstance = new AssetSubItem(name: "C579-TK-0023",
1341                                                                                            description: "Reactor Tower",
1342                                                                                            parentItem: AssetSubItem.get(2))
1343        saveAndTest(assetSubItemInstance)
1344
1345        //AssetSubItem #6 Level2
1346        assetSubItemInstance = new AssetSubItem(name: "Print Unit",
1347                                                                                    description: "Print Unit - Common Level 2 sub item.",
1348                                                                                    parentItem: AssetSubItem.get(1))
1349        saveAndTest(assetSubItemInstance)
1350
1351        //AssetSubItem #7 Level2
1352        assetSubItemInstance = new AssetSubItem(name: "1925365",
1353                                                                                    description: "Agitator",
1354                                                                                    parentItem: AssetSubItem.get(4))
1355        saveAndTest(assetSubItemInstance)
1356
1357        //AssetSubItem #8 Level2
1358        assetSubItemInstance = new AssetSubItem(name: "1925366",
1359                                                                                    description: "Scraper",
1360                                                                                    parentItem: AssetSubItem.get(4))
1361        saveAndTest(assetSubItemInstance)
1362
1363        //AssetSubItem #9 Level3
1364        assetSubItemInstance = new AssetSubItem(name: "Motor",
1365                                                                                    description: "Motor - Level 3 sub item",
1366                                                                                    parentItem: AssetSubItem.get(6))
1367        saveAndTest(assetSubItemInstance)
1368
1369        //AssetSubItem #10 Level3
1370        assetSubItemInstance = new AssetSubItem(name: "Gearbox",
1371                                                                                    description: "Gearbox - Level 3 sub item, gearbox",
1372                                                                                    parentItem: AssetSubItem.get(6))
1373        saveAndTest(assetSubItemInstance)
1374
1375        //AssetSubItem #11 Level4
1376        assetSubItemInstance = new AssetSubItem(name: "DS Bearing",
1377                                                                                    description: "Drive Side Bearing",
1378                                                                                    parentItem: AssetSubItem.get(9))
1379        saveAndTest(assetSubItemInstance)
1380
1381        //AssetSubItem #12 Level4
1382        assetSubItemInstance = new AssetSubItem(name: "NDS Bearing",
1383                                                                                    description: "Non Drive Side Bearing",
1384                                                                                    parentItem: AssetSubItem.get(9))
1385        saveAndTest(assetSubItemInstance)
1386
1387        //AssetSubItem #13 Level2
1388        assetSubItemInstance = new AssetSubItem(name: "C579-F-0001",
1389                                                                                    description: "Weak Caustic Flow",
1390                                                                                    parentItem: AssetSubItem.get(3))
1391        saveAndTest(assetSubItemInstance)
1392
1393        //AssetSubItem #14 Level3
1394        assetSubItemInstance = new AssetSubItem(name: "C579-FT-0002",
1395                                                                                    description: "Weak Caustic Flow Transmitter",
1396                                                                                    parentItem: AssetSubItem.get(13))
1397        saveAndTest(assetSubItemInstance)
1398
1399        //AssetSubItem #15 Level3
1400        assetSubItemInstance = new AssetSubItem(name: "C579-PT-0003",
1401                                                                                    description: "Weak Caustic Pressure Transmitter",
1402                                                                                    parentItem: AssetSubItem.get(13))
1403        saveAndTest(assetSubItemInstance)
1404    } // createDemoAssetTree()
1405
1406    def createDemoAssetExtenedAttributes() {
1407
1408        //AssetExtendedAttribute
1409        def assetExtendedAttributeInstance
1410
1411        //AssetExtendedAttribute #1
1412        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "PU Mark 2",
1413                                                                                                                    asset: Asset.get(1),
1414                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(1))
1415        saveAndTest(assetExtendedAttributeInstance)
1416
1417        //AssetExtendedAttribute #2
1418        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5",
1419                                                                                                                    asset: Asset.get(1),
1420                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(5))
1421        saveAndTest(assetExtendedAttributeInstance)
1422    }
1423
1424
1425/****************************************
1426Call this function instead of .save()
1427*****************************************/
1428    private boolean saveAndTest(object) {
1429        if(!object.save()) {
1430//             DemoDataSuccessful = false
1431            log.error "'${object}' failed to save!"
1432            log.error object.errors
1433            return false
1434        }
1435        return true
1436    }
1437}
Note: See TracBrowser for help on using the repository browser.