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

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

Work on inventory types base data, added "Tool" and "Service", changed "Repairable" to "Rotable".

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