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

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

Add gram(s) unitOfMeasure to base data.

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