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

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

Add some extendedAttribute base and demo data.

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