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

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

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

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