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

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

Add constraints to Task domain class for targetCompletionDate and comment, part 2.

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