source: branches/features/taskProcedureRework/grails-app/services/CreateDataService.groovy @ 763

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

Re-enable createDemoMaintenanceActions() and add list action to MaintenanceActionController?.

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