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

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

Add estimatedUnitPrice to demo data.

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