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

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

Add more base task groups as per ticket #65.

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