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

Last change on this file since 722 was 722, checked in by gav, 13 years ago

Domain change: as per ticket #97 - Drop the entire Manufacturer domain concept.

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