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
RevLine 
[622]1import org.codehaus.groovy.grails.commons.ConfigurationHolder
2
[149]3/**
4* Provides a data service to create base and demo data.
[180]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.
[149]8*/
9class  CreateDataService {
10
11    boolean transactional = false
12
[291]13    def authService
[180]14    def taskService
[210]15    def dateUtilService
[237]16    def appConfigService
[571]17    def searchableService
[549]18    def inventoryItemService
[251]19    def assignedGroupService
20    def assignedPersonService
[180]21
[549]22    def grailsApplication
23
[149]24/*******************************************
25Start of Group methods.
26Generally use these methods to create data.
27*******************************************/
28
29    /**
[199]30    * Always call this at startup to ensure that we have admin access
31    * and that the system pseudo person is available.
[149]32    */
[199]33    def ensureSystemAndAdminAccess() {
[149]34        if(!Authority.findByAuthority("ROLE_AppAdmin") ) {
[199]35            log.warn "ROLE_AppAdmin not found, calling createAdminAuthority()."
[149]36            createAdminAuthority()
37        }
[199]38        if(!Person.findByloginName("system") ) {
39            log.warn "LoginName 'system' not found, calling createSystemPerson()."
40            createSystemPerson()
41        }
[149]42        if(!Person.findByloginName("admin") ) {
[199]43            log.warn "LoginName 'admin' not found, calling createAdminPerson()."
[149]44            createAdminPerson()
45        }
46    }
47
48    /**
49    * Create the base data required for the application to function.
50    */
51    def createBaseData() {
[237]52
53        if(appConfigService.exists("baseDataCreated")) {
[506]54            log.info "Base data previously created."
[237]55            return false
56        }
57
[506]58        log.info "Creating base data."
[237]59
[149]60        // Person and Utils
61        createBaseAuthorities()
[506]62        createBasePersonGroupTypes()
[149]63        createBasePersonGroups()
[265]64        createBaseDefinitions()
[149]65        createBaseUnitsOfMeasure()
66        createBasePeriods()
[397]67        createBaseSupplierTypes()
68        createBaseManufacturerTypes()
69        createBaseAddressTypes()
[402]70        createBaseContactTypes()
[534]71        createBaseMaintenancePolicies()
[441]72        createBaseInventoryItemPurchaseTypes()
[237]73
[534]74        // Assets
75        createBaseExtenededAttributeTypes()
76
77        // Inventory
78        createBaseInventoryTypes()
79        createBaseInventoryMovementTypes()
80
[149]81        // Tasks
[180]82        createBaseTaskGroups()
[149]83        createBaseTaskStatus()
84        createBaseTaskPriorities()
[252]85        createBaseTaskBudgetStatus()
[149]86        createBaseTaskTypes()
[180]87        createBaseTaskModificationTypes()
[149]88        createBaseEntryTypes()
[237]89
90        // Record that data has been created.
91        appConfigService.set("baseDataCreated")
[149]92    }
93
94    /**
95    * Create demo data for some example sites.
96    */
97    def createDemoData() {
[237]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
[199]114        log.info "Creating demo data..."
[237]115
[149]116        // Person and Utils
117        createDemoSites()
[162]118        createDemoDepartments()
[175]119        createDemoSuppliers()
120        createDemoManufacturers()
[431]121        createDemoProductionReference()
[633]122        createDemoPurchasingGroups()  /// @todo: Perhaps a 'createQuickStartData' method?
[441]123        createDemoCostCodes()
[633]124        createDemoPersons()
[237]125
[534]126        // Assets
127        createDemoLifePlan()
128        createDemoSections()
129        createDemoAssetTree()
[685]130        createDemoAssetExtendedAttributes()
131        createDemoAssetSubItemExtendedAttributes()
[237]132
[149]133        // Inventory
134        createDemoInventoryStores()  /// @todo: Perhaps a 'createQuickStartData' method?
[175]135        createDemoInventoryLocations()
[149]136        createDemoInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method?
137        createDemoInventoryItems()
[237]138
[534]139        // Tasks
140        createDemoTasks()
141        createDemoEntries()
142        createDemoAssignedGroups()
143        createDemoAssignedPersons()
[149]144        createDemoTaskProcedure()
145        createDemoMaintenanceActions()
[534]146        createDemoTaskRecurringSchedules()
[237]147
148        // Record that data has been created.
149        appConfigService.set("demoDataCreated")
[149]150    }
151
152/******************
153Start of Person
154*******************/
155
156    def createAdminAuthority() {
157        def authInstance
158
[294]159        // Authority #1
[431]160        authInstance = new Authority(description:"Application Admin, not required for daily use! \
161                                                                                Grants full admin access to the application.",
[149]162                                        authority:"ROLE_AppAdmin")
163        saveAndTest(authInstance)
164    }
165
166    def createBaseAuthorities() {
167
168        def authInstance
169
[294]170        // Authority #2
[296]171        authInstance = new Authority(description:"Business Manager, grants full management access.",
[431]172                                                            authority:"ROLE_Manager")
[149]173        saveAndTest(authInstance)
174
[294]175        // Authority #3
[431]176        authInstance = new Authority(description:"Application User, all application users need this base role \
177                                                                                    to allow login.",
178                                                            authority:"ROLE_AppUser")
[149]179        saveAndTest(authInstance)
[296]180
181        // Authority #4
182        authInstance = new Authority(description:"Task Manager",
[431]183                                                            authority:"ROLE_TaskManager")
[296]184        saveAndTest(authInstance)
185
186        // Authority #5
187        authInstance = new Authority(description:"Task User",
[431]188                                                            authority:"ROLE_TaskUser")
[296]189        saveAndTest(authInstance)
190
191        // Authority #6
192        authInstance = new Authority(description:"Inventory Manager",
[431]193                                                            authority:"ROLE_InventoryManager")
[296]194        saveAndTest(authInstance)
195
196        // Authority #7
197        authInstance = new Authority(description:"Inventory User",
[431]198                                                            authority:"ROLE_InventoryUser")
[296]199        saveAndTest(authInstance)
200
201        // Authority #8
202        authInstance = new Authority(description:"Asset Manager",
[431]203                                                            authority:"ROLE_AssetManager")
[296]204        saveAndTest(authInstance)
205
206        // Authority #9
207        authInstance = new Authority(description:"Asset User",
[431]208                                                            authority:"ROLE_AssetUser")
[296]209        saveAndTest(authInstance)
[431]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)
[149]220    }
221
[506]222    void createBasePersonGroupTypes() {
223
224        //PersonGroupType.
[149]225        def personGroupTypeInstance
[506]226        personGroupTypeInstance = new PersonGroupType(name:"Team")
[149]227        saveAndTest(personGroupTypeInstance)
[506]228        personGroupTypeInstance = new PersonGroupType(name:"Contractor")
[149]229        saveAndTest(personGroupTypeInstance)
[506]230        personGroupTypeInstance = new PersonGroupType(name:"Project Team")
[149]231        saveAndTest(personGroupTypeInstance)
[506]232    }
[149]233
[506]234    void createBasePersonGroups() {
235
[149]236        //PersonGroup
237        def personGroupInstance
[506]238        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
239                                                                                name:"Electrical - General")
[149]240        saveAndTest(personGroupInstance)
[506]241        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
242                                                                                name:"Mechanical - General")
[149]243        saveAndTest(personGroupInstance)
[506]244        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
245                                                                                name:"Production")
[149]246        saveAndTest(personGroupInstance)
[506]247        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(2),
248                                                                                name:"AirCon Contractor")
[149]249        saveAndTest(personGroupInstance)
[506]250        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(3),
251                                                                                name:"gnuMims")
[149]252        saveAndTest(personGroupInstance)
253    }
254
[199]255    def createSystemPerson() {
256        //Person
257        def passClearText = "pass"
[291]258        def passwordEncoded = authService.encodePassword(passClearText)
[199]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,
[399]268                                    password:passwordEncoded)
[199]269        saveAndTest(personInstance)
270    }
271
[149]272    def createAdminPerson() {
273        //Person
274        def passClearText = "pass"
[291]275        def passwordEncoded = authService.encodePassword(passClearText)
[149]276        def personInstance
277
[199]278        //Person #2
[149]279        personInstance = new Person(loginName:"admin",
280                                    firstName:"Admin",
281                                    lastName:"Powers",
[199]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'. ''',
[149]284                                    pass:passClearText,
[399]285                                    password:passwordEncoded)
[149]286        saveAndTest(personInstance)
287        personInstance.addToAuthorities(Authority.get(1))
288    }
289
290    def createBasePersons() {
[199]291    }
292
293    def createDemoPersons() {
[149]294        //Person
295        def passClearText = "pass"
[291]296        def passwordEncoded = authService.encodePassword(passClearText)
[149]297        def personInstance
298
[199]299        //Person #1 is system.
300        //Person #2 is admin.
[149]301
[199]302        //Person #3
[149]303        personInstance = new Person(loginName:"manager",
304                                    firstName:"Demo",
305                                    lastName:"Manager",
306                                    pass:passClearText,
[399]307                                    password:passwordEncoded)
[149]308        saveAndTest(personInstance)
[431]309        personInstance.addToAuthorities(Authority.get(2)) // ROLE_Manager.
310        personInstance.addToAuthorities(Authority.get(3)) // ROLE_AppUser.
[633]311        personInstance.addToPersonGroups(PersonGroup.get(1))
312        personInstance.addToPurchasingGroups(PurchasingGroup.get(1))
313        personInstance.addToPurchasingGroups(PurchasingGroup.get(2))
[149]314
[199]315        //Person #4
[149]316        personInstance = new Person(loginName:"user",
317                                    firstName:"Demo",
318                                    lastName:"User",
319                                    pass:passClearText,
[399]320                                    password:passwordEncoded)
[149]321        saveAndTest(personInstance)
[431]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.
[164]326        personInstance.addToPersonGroups(PersonGroup.get(1))
[149]327
[199]328        //Person #5
[149]329        personInstance = new Person(loginName:"craig",
330                                    firstName:"Craig",
331                                    lastName:"SuperSparky",
332                                    pass:passClearText,
[399]333                                    password:passwordEncoded)
[149]334        saveAndTest(personInstance)
335        personInstance.addToAuthorities(Authority.get(3))
[296]336        personInstance.addToAuthorities(Authority.get(5))
337        personInstance.addToAuthorities(Authority.get(7))
338        personInstance.addToAuthorities(Authority.get(9))
[164]339        personInstance.addToPersonGroups(PersonGroup.get(1))
[149]340
[199]341        //Person #6
[149]342        personInstance = new Person(loginName:"john",
343                                    firstName:"John",
344                                    lastName:"SuperFitter",
345                                    pass:passClearText,
[399]346                                    password:passwordEncoded)
[149]347        saveAndTest(personInstance)
348        personInstance.addToAuthorities(Authority.get(3))
[296]349        personInstance.addToAuthorities(Authority.get(5))
350        personInstance.addToAuthorities(Authority.get(7))
351        personInstance.addToAuthorities(Authority.get(9))
[164]352        personInstance.addToPersonGroups(PersonGroup.get(2))
[149]353
[199]354        //Person #7
[431]355        personInstance = new Person(loginName:"production manager",
[149]356                                    firstName:"Production",
[431]357                                    lastName:"Manager",
[149]358                                    pass:passClearText,
[399]359                                    password:passwordEncoded)
[149]360        saveAndTest(personInstance)
[431]361        personInstance.addToAuthorities(Authority.get(3)) // ROLE_AppUser.
362        personInstance.addToAuthorities(Authority.get(10)) // ROLE_ProductionManager.
[164]363        personInstance.addToPersonGroups(PersonGroup.get(3))
[296]364
[431]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
[296]377        personInstance = new Person(loginName:"testmanager",
378                                    firstName:"Test",
379                                    lastName:"Manager",
380                                    pass:passClearText,
[399]381                                    password:passwordEncoded)
[296]382        saveAndTest(personInstance)
[431]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.
[296]387        personInstance.addToPersonGroups(PersonGroup.get(3))
[149]388    }
389
390/***********************
391START OF UTILITIES
392***********************/
393
[265]394    //These can redefined by the site at deployment time.
[266]395    /// @todo: build an admin view so that only the value (definition) can be changed.
[265]396    def createBaseDefinitions() {
397        appConfigService.set("Department Definition", "A department as recongised by accounting.")
[393]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.")
[265]422    }
423
[149]424    def createDemoSites() {
425        //Site
426        def siteInstance
427
[321]428        siteInstance = new Site(name: "CSM",
[314]429                                                    description: "Creek Side Mill")
[149]430        saveAndTest(siteInstance)
431
[314]432        siteInstance = new Site(name: "Jasper Street Depot",
433                                                    description: "Storage depot on Jasper Street.")
[149]434        saveAndTest(siteInstance)
[162]435
[314]436        siteInstance = new Site(name: "River Press",
437                                                    description: "Printing press site")
[162]438        saveAndTest(siteInstance)
[149]439    }
440
[162]441    def createDemoDepartments() {
442
443        //Department
444        def departmentInstance
445
446        //Department #1
447        departmentInstance = new Department(name: "Print Centre",
[314]448                                                                                description: "Printing Department",
449                                                                                site: Site.get(1))
[162]450        saveAndTest(departmentInstance)
451
452        //Department #2
[321]453        departmentInstance = new Department(name: "Pulp Mill",
454                                                                                description: "Business Department",
[314]455                                                                                site: Site.get(2))
[162]456        saveAndTest(departmentInstance)
457    }
458
[149]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
[397]507    def createBaseSupplierTypes() {
[175]508
509        // SupplierType
510        def supplierTypeInstance
511
512        // SupplierType #1
[420]513        supplierTypeInstance = new SupplierType(name: "Unknown",
514                                                                    description: "Unknown supplier type")
515        saveAndTest(supplierTypeInstance)
516
517        // SupplierType #2
[175]518        supplierTypeInstance = new SupplierType(name: "OEM",
519                                                                    description: "Original equipment supplier")
520        saveAndTest(supplierTypeInstance)
521
[420]522        // SupplierType #3
[175]523        supplierTypeInstance = new SupplierType(name: "Local",
524                                                                    description: "Local supplier")
525        saveAndTest(supplierTypeInstance)
526    }
527
[397]528    def createBaseManufacturerTypes() {
[175]529
530        // ManufacturerType
531        def manufacturerTypeInstance
532
533        // ManufacturerType #1
[420]534        manufacturerTypeInstance = new ManufacturerType(name: "Unknown",
535                                                                        description: "Unknown manufacturer type")
536        saveAndTest(manufacturerTypeInstance)
537
538        // ManufacturerType #2
[175]539        manufacturerTypeInstance = new ManufacturerType(name: "OEM",
540                                                                        description: "Original equipment manufacturer")
541        saveAndTest(manufacturerTypeInstance)
542
[420]543        // ManufacturerType #3
[175]544        manufacturerTypeInstance = new ManufacturerType(name: "Alternate",
545                                                                        description: "Not original equipment manufacturer")
546        saveAndTest(manufacturerTypeInstance)
547
548    }
549
[397]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
[402]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
[441]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)
[597]646
[441]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
[175]658    def createDemoSuppliers() {
659
660        // Supplier
661        def supplierInstance
662
663        // Supplier #1
664        supplierInstance = new Supplier(name: "OEM Distributors",
[420]665                                                                        supplierType: SupplierType.get(2))
[175]666        saveAndTest(supplierInstance)
667
668        // Supplier #2
669        supplierInstance = new Supplier(name: "Mex Holdings",
[420]670                                                                        supplierType: SupplierType.get(3))
[175]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",
[420]681                                                                        manufacturerType: ManufacturerType.get(2))
[175]682        saveAndTest(manufacturerInstance)
683
684        // Manufacturer #2
685        manufacturerInstance = new Manufacturer(name: "Laser Cutting Services Pty",
[420]686                                                                        manufacturerType: ManufacturerType.get(3))
[175]687        saveAndTest(manufacturerInstance)
688    }
689
[431]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
[633]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
[441]719    def createDemoCostCodes() {
720
721        // CostCode
722        def costCodeInstance
723
724        // CostCode #1
[633]725        costCodeInstance = new CostCode(name: "Reelstand.172",
726                                                                    purchasingGroup: PurchasingGroup.get(1))
[441]727        saveAndTest(costCodeInstance)
728
729        // CostCode #2
[633]730        costCodeInstance = new CostCode(name: "Reelstand.CAPEX",
731                                                                    purchasingGroup: PurchasingGroup.get(1))
[441]732        saveAndTest(costCodeInstance)
[633]733
734        // CostCode #2
735        costCodeInstance = new CostCode(name: "PrintUnit.123",
736                                                                    purchasingGroup: PurchasingGroup.get(3))
737        saveAndTest(costCodeInstance)
[441]738    }
739
[149]740/*********************
741START OF TASK
742*********************/
743
[180]744    def createBaseTaskGroups() {
[149]745        //TaskGroup
746        def taskGroupInstance
747
[258]748        //TaskGroup #1
[149]749        taskGroupInstance = new TaskGroup(name:"Engineering Activites",
750                                                                            description:"Engineering daily activities")
751        saveAndTest(taskGroupInstance)
752
[258]753        //TaskGroup #2
[149]754        taskGroupInstance = new TaskGroup(name:"Production Activites",
755                                                                            description:"Production daily activities")
756        saveAndTest(taskGroupInstance)
757
[258]758        //TaskGroup #3
[149]759        taskGroupInstance = new TaskGroup(name:"New Projects",
[576]760                                                                            description:"New site projects")
[149]761        saveAndTest(taskGroupInstance)
[576]762
763        //TaskGroup #4
[587]764        taskGroupInstance = new TaskGroup(name:"Electrical Dayshift",
[576]765                                                                            description:"Group for dayshift electrical tasks")
766        saveAndTest(taskGroupInstance)
767
768        //TaskGroup #5
[587]769        taskGroupInstance = new TaskGroup(name:"Electrical Nightshift",
[576]770                                                                            description:"Group for dayshift mechanical tasks")
771        saveAndTest(taskGroupInstance)
772
773        //TaskGroup #6
[587]774        taskGroupInstance = new TaskGroup(name:"Mechanical Dayshift",
[576]775                                                                            description:"Group for nightshift electrical tasks")
776        saveAndTest(taskGroupInstance)
777
778        //TaskGroup #7
[587]779        taskGroupInstance = new TaskGroup(name:"Mechanical Nightshift",
[576]780                                                                            description:"Group for nightshift mechanical tasks")
781        saveAndTest(taskGroupInstance)
[149]782    }
783
784    def createBaseTaskStatus() {
785
786        //TaskStatus
787        def taskStatusInstance
788
[181]789        taskStatusInstance = new TaskStatus(name:"Not Started") // #1
[149]790        saveAndTest(taskStatusInstance)
791
[181]792        taskStatusInstance = new TaskStatus(name:"In Progress") // #2
[149]793        saveAndTest(taskStatusInstance)
794
[222]795        taskStatusInstance = new TaskStatus(name:"Complete") // #3
[149]796        saveAndTest(taskStatusInstance)
797    }
798
799    def createBaseTaskPriorities() {
800
801        //TaskPriority
802        def taskPriorityInstance
803
[433]804        taskPriorityInstance = new TaskPriority(name:"0 - Immediate") // #1
[149]805        saveAndTest(taskPriorityInstance)
806
[433]807        taskPriorityInstance = new TaskPriority(name:"1 - Very High") // #2
[149]808        saveAndTest(taskPriorityInstance)
809
[433]810        taskPriorityInstance = new TaskPriority(name:"2 - High") // #3
[149]811        saveAndTest(taskPriorityInstance)
812
[433]813        taskPriorityInstance = new TaskPriority(name:"3 - Normal") // #4
[149]814        saveAndTest(taskPriorityInstance)
[433]815
816        taskPriorityInstance = new TaskPriority(name:"4 - Low") // #5
817        saveAndTest(taskPriorityInstance)
818
819        taskPriorityInstance = new TaskPriority(name:"5 - Minor") //  #6
820        saveAndTest(taskPriorityInstance)
[149]821    }
822
[252]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
[149]835    def createBaseTaskTypes() {
836
837        //TaskType
838        def taskTypeInstance
839
[418]840        taskTypeInstance = new TaskType(name:"Immediate Callout") // #1
[149]841        saveAndTest(taskTypeInstance)
842
[418]843        taskTypeInstance = new TaskType(name:"Unscheduled Breakin") // #2
[149]844        saveAndTest(taskTypeInstance)
845
[418]846        taskTypeInstance = new TaskType(name:"Scheduled") // #3
[149]847        saveAndTest(taskTypeInstance)
848
[418]849        taskTypeInstance = new TaskType(name:"Preventative Maintenance") // #4
[149]850        saveAndTest(taskTypeInstance)
851
[523]852        taskTypeInstance = new TaskType(name:"Project") // #5
[149]853        saveAndTest(taskTypeInstance)
854    }
855
[180]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
[251]869        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Groups)").save()  // #10
870        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Persons)").save()  // #11
[418]871        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Flagged for attention)").save()  // #12
872        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Attention flag cleared)").save()  // #13
[180]873    }
874
[149]875    def createDemoTasks() {
876
[180]877        def taskResult
878        def p = [:]
[149]879
880        //Task #1
[180]881        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
882                taskPriority:TaskPriority.get(2),
883                taskType:TaskType.get(1),
884                leadPerson:Person.get(2),
[534]885                primaryAsset:Asset.get(4),
[418]886                description:"Level sensor not working",
[180]887                comment:"Has been noted as problematic, try recalibrating.",
[447]888                targetStartDate: dateUtilService.today,
889                targetCompletionDate: dateUtilService.today]
[149]890
[394]891        taskResult = taskService.save(p)
[180]892
[149]893        //Task #2
[180]894        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
[149]895                taskPriority:TaskPriority.get(2),
[418]896                taskType:TaskType.get(3),
[149]897                leadPerson:Person.get(5),
[534]898                primaryAsset:Asset.get(4),
[149]899                description:"Some follow-up work",
900                comment:"Some help required",
[210]901                targetStartDate: dateUtilService.tomorrow,
[447]902                targetCompletionDate: dateUtilService.tomorrow,
[529]903                parentTask: Task.list()[0]]
[149]904
[394]905        taskResult = taskService.save(p)
[180]906
[149]907        //Task #3
[180]908        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
[149]909                taskPriority:TaskPriority.get(2),
[418]910                taskType:TaskType.get(3),
[149]911                leadPerson:Person.get(5),
[534]912                primaryAsset:Asset.get(4),
[418]913                description:"A Sub Task can be created from the 'Sub Task' tab.",
[149]914                comment:"Some help required",
[210]915                targetStartDate: dateUtilService.yesterday,
[447]916                targetCompletionDate: dateUtilService.yesterday,
[529]917                parentTask: Task.list()[0]]
[149]918
[394]919        taskResult = taskService.save(p)
[180]920
[149]921        //Task #4
[180]922        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
[534]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.",
[447]929                targetStartDate: dateUtilService.today,
930                targetCompletionDate: dateUtilService.oneWeekFromNow,
[529]931                parentTask: Task.list()[0]]
[149]932
[394]933        taskResult = taskService.save(p)
[180]934
[149]935        //Task #5
[180]936        p = [taskGroup:TaskGroup.findByName("Production Activites"),
[534]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",
[447]943                targetStartDate: dateUtilService.today - 6,
944                targetCompletionDate: dateUtilService.today - 6]
[149]945
[394]946        taskResult = taskService.save(p)
[180]947
[149]948        //Task #6
[199]949        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
[534]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.",
[447]956                targetStartDate: dateUtilService.today,
957                targetCompletionDate: dateUtilService.today + 30]
[180]958
[394]959        taskResult = taskService.save(p)
[534]960        taskService.approve(taskResult.taskInstance)
[149]961    }
962
963    def createBaseEntryTypes() {
964
965        //EntryType
966        def entryTypeInstance
967
[190]968        entryTypeInstance = new EntryType(name:"Fault") // #1
[149]969        saveAndTest(entryTypeInstance)
970
[418]971        entryTypeInstance = new EntryType(name:"Cause") // #2
[149]972        saveAndTest(entryTypeInstance)
973
[418]974        entryTypeInstance = new EntryType(name:"Work Done") // #3
[149]975        saveAndTest(entryTypeInstance)
976
[418]977        entryTypeInstance = new EntryType(name:"Production Note") // #4
[149]978        saveAndTest(entryTypeInstance)
[418]979
980        entryTypeInstance = new EntryType(name:"Work Request") // #5
981        saveAndTest(entryTypeInstance)
[149]982    }
983
984    def createDemoEntries() {
985
[190]986        def entryResult
987        def p = [:]
[149]988
989        //Entry #1
[529]990        p = [task: Task.list()[0],
[190]991                entryType: EntryType.get(1),
992                comment: "This level sensor is causing us trouble.",
993                durationMinute: 20]
[149]994
[394]995        entryResult = taskService.saveEntry(p)
[190]996
[149]997        //Entry #2
[529]998        p = [task: Task.list()[0],
[418]999                entryType: EntryType.get(3),
[190]1000                comment: "Cleaned sensor, see how it goes.",
1001                durationMinute: 30]
[149]1002
[394]1003        entryResult = taskService.saveEntry(p)
[190]1004
[149]1005        //Entry #3
[529]1006        p = [task: Task.list()[0],
[418]1007                entryType: EntryType.get(3),
[190]1008                comment: "Checked up on it later and sensor is dropping out intermittently, created sub task to replace sensor.",
1009                durationMinute: 20]
1010
[394]1011        entryResult = taskService.saveEntry(p)
[534]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)
[149]1020    }
1021
[242]1022    def createDemoAssignedGroups() {
1023
[251]1024        def result
1025        def p = [:]
[242]1026
1027        //AssignedGroup #1
[251]1028        p = [personGroup: PersonGroup.get(1),
[529]1029                task: Task.list()[0],
[251]1030                estimatedHour: 2,
1031                estimatedMinute: 30]
1032        result = assignedGroupService.save(p)
[242]1033
1034        //AssignedGroup #2
[251]1035        p = [personGroup: PersonGroup.get(2),
[529]1036                task: Task.list()[0],
[251]1037                estimatedHour: 1,
1038                estimatedMinute: 0]
1039        result = assignedGroupService.save(p)
[242]1040    }
1041
[241]1042    def createDemoAssignedPersons() {
[149]1043
[251]1044        def result
1045        def p = [:]
[149]1046
[241]1047        //AssignedPerson #1
[534]1048        p = [person: Person.get(3), // Demo Manager.
1049                task: Task.list()[5],
[251]1050                estimatedHour: 1,
1051                estimatedMinute: 20]
1052        result = assignedPersonService.save(p)
[149]1053
[241]1054        //AssignedPerson #2
[534]1055        p = [person: Person.get(4), // Demo User.
[529]1056                task: Task.list()[0],
[251]1057                estimatedHour: 3,
1058                estimatedMinute: 30]
1059        result = assignedPersonService.save(p)
[149]1060    }
1061
[534]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
[149]1133    def createDemoTaskRecurringSchedules() {
1134
1135        //TaskRecurringSchedule
1136        def taskRecurringScheduleInstance
1137
1138        //TaskRecurringSchedule #1
[529]1139        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.list()[0],
[149]1140                                                                                                    recurEvery: 1,
[199]1141                                                                                                    recurPeriod: Period.get(2),
[210]1142                                                                                                    nextTargetStartDate: dateUtilService.today,
[149]1143                                                                                                    generateAhead: 1,
[199]1144                                                                                                    taskDuration: 2,
1145                                                                                                    taskDurationPeriod: Period.get(1),
1146                                                                                                    enabled: false)
[149]1147        saveAndTest(taskRecurringScheduleInstance)
1148
1149        //TaskRecurringSchedule #2
[534]1150        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.list()[5],
[149]1151                                                                                                    recurEvery: 1,
1152                                                                                                    recurPeriod: Period.get(1),
[210]1153                                                                                                    nextTargetStartDate: dateUtilService.today,
[149]1154                                                                                                    generateAhead: 1,
1155                                                                                                    taskDuration: 1,
[199]1156                                                                                                    taskDurationPeriod: Period.get(1),
1157                                                                                                    enabled: true)
[149]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
[175]1177    def createDemoInventoryLocations() {
[149]1178
[175]1179        // InventoryLocation
1180        def inventoryLocation
[149]1181
[175]1182        inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(1), name: "A1-2")
1183        saveAndTest(inventoryLocation)
[149]1184
[418]1185        inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(2), name: "C55")
[175]1186        saveAndTest(inventoryLocation)
[149]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
[175]1223    def createBaseInventoryMovementTypes() {
1224
1225        // InventoryMovementType
1226        def inventoryMovementTypeInstance
1227
1228        // InventoryMovementType #1
[177]1229        inventoryMovementTypeInstance = new InventoryMovementType(name: "Used",
1230                                                                                                                        incrementsInventory: false)
[175]1231        saveAndTest(inventoryMovementTypeInstance)
1232
1233        // InventoryMovementType #2
[177]1234        inventoryMovementTypeInstance = new InventoryMovementType(name: "Repaired",
1235                                                                                                                        incrementsInventory: true)
[175]1236        saveAndTest(inventoryMovementTypeInstance)
1237
1238        // InventoryMovementType #3
[177]1239        inventoryMovementTypeInstance = new InventoryMovementType(name: "Purchase Received",
1240                                                                                                                        incrementsInventory: true)
[175]1241        saveAndTest(inventoryMovementTypeInstance)
[177]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)
[175]1252    }
1253
[149]1254    def createDemoInventoryItems() {
1255
1256        //InventoryItem
1257        def inventoryItemInstance
[665]1258        def currency = Currency.getInstance('AUD')
[149]1259
[549]1260        def pictureResource = grailsApplication.mainContext.getResource('images/logo.png')
1261
[149]1262        //InventoryItem #1
1263        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
1264                                                                                    inventoryType: InventoryType.get(1),
1265                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
[175]1266                                                                                    inventoryLocation: InventoryLocation.get(1),
[185]1267                                                                                    name: "Hemp rope",
1268                                                                                    description: "Natural hemp rope.",
[665]1269                                                                                    estimatedUnitPriceAmount: 1.23,
1270                                                                                    estimatedUnitPriceCurrency: currency,
[175]1271                                                                                    unitsInStock: 2,
[149]1272                                                                                    reorderPoint: 0)
1273        saveAndTest(inventoryItemInstance)
[549]1274        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
[149]1275
1276        //InventoryItem #2
1277        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
1278                                                                                    inventoryType: InventoryType.get(1),
1279                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
[175]1280                                                                                    inventoryLocation: InventoryLocation.get(1),
[185]1281                                                                                    name: "Cotton Rope 12mm",
1282                                                                                    description: "A soft natural rope made from cotton.",
[665]1283                                                                                    estimatedUnitPriceAmount: 2.50,
1284                                                                                    estimatedUnitPriceCurrency: currency,
[149]1285                                                                                    alternateItems: InventoryItem.get(1),
[175]1286                                                                                    unitsInStock: 2,
[149]1287                                                                                    reorderPoint: 0)
1288        saveAndTest(inventoryItemInstance)
[549]1289        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
[149]1290
1291        //InventoryItem #3
1292        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1293                                                                                    inventoryType: InventoryType.get(1),
1294                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
[175]1295                                                                                    inventoryLocation: InventoryLocation.get(2),
[149]1296                                                                                    name: "2305-2RS",
1297                                                                                    description: "Bearing 25x62x24mm double row self aligning ball",
[665]1298                                                                                    estimatedUnitPriceAmount: 5,
1299                                                                                    estimatedUnitPriceCurrency: currency,
[175]1300                                                                                    unitsInStock: 3,
[149]1301                                                                                    reorderPoint: 2)
1302        saveAndTest(inventoryItemInstance)
[549]1303        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
[149]1304
1305        //InventoryItem #4
1306        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2),
1307                                                                                    inventoryType: InventoryType.get(1),
1308                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
[175]1309                                                                                    inventoryLocation: InventoryLocation.get(2),
[149]1310                                                                                    name: "L1592-K10",
1311                                                                                    description: "10kW contactor",
[665]1312                                                                                    estimatedUnitPriceAmount: 180,
1313                                                                                    estimatedUnitPriceCurrency: currency,
[175]1314                                                                                    unitsInStock: 4,
[149]1315                                                                                    reorderPoint: 0)
1316        saveAndTest(inventoryItemInstance)
[549]1317        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
[149]1318
1319        //InventoryItem #5
1320        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1321                                                                                    inventoryType: InventoryType.get(1),
1322                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
[175]1323                                                                                    inventoryLocation: InventoryLocation.get(2),
[149]1324                                                                                    name: "6205-ZZ",
1325                                                                                    description: "Bearing 25x52x15mm single row ball shielded",
[665]1326                                                                                    estimatedUnitPriceAmount: 3.45,
1327                                                                                    estimatedUnitPriceCurrency: currency,
[175]1328                                                                                    unitsInStock: 5,
[149]1329                                                                                    reorderPoint: 2)
1330        saveAndTest(inventoryItemInstance)
[549]1331        inventoryItemService.savePicture(inventoryItemInstance, pictureResource)
[149]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
[270]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
[650]1381        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufacturer")
[270]1382        saveAndTest(extendedAttributeTypeInstance)
1383
1384        //ExtendedAttributeType #9
[678]1385        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "ecr")
[270]1386        saveAndTest(extendedAttributeTypeInstance)
[650]1387
1388        //ExtendedAttributeType #10
[678]1389        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Risk Level")
[650]1390        saveAndTest(extendedAttributeTypeInstance)
1391
1392        //ExtendedAttributeType #11
1393        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Safe Work Procedure")
1394        saveAndTest(extendedAttributeTypeInstance)
1395
1396        //ExtendedAttributeType #12
[678]1397        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Regulatory Requirement")
[650]1398        saveAndTest(extendedAttributeTypeInstance)
1399
1400        //ExtendedAttributeType #13
[678]1401        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Maintenance % Completion")
[650]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)
[685]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)
[270]1419    }
1420
[268]1421    def createDemoSections() {
[149]1422
[268]1423        //Section
1424        def sectionInstance
[149]1425
[268]1426        //Section #1
[314]1427        sectionInstance = new Section(name: "Press",
1428                                                                description: "Press Section",
1429                                                                site: Site.get(3),
1430                                                                department: Department.get(1))
[268]1431        saveAndTest(sectionInstance)
[149]1432
[268]1433        //Section #2
[321]1434        sectionInstance = new Section(name: "CSM-Delig",
[314]1435                                                                description: "Pulp Delignification",
1436                                                                site: Site.get(1),
1437                                                                department: Department.get(2))
[268]1438        saveAndTest(sectionInstance)
[149]1439
[268]1440        //Section #3
[321]1441        sectionInstance = new Section(name: "CSM-Aux",
[314]1442                                                                description: "Auxilliary Section",
1443                                                                site: Site.get(1),
1444                                                                department: Department.get(1))
[268]1445        saveAndTest(sectionInstance)
[149]1446    }
1447
[276]1448    def createDemoAssetTree() {
[149]1449
[270]1450        //Asset
1451        def assetInstance
[149]1452
[270]1453        //Asset #1
[276]1454        def assetInstance1 = new Asset(name: "Print Tower 22",
[314]1455                                                                description: "Complete Printing Asset #22",
[650]1456                                                                comment: "Includes everthing directly attached to the tower.",
[314]1457                                                                section: Section.get(1))
[276]1458        saveAndTest(assetInstance1)
[270]1459//        assetInstance.addToMaintenanceActions(MaintenanceAction.get(1))
[149]1460
[270]1461        //Asset #2
[276]1462        def assetInstance2 = new Asset(name: "Print Tower 21",
[314]1463                                                                description: "Complete Printing Asset #21",
1464                                                                section: Section.get(1))
[276]1465        saveAndTest(assetInstance2)
[149]1466
[270]1467        //Asset #3
[276]1468        def assetInstance3 = new Asset(name: "Print Tower 23",
[314]1469                                                                description: "Complete Printing Asset #23",
1470                                                                section: Section.get(1))
[276]1471        saveAndTest(assetInstance3)
[149]1472
[270]1473        //Asset #4
[321]1474        def assetInstance4 = new Asset(name: "C579",
[314]1475                                                                description: "RO #1",
1476                                                                section: Section.get(2))
[276]1477        saveAndTest(assetInstance4)
[149]1478
[270]1479        //AssetSubItem
1480        def assetSubItemInstance
[149]1481
[276]1482        //AssetSubItem #1 Level1
[314]1483        def assetSubItemInstance1 = new AssetSubItem(name: "Print Tower",
1484                                                                                            description: "Common sub asset.")
[276]1485        saveAndTest(assetSubItemInstance1)
[149]1486
[276]1487        // Add assetSubItemInstance1 to some assets.
1488        assetInstance1.addToAssetSubItems(assetSubItemInstance1)
1489        assetInstance2.addToAssetSubItems(assetSubItemInstance1)
1490        assetInstance3.addToAssetSubItems(assetSubItemInstance1)
1491
1492        //AssetSubItem #2 Level1
[321]1493        def assetSubItemInstance2 = new AssetSubItem(name: "C579-44",
1494                                                                                            description: "Tanks and towers")
[276]1495        saveAndTest(assetSubItemInstance2)
1496
1497        // Add assetSubItemInstance2 to some assets.
1498        assetInstance4.addToAssetSubItems(assetSubItemInstance2)
1499
1500        //AssetSubItem #3 Level1
[321]1501        def assetSubItemInstance3 = new AssetSubItem(name: "C579-20",
1502                                                                                            description: "Control Loops")
[276]1503        saveAndTest(assetSubItemInstance3)
1504
1505        // Add assetSubItemInstance3 to some assets.
1506        assetInstance4.addToAssetSubItems(assetSubItemInstance3)
1507
1508        //AssetSubItem #4 Level2
[321]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
[314]1521        assetSubItemInstance = new AssetSubItem(name: "Print Unit",
1522                                                                                    description: "Print Unit - Common Level 2 sub item.",
1523                                                                                    parentItem: AssetSubItem.get(1))
[270]1524        saveAndTest(assetSubItemInstance)
[149]1525
[321]1526        //AssetSubItem #7 Level2
1527        assetSubItemInstance = new AssetSubItem(name: "1925365",
1528                                                                                    description: "Agitator",
1529                                                                                    parentItem: AssetSubItem.get(4))
[270]1530        saveAndTest(assetSubItemInstance)
[149]1531
[321]1532        //AssetSubItem #8 Level2
1533        assetSubItemInstance = new AssetSubItem(name: "1925366",
1534                                                                                    description: "Scraper",
1535                                                                                    parentItem: AssetSubItem.get(4))
[276]1536        saveAndTest(assetSubItemInstance)
1537
[321]1538        //AssetSubItem #9 Level3
[276]1539        assetSubItemInstance = new AssetSubItem(name: "Motor",
[314]1540                                                                                    description: "Motor - Level 3 sub item",
[321]1541                                                                                    parentItem: AssetSubItem.get(6))
[276]1542        saveAndTest(assetSubItemInstance)
1543
[321]1544        //AssetSubItem #10 Level3
[276]1545        assetSubItemInstance = new AssetSubItem(name: "Gearbox",
[314]1546                                                                                    description: "Gearbox - Level 3 sub item, gearbox",
[321]1547                                                                                    parentItem: AssetSubItem.get(6))
[276]1548        saveAndTest(assetSubItemInstance)
1549
[321]1550        //AssetSubItem #11 Level4
[276]1551        assetSubItemInstance = new AssetSubItem(name: "DS Bearing",
[314]1552                                                                                    description: "Drive Side Bearing",
[321]1553                                                                                    parentItem: AssetSubItem.get(9))
[276]1554        saveAndTest(assetSubItemInstance)
1555
[321]1556        //AssetSubItem #12 Level4
[276]1557        assetSubItemInstance = new AssetSubItem(name: "NDS Bearing",
[314]1558                                                                                    description: "Non Drive Side Bearing",
[321]1559                                                                                    parentItem: AssetSubItem.get(9))
[276]1560        saveAndTest(assetSubItemInstance)
[321]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)
[276]1579    } // createDemoAssetTree()
1580
[685]1581    def createDemoAssetSubItemExtendedAttributes() {
[149]1582
[685]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
[270]1614        //AssetExtendedAttribute
1615        def assetExtendedAttributeInstance
1616
1617        //AssetExtendedAttribute #1
[685]1618        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5",
1619                                                                                                            asset: Asset.get(1),
1620                                                                                                            extendedAttributeType: ExtendedAttributeType.get(5)) // Location Description.
[650]1621        saveAndTest(assetExtendedAttributeInstance)
1622
1623        //AssetExtendedAttribute #2
[685]1624        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "3",
1625                                                                                                            asset: Asset.get(1),
1626                                                                                                            extendedAttributeType: ExtendedAttributeType.get(9)) // ecr.
[270]1627        saveAndTest(assetExtendedAttributeInstance)
1628
[650]1629        //AssetExtendedAttribute #3
[685]1630        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "RP-001",
1631                                                                                                            asset: Asset.get(1),
1632                                                                                                            extendedAttributeType: ExtendedAttributeType.get(17)) // Asset Number.
[270]1633        saveAndTest(assetExtendedAttributeInstance)
[650]1634
1635        //AssetExtendedAttribute #4
[685]1636        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "Good",
1637                                                                                                            asset: Asset.get(1),
1638                                                                                                            extendedAttributeType: ExtendedAttributeType.get(16)) // Asset Condition.
[650]1639        saveAndTest(assetExtendedAttributeInstance)
1640
1641        //AssetExtendedAttribute #5
[685]1642        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "TBA",
1643                                                                                                            asset: Asset.get(1),
1644                                                                                                            extendedAttributeType: ExtendedAttributeType.get(13)) // Maintenance % Completion.
[650]1645        saveAndTest(assetExtendedAttributeInstance)
[685]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)
[149]1676    }
1677
[571]1678    /**
[622]1679    * SearchableIndex and mirroring is disabled at startup.
1680    * Use this to start indexing after creating bootstrap data.
[571]1681    * @param indexInNewThread Whether to run the index in a new thread, defaults to true.
1682    */
[622]1683    def startSearchableIndex(Boolean indexInNewThread = true) {
1684        log.info "Start mirroring searchable index."
1685        ConfigurationHolder.config.appSearchable.cascadeOnUpdate = true
[571]1686        searchableService.startMirroring()
1687        if(indexInNewThread) {
1688            Thread.start {
[622]1689                log.info "Rebuilding searchable index, bulkIndex (new thread)."
[571]1690                searchableService.index()
[622]1691                log.info "Rebuilding searchable index, complete."
[571]1692            }
1693        }
1694        else {
[622]1695            log.info "Rebuilding searchable index, bulkIndex."
[571]1696            searchableService.index()
[622]1697            log.info "Rebuilding searchable index, complete."
[571]1698        }
1699    }
[149]1700
[571]1701    /**
[622]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.
[571]1704    */
[622]1705    def stopSearchableIndex() {
1706        log.info "Stop mirroring searchable index."
1707        ConfigurationHolder.config.appSearchable.cascadeOnUpdate = false
[571]1708        searchableService.stopMirroring()
1709    }
1710
1711    /**
1712    * Call this function instead of .save()
1713    */
[149]1714    private boolean saveAndTest(object) {
1715        if(!object.save()) {
1716//             DemoDataSuccessful = false
[199]1717            log.error "'${object}' failed to save!"
1718            log.error object.errors
[149]1719            return false
1720        }
1721        return true
1722    }
[571]1723
[617]1724} // end of class
Note: See TracBrowser for help on using the repository browser.