source: branches/features/purchaseOrders/grails-app/services/CreateDataService.groovy @ 893

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

Formatting only, no code change.

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