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

Last change on this file since 720 was 720, checked in by gav, 13 years ago

Domain change: as per ticket #96 - Remove unused fields from InventoryItem?.
Removed InventoryItem?.alternateItems.

File size: 79.0 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                                                                                    unitsInStock: 2,
1300                                                                                    reorderPoint: 0)
1301        saveAndTest(inventoryItemInstance)
1302        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
1303
1304        //InventoryItem #3
1305        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1306                                                                                    inventoryType: InventoryType.get(1),
1307                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1308                                                                                    inventoryLocation: InventoryLocation.get(2),
1309                                                                                    name: "2305-2RS",
1310                                                                                    description: "Bearing 25x62x24mm double row self aligning ball",
1311                                                                                    estimatedUnitPriceAmount: 5,
1312                                                                                    estimatedUnitPriceCurrency: currency,
1313                                                                                    unitsInStock: 3,
1314                                                                                    reorderPoint: 2)
1315        saveAndTest(inventoryItemInstance)
1316        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
1317
1318        //InventoryItem #4
1319        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2),
1320                                                                                    inventoryType: InventoryType.get(1),
1321                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1322                                                                                    inventoryLocation: InventoryLocation.get(2),
1323                                                                                    name: "L1592-K10",
1324                                                                                    description: "10kW contactor",
1325                                                                                    estimatedUnitPriceAmount: 180,
1326                                                                                    estimatedUnitPriceCurrency: currency,
1327                                                                                    unitsInStock: 4,
1328                                                                                    reorderPoint: 0)
1329        saveAndTest(inventoryItemInstance)
1330        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
1331
1332        //InventoryItem #5
1333        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1334                                                                                    inventoryType: InventoryType.get(1),
1335                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
1336                                                                                    inventoryLocation: InventoryLocation.get(2),
1337                                                                                    name: "6205-ZZ",
1338                                                                                    description: "Bearing 25x52x15mm single row ball shielded",
1339                                                                                    estimatedUnitPriceAmount: 3.45,
1340                                                                                    estimatedUnitPriceCurrency: currency,
1341                                                                                    unitsInStock: 5,
1342                                                                                    reorderPoint: 2)
1343        saveAndTest(inventoryItemInstance)
1344        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
1345    }
1346
1347/*******************
1348START OF ASSET
1349*******************/
1350
1351    def createDemoLifePlan() {
1352
1353        //LifePlan
1354        def lifeplanInstance
1355
1356        lifeplanInstance = new LifePlan(name: "Initial Plan")
1357        saveAndTest(lifeplanInstance)
1358    }
1359
1360    def createBaseExtenededAttributeTypes() {
1361
1362        //ExtendedAttributeType
1363        def extendedAttributeTypeInstance
1364
1365        //ExtendedAttributeType #1
1366        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Model Number")
1367        saveAndTest(extendedAttributeTypeInstance)
1368
1369        //ExtendedAttributeType #2
1370        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Purchase Cost")
1371        saveAndTest(extendedAttributeTypeInstance)
1372
1373        //ExtendedAttributeType #3
1374        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Serial Number")
1375        saveAndTest(extendedAttributeTypeInstance)
1376
1377        //ExtendedAttributeType #4
1378        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufactured Date")
1379        saveAndTest(extendedAttributeTypeInstance)
1380
1381        //ExtendedAttributeType #5
1382        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Location Description")
1383        saveAndTest(extendedAttributeTypeInstance)
1384
1385        //ExtendedAttributeType #6
1386        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Cost Centre")
1387        saveAndTest(extendedAttributeTypeInstance)
1388
1389        //ExtendedAttributeType #7
1390        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Cost Code")
1391        saveAndTest(extendedAttributeTypeInstance)
1392
1393        //ExtendedAttributeType #8
1394        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufacturer")
1395        saveAndTest(extendedAttributeTypeInstance)
1396
1397        //ExtendedAttributeType #9
1398        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "ecr")
1399        saveAndTest(extendedAttributeTypeInstance)
1400
1401        //ExtendedAttributeType #10
1402        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Risk Level")
1403        saveAndTest(extendedAttributeTypeInstance)
1404
1405        //ExtendedAttributeType #11
1406        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Safe Work Procedure")
1407        saveAndTest(extendedAttributeTypeInstance)
1408
1409        //ExtendedAttributeType #12
1410        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Regulatory Requirement")
1411        saveAndTest(extendedAttributeTypeInstance)
1412
1413        //ExtendedAttributeType #13
1414        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Maintenance % Completion")
1415        saveAndTest(extendedAttributeTypeInstance)
1416
1417        //ExtendedAttributeType #14
1418        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Registration Required")
1419        saveAndTest(extendedAttributeTypeInstance)
1420
1421        //ExtendedAttributeType #15
1422        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Registration Expiry Date")
1423        saveAndTest(extendedAttributeTypeInstance)
1424
1425        //ExtendedAttributeType #16
1426        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Asset Condition")
1427        saveAndTest(extendedAttributeTypeInstance)
1428
1429        //ExtendedAttributeType #17
1430        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Asset Number")
1431        saveAndTest(extendedAttributeTypeInstance)
1432    }
1433
1434    def createDemoSections() {
1435
1436        //Section
1437        def sectionInstance
1438
1439        //Section #1
1440        sectionInstance = new Section(name: "A-Press",
1441                                                                description: "Press Section",
1442                                                                site: Site.get(3),
1443                                                                department: Department.get(1))
1444        saveAndTest(sectionInstance)
1445
1446        //Section #2
1447        sectionInstance = new Section(name: "CSM-Delig",
1448                                                                description: "Pulp Delignification",
1449                                                                site: Site.get(1),
1450                                                                department: Department.get(2))
1451        saveAndTest(sectionInstance)
1452
1453        //Section #3
1454        sectionInstance = new Section(name: "CSM-Aux",
1455                                                                description: "Auxilliary Section",
1456                                                                site: Site.get(1),
1457                                                                department: Department.get(1))
1458        saveAndTest(sectionInstance)
1459    }
1460
1461    def createDemoAssetTree() {
1462
1463        //Asset
1464        def assetInstance
1465
1466        //Asset #1
1467        def assetInstance1 = new Asset(name: "Print Tower 22",
1468                                                                description: "Complete Printing Asset #22",
1469                                                                comment: "Includes everthing directly attached to the tower.",
1470                                                                section: Section.get(1))
1471        saveAndTest(assetInstance1)
1472//        assetInstance.addToMaintenanceActions(MaintenanceAction.get(1))
1473
1474        //Asset #2
1475        def assetInstance2 = new Asset(name: "Print Tower 21",
1476                                                                description: "Complete Printing Asset #21",
1477                                                                section: Section.get(1))
1478        saveAndTest(assetInstance2)
1479
1480        //Asset #3
1481        def assetInstance3 = new Asset(name: "Print Tower 23",
1482                                                                description: "Complete Printing Asset #23",
1483                                                                section: Section.get(1))
1484        saveAndTest(assetInstance3)
1485
1486        //Asset #4
1487        def assetInstance4 = new Asset(name: "C579",
1488                                                                description: "RO #1",
1489                                                                section: Section.get(2))
1490        saveAndTest(assetInstance4)
1491
1492        //AssetSubItem
1493        def assetSubItemInstance
1494
1495        //AssetSubItem #1 Level1
1496        def assetSubItemInstance1 = new AssetSubItem(name: "Print Tower",
1497                                                                                            description: "Common sub asset.")
1498        saveAndTest(assetSubItemInstance1)
1499
1500        // Add assetSubItemInstance1 to some assets.
1501        assetInstance1.addToAssetSubItems(assetSubItemInstance1)
1502        assetInstance2.addToAssetSubItems(assetSubItemInstance1)
1503        assetInstance3.addToAssetSubItems(assetSubItemInstance1)
1504
1505        //AssetSubItem #2 Level1
1506        def assetSubItemInstance2 = new AssetSubItem(name: "C579-44",
1507                                                                                            description: "Tanks and towers")
1508        saveAndTest(assetSubItemInstance2)
1509
1510        // Add assetSubItemInstance2 to some assets.
1511        assetInstance4.addToAssetSubItems(assetSubItemInstance2)
1512
1513        //AssetSubItem #3 Level1
1514        def assetSubItemInstance3 = new AssetSubItem(name: "C579-20",
1515                                                                                            description: "Control Loops")
1516        saveAndTest(assetSubItemInstance3)
1517
1518        // Add assetSubItemInstance3 to some assets.
1519        assetInstance4.addToAssetSubItems(assetSubItemInstance3)
1520
1521        //AssetSubItem #4 Level2
1522        assetSubItemInstance = new AssetSubItem(name: "C579-TK-0022",
1523                                                                                            description: "Blow Tank",
1524                                                                                            parentItem: AssetSubItem.get(2))
1525        saveAndTest(assetSubItemInstance)
1526
1527        //AssetSubItem #5 Level2
1528        assetSubItemInstance = new AssetSubItem(name: "C579-TK-0023",
1529                                                                                            description: "Reactor Tower",
1530                                                                                            parentItem: AssetSubItem.get(2))
1531        saveAndTest(assetSubItemInstance)
1532
1533        //AssetSubItem #6 Level2
1534        assetSubItemInstance = new AssetSubItem(name: "Print Unit",
1535                                                                                    description: "Print Unit - Common Level 2 sub item.",
1536                                                                                    parentItem: AssetSubItem.get(1))
1537        saveAndTest(assetSubItemInstance)
1538
1539        //AssetSubItem #7 Level2
1540        assetSubItemInstance = new AssetSubItem(name: "1925365",
1541                                                                                    description: "Agitator",
1542                                                                                    parentItem: AssetSubItem.get(4))
1543        saveAndTest(assetSubItemInstance)
1544
1545        //AssetSubItem #8 Level2
1546        assetSubItemInstance = new AssetSubItem(name: "1925366",
1547                                                                                    description: "Scraper",
1548                                                                                    parentItem: AssetSubItem.get(4))
1549        saveAndTest(assetSubItemInstance)
1550
1551        //AssetSubItem #9 Level3
1552        assetSubItemInstance = new AssetSubItem(name: "Motor",
1553                                                                                    description: "Motor - Level 3 sub item",
1554                                                                                    parentItem: AssetSubItem.get(6))
1555        saveAndTest(assetSubItemInstance)
1556
1557        //AssetSubItem #10 Level3
1558        assetSubItemInstance = new AssetSubItem(name: "Gearbox",
1559                                                                                    description: "Gearbox - Level 3 sub item, gearbox",
1560                                                                                    parentItem: AssetSubItem.get(6))
1561        saveAndTest(assetSubItemInstance)
1562
1563        //AssetSubItem #11 Level4
1564        assetSubItemInstance = new AssetSubItem(name: "DS Bearing",
1565                                                                                    description: "Drive Side Bearing",
1566                                                                                    parentItem: AssetSubItem.get(9))
1567        saveAndTest(assetSubItemInstance)
1568
1569        //AssetSubItem #12 Level4
1570        assetSubItemInstance = new AssetSubItem(name: "NDS Bearing",
1571                                                                                    description: "Non Drive Side Bearing",
1572                                                                                    parentItem: AssetSubItem.get(9))
1573        saveAndTest(assetSubItemInstance)
1574
1575        //AssetSubItem #13 Level2
1576        assetSubItemInstance = new AssetSubItem(name: "C579-F-0001",
1577                                                                                    description: "Weak Caustic Flow",
1578                                                                                    parentItem: AssetSubItem.get(3))
1579        saveAndTest(assetSubItemInstance)
1580
1581        //AssetSubItem #14 Level3
1582        assetSubItemInstance = new AssetSubItem(name: "C579-FT-0002",
1583                                                                                    description: "Weak Caustic Flow Transmitter",
1584                                                                                    parentItem: AssetSubItem.get(13))
1585        saveAndTest(assetSubItemInstance)
1586
1587        //AssetSubItem #15 Level3
1588        assetSubItemInstance = new AssetSubItem(name: "C579-PT-0003",
1589                                                                                    description: "Weak Caustic Pressure Transmitter",
1590                                                                                    parentItem: AssetSubItem.get(13))
1591        saveAndTest(assetSubItemInstance)
1592    } // createDemoAssetTree()
1593
1594    def createDemoAssetSubItemExtendedAttributes() {
1595
1596        //AssetSubItemExtendedAttribute
1597        def assetSubItemExtendedAttributeInstance
1598
1599        //AssetSubItemExtendedAttribute #1
1600        assetSubItemExtendedAttributeInstance = new AssetSubItemExtendedAttribute(value: "United Press",
1601                                                                                                                    assetSubItem: AssetSubItem.get(1),
1602                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(8)) // Manufacturer.
1603        saveAndTest(assetSubItemExtendedAttributeInstance)
1604
1605        //AssetSubItemExtendedAttribute #2
1606        assetSubItemExtendedAttributeInstance = new AssetSubItemExtendedAttribute(value: "PU Mark 2",
1607                                                                                                                    assetSubItem: AssetSubItem.get(1),
1608                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(1)) // Model Number.
1609        saveAndTest(assetSubItemExtendedAttributeInstance)
1610
1611        //AssetSubItemExtendedAttribute #3
1612        assetSubItemExtendedAttributeInstance = new AssetSubItemExtendedAttribute(value: "765895",
1613                                                                                                                    assetSubItem: AssetSubItem.get(1),
1614                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(3)) // Serial Number.
1615        saveAndTest(assetSubItemExtendedAttributeInstance)
1616
1617        //AssetSubItemExtendedAttribute #4
1618        assetSubItemExtendedAttributeInstance = new AssetSubItemExtendedAttribute(value: "Jan-2003",
1619                                                                                                                    assetSubItem: AssetSubItem.get(1),
1620                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(4)) // Manufactured Date.
1621        saveAndTest(assetSubItemExtendedAttributeInstance)
1622
1623    }
1624
1625    def createDemoAssetExtendedAttributes() {
1626
1627        //AssetExtendedAttribute
1628        def assetExtendedAttributeInstance
1629
1630        //AssetExtendedAttribute #1
1631        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5",
1632                                                                                                            asset: Asset.get(1),
1633                                                                                                            extendedAttributeType: ExtendedAttributeType.get(5)) // Location Description.
1634        saveAndTest(assetExtendedAttributeInstance)
1635
1636        //AssetExtendedAttribute #2
1637        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "3",
1638                                                                                                            asset: Asset.get(1),
1639                                                                                                            extendedAttributeType: ExtendedAttributeType.get(9)) // ecr.
1640        saveAndTest(assetExtendedAttributeInstance)
1641
1642        //AssetExtendedAttribute #3
1643        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "RP-001",
1644                                                                                                            asset: Asset.get(1),
1645                                                                                                            extendedAttributeType: ExtendedAttributeType.get(17)) // Asset Number.
1646        saveAndTest(assetExtendedAttributeInstance)
1647
1648        //AssetExtendedAttribute #4
1649        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "Good",
1650                                                                                                            asset: Asset.get(1),
1651                                                                                                            extendedAttributeType: ExtendedAttributeType.get(16)) // Asset Condition.
1652        saveAndTest(assetExtendedAttributeInstance)
1653
1654        //AssetExtendedAttribute #5
1655        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "TBA",
1656                                                                                                            asset: Asset.get(1),
1657                                                                                                            extendedAttributeType: ExtendedAttributeType.get(13)) // Maintenance % Completion.
1658        saveAndTest(assetExtendedAttributeInstance)
1659
1660        //AssetExtendedAttribute #6
1661        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "Y",
1662                                                                                                            asset: Asset.get(1),
1663                                                                                                            extendedAttributeType: ExtendedAttributeType.get(14)) // Registration Required.
1664        saveAndTest(assetExtendedAttributeInstance)
1665
1666        //AssetExtendedAttribute #7
1667        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "Feb-2009",
1668                                                                                                            asset: Asset.get(1),
1669                                                                                                            extendedAttributeType: ExtendedAttributeType.get(15)) // Registration Expiry Date.
1670        saveAndTest(assetExtendedAttributeInstance)
1671
1672        //AssetExtendedAttribute #8
1673        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "N",
1674                                                                                                            asset: Asset.get(1),
1675                                                                                                            extendedAttributeType: ExtendedAttributeType.get(12)) // Regulatory Requirement.
1676        saveAndTest(assetExtendedAttributeInstance)
1677
1678        //AssetExtendedAttribute #9
1679        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "Med",
1680                                                                                                            asset: Asset.get(1),
1681                                                                                                            extendedAttributeType: ExtendedAttributeType.get(10)) // Risk Level.
1682        saveAndTest(assetExtendedAttributeInstance)
1683
1684        //AssetExtendedAttribute #10
1685        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "WP-003",
1686                                                                                                            asset: Asset.get(1),
1687                                                                                                            extendedAttributeType: ExtendedAttributeType.get(11)) // Safe Work Procedure.
1688        saveAndTest(assetExtendedAttributeInstance)
1689    }
1690
1691    /**
1692    * SearchableIndex and mirroring is disabled at startup.
1693    * Use this to start indexing after creating bootstrap data.
1694    * @param indexInNewThread Whether to run the index in a new thread, defaults to true.
1695    */
1696    def startSearchableIndex(Boolean indexInNewThread = true) {
1697        log.info "Start mirroring searchable index."
1698        ConfigurationHolder.config.appSearchable.cascadeOnUpdate = true
1699        searchableService.startMirroring()
1700        if(indexInNewThread) {
1701            Thread.start {
1702                log.info "Rebuilding searchable index, bulkIndex (new thread)."
1703                searchableService.index()
1704                log.info "Rebuilding searchable index, complete."
1705            }
1706        }
1707        else {
1708            log.info "Rebuilding searchable index, bulkIndex."
1709            searchableService.index()
1710            log.info "Rebuilding searchable index, complete."
1711        }
1712    }
1713
1714    /**
1715    * Searchable index and mirroring during bulk data creation may be slow.
1716    * Use this to stop indexing and restart with startSearchableIndex() after data creation.
1717    */
1718    def stopSearchableIndex() {
1719        log.info "Stop mirroring searchable index."
1720        ConfigurationHolder.config.appSearchable.cascadeOnUpdate = false
1721        searchableService.stopMirroring()
1722    }
1723
1724    /**
1725    * Call this function instead of .save()
1726    */
1727    private boolean saveAndTest(object) {
1728        if(!object.save()) {
1729//             DemoDataSuccessful = false
1730            log.error "'${object}' failed to save!"
1731            log.error object.errors
1732            return false
1733        }
1734        return true
1735    }
1736
1737} // end of class
Note: See TracBrowser for help on using the repository browser.