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

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

Start lucene mirroring and index after creating bootstrap data.

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