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

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

Add more base task groups as per ticket #65.

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