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

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

Add CostCode and InventoryItemPurchase domain classes with import features.
Includes some fixes to inventory imports, where manufacturer and supplier were crossed.

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