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

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

Apply bug fix for ticket #76.
Rename all instances of Lucene to Searchable.
Improved global directory config.
Add log levels for searchable plugin and compass.

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