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

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

Domain change: Add PurchasingGroup?.
Logic and views to suite.

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