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

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

Remove email and emailShow from Person in preparation for ContactDetails.

File size: 56.8 KB
RevLine 
[149]1/**
2* Provides a data service to create base and demo data.
[180]3* Beware that most, if not all, base data is referenced by "Id" throughout the program.
4* This allows changing the text of the 'name' property to something of the same meaning.
5* But be sure to maintain the correct Id during creation, indicated by #1, #2 etc.
[149]6*/
7class  CreateDataService {
8
9    boolean transactional = false
10
[291]11    def authService
[180]12    def taskService
[210]13    def dateUtilService
[237]14    def appConfigService
[251]15    def assignedGroupService
16    def assignedPersonService
[180]17
[149]18/*******************************************
19Start of Group methods.
20Generally use these methods to create data.
21*******************************************/
22
23    /**
[199]24    * Always call this at startup to ensure that we have admin access
25    * and that the system pseudo person is available.
[149]26    */
[199]27    def ensureSystemAndAdminAccess() {
[149]28        if(!Authority.findByAuthority("ROLE_AppAdmin") ) {
[199]29            log.warn "ROLE_AppAdmin not found, calling createAdminAuthority()."
[149]30            createAdminAuthority()
31        }
[199]32        if(!Person.findByloginName("system") ) {
33            log.warn "LoginName 'system' not found, calling createSystemPerson()."
34            createSystemPerson()
35        }
[149]36        if(!Person.findByloginName("admin") ) {
[199]37            log.warn "LoginName 'admin' not found, calling createAdminPerson()."
[149]38            createAdminPerson()
39        }
40    }
41
42    /**
43    * Create the base data required for the application to function.
44    */
45    def createBaseData() {
[237]46
47        if(appConfigService.exists("baseDataCreated")) {
48            log.error "Base data has already been created, will NOT recreate."
49            return false
50        }
51
[199]52        log.info "Creating base data..."
[237]53
[149]54        // Person and Utils
55        createBaseAuthorities()
56        createBasePersonGroups()
[265]57        createBaseDefinitions()
[149]58        createBaseUnitsOfMeasure()
59        createBasePeriods()
[397]60        createBaseSupplierTypes()
61        createBaseManufacturerTypes()
62        createBaseAddressTypes()
[237]63
[149]64        // Tasks
[180]65        createBaseTaskGroups()
[149]66        createBaseTaskStatus()
67        createBaseTaskPriorities()
[252]68        createBaseTaskBudgetStatus()
[149]69        createBaseTaskTypes()
[180]70        createBaseTaskModificationTypes()
[149]71        createBaseEntryTypes()
[237]72
[149]73        // Inventory
74        createBaseInventoryTypes()
[175]75        createBaseInventoryMovementTypes()
[237]76
[149]77        // Assets
[270]78        createBaseExtenededAttributeTypes()
79        createBaseMaintenancePolicies()
[149]80
[237]81        // Record that data has been created.
82        appConfigService.set("baseDataCreated")
[149]83    }
84
85    /**
86    * Create demo data for some example sites.
87    */
88    def createDemoData() {
[237]89
90        if(!appConfigService.exists("baseDataCreated")) {
91            log.error "Demo data cannot be created until base data has been created."
92            return false
93        }
94
95        if(appConfigService.exists("demoDataCreated")) {
96            log.error "Demo data has already been created, will NOT recreate."
97            return false
98        }
99
100        if(appConfigService.exists("demoDataCreationDisabled")) {
101            log.error "Demo data creation has been disabled, will NOT create."
102            return false
103        }
104
[199]105        log.info "Creating demo data..."
[237]106
[149]107        // Person and Utils
108        createDemoPersons()
109        createDemoSites()
[162]110        createDemoDepartments()
[175]111        createDemoSuppliers()
112        createDemoManufacturers()
[237]113
[149]114        // Tasks
115        createDemoTasks()
116        createDemoEntries()
[242]117        createDemoAssignedGroups()
[241]118        createDemoAssignedPersons()
[149]119        createDemoTaskRecurringSchedules()
[237]120
[149]121        // Inventory
122        createDemoInventoryStores()  /// @todo: Perhaps a 'createQuickStartData' method?
[175]123        createDemoInventoryLocations()
[149]124        createDemoInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method?
125        createDemoInventoryItems()
[237]126
[149]127        // Assets
128        createDemoLifePlan()
129        createDemoTaskProcedure()
130        createDemoMaintenanceActions()
[268]131        createDemoSections()
[276]132        createDemoAssetTree()
[149]133        createDemoAssetExtenedAttributes()
[237]134
135        // Record that data has been created.
136        appConfigService.set("demoDataCreated")
[149]137    }
138
139/******************
140Start of Person
141*******************/
142
143    def createAdminAuthority() {
144        def authInstance
145
[294]146        // Authority #1
[149]147        authInstance = new Authority(description:"Application Admin, not required for daily use! Grants full admin access to the application.",
148                                        authority:"ROLE_AppAdmin")
149        saveAndTest(authInstance)
150    }
151
152    def createBaseAuthorities() {
153
154        def authInstance
155
[294]156        // Authority #2
[296]157        authInstance = new Authority(description:"Business Manager, grants full management access.",
[149]158                                        authority:"ROLE_Manager")
159        saveAndTest(authInstance)
160
[294]161        // Authority #3
[149]162        authInstance = new Authority(description:"Application User, all application users need this base role to allow login.",
163                                        authority:"ROLE_AppUser")
164        saveAndTest(authInstance)
[296]165
166        // Authority #4
167        authInstance = new Authority(description:"Task Manager",
168                                        authority:"ROLE_TaskManager")
169        saveAndTest(authInstance)
170
171        // Authority #5
172        authInstance = new Authority(description:"Task User",
173                                        authority:"ROLE_TaskUser")
174        saveAndTest(authInstance)
175
176        // Authority #6
177        authInstance = new Authority(description:"Inventory Manager",
178                                        authority:"ROLE_InventoryManager")
179        saveAndTest(authInstance)
180
181        // Authority #7
182        authInstance = new Authority(description:"Inventory User",
[298]183                                        authority:"ROLE_InventoryUser")
[296]184        saveAndTest(authInstance)
185
186        // Authority #8
187        authInstance = new Authority(description:"Asset Manager",
188                                        authority:"ROLE_AssetManager")
189        saveAndTest(authInstance)
190
191        // Authority #9
192        authInstance = new Authority(description:"Asset User",
193                                        authority:"ROLE_AssetUser")
194        saveAndTest(authInstance)
[149]195    }
196
197    void createBasePersonGroups() {
198        //TypeOfPersonGroup
199        def personGroupTypeInstance
[164]200            personGroupTypeInstance = new PersonGroupType(name:"Team")
[149]201        saveAndTest(personGroupTypeInstance)
202            personGroupTypeInstance = new PersonGroupType(name:"Contractor")
203        saveAndTest(personGroupTypeInstance)
204            personGroupTypeInstance = new PersonGroupType(name:"ProjectTeam")
205        saveAndTest(personGroupTypeInstance)
206
207        //PersonGroup
208        def personGroupInstance
[164]209            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
[149]210                            name:"Electrical")
211        saveAndTest(personGroupInstance)
[164]212            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
[149]213                            name:"Mechanical")
214        saveAndTest(personGroupInstance)
[164]215            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1),
[149]216                            name:"Production")
217        saveAndTest(personGroupInstance)
218            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(2),
219                            name:"Kewl AirCon Guys")
220        saveAndTest(personGroupInstance)
221            personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(3),
222                            name:"gnuMims")
223        saveAndTest(personGroupInstance)
224    }
225
[199]226    def createSystemPerson() {
227        //Person
228        def passClearText = "pass"
[291]229        def passwordEncoded = authService.encodePassword(passClearText)
[199]230        def personInstance
231
232        //Person #1
233        personInstance = new Person(loginName:"system",
234                                    firstName:"gnuMims",
235                                    lastName:"System",
236                                    description:'''This is a pseudo person that the application uses to insert data. DO NOT
237                                                        assign login authorities or change the details of this person.''',
238                                    pass:passClearText,
[399]239                                    password:passwordEncoded)
[199]240        saveAndTest(personInstance)
241    }
242
[149]243    def createAdminPerson() {
244        //Person
245        def passClearText = "pass"
[291]246        def passwordEncoded = authService.encodePassword(passClearText)
[149]247        def personInstance
248
[199]249        //Person #2
[149]250        personInstance = new Person(loginName:"admin",
251                                    firstName:"Admin",
252                                    lastName:"Powers",
[199]253                                    description:'''Every time the application starts it ensures that the 'admin' login name is available.
254                                                        DO update the password and other details but keep the login name as 'admin'. ''',
[149]255                                    pass:passClearText,
[399]256                                    password:passwordEncoded)
[149]257        saveAndTest(personInstance)
258        personInstance.addToAuthorities(Authority.get(1))
259    }
260
261    def createBasePersons() {
[199]262    }
263
264    def createDemoPersons() {
[149]265        //Person
266        def passClearText = "pass"
[291]267        def passwordEncoded = authService.encodePassword(passClearText)
[149]268        def personInstance
269
[199]270        //Person #1 is system.
271        //Person #2 is admin.
[149]272
[199]273        //Person #3
[149]274        personInstance = new Person(loginName:"manager",
275                                    firstName:"Demo",
276                                    lastName:"Manager",
277                                    pass:passClearText,
[399]278                                    password:passwordEncoded)
[149]279        saveAndTest(personInstance)
280        personInstance.addToAuthorities(Authority.get(2))
281        personInstance.addToAuthorities(Authority.get(3))
[164]282        personInstance.addToPersonGroups(PersonGroup.get(5))
[149]283
[199]284        //Person #4
[149]285        personInstance = new Person(loginName:"user",
286                                    firstName:"Demo",
287                                    lastName:"User",
288                                    pass:passClearText,
[399]289                                    password:passwordEncoded)
[149]290        saveAndTest(personInstance)
291        personInstance.addToAuthorities(Authority.get(3))
[296]292        personInstance.addToAuthorities(Authority.get(5))
293        personInstance.addToAuthorities(Authority.get(7))
294        personInstance.addToAuthorities(Authority.get(9))
[164]295        personInstance.addToPersonGroups(PersonGroup.get(1))
[149]296
[199]297        //Person #5
[149]298        personInstance = new Person(loginName:"craig",
299                                    firstName:"Craig",
300                                    lastName:"SuperSparky",
301                                    pass:passClearText,
[399]302                                    password:passwordEncoded)
[149]303        saveAndTest(personInstance)
304        personInstance.addToAuthorities(Authority.get(3))
[296]305        personInstance.addToAuthorities(Authority.get(5))
306        personInstance.addToAuthorities(Authority.get(7))
307        personInstance.addToAuthorities(Authority.get(9))
[164]308        personInstance.addToPersonGroups(PersonGroup.get(1))
[149]309
[199]310        //Person #6
[149]311        personInstance = new Person(loginName:"john",
312                                    firstName:"John",
313                                    lastName:"SuperFitter",
314                                    pass:passClearText,
[399]315                                    password:passwordEncoded)
[149]316        saveAndTest(personInstance)
317        personInstance.addToAuthorities(Authority.get(3))
[296]318        personInstance.addToAuthorities(Authority.get(5))
319        personInstance.addToAuthorities(Authority.get(7))
320        personInstance.addToAuthorities(Authority.get(9))
[164]321        personInstance.addToPersonGroups(PersonGroup.get(2))
[149]322
[199]323        //Person #7
[149]324        personInstance = new Person(loginName:"mann",
325                                    firstName:"Production",
326                                    lastName:"Mann",
327                                    pass:passClearText,
[399]328                                    password:passwordEncoded)
[149]329        saveAndTest(personInstance)
330        personInstance.addToAuthorities(Authority.get(3))
[296]331        personInstance.addToAuthorities(Authority.get(5))
[164]332        personInstance.addToPersonGroups(PersonGroup.get(3))
[296]333
334        //Person #7
335        personInstance = new Person(loginName:"testmanager",
336                                    firstName:"Test",
337                                    lastName:"Manager",
338                                    pass:passClearText,
[399]339                                    password:passwordEncoded)
[296]340        saveAndTest(personInstance)
341        personInstance.addToAuthorities(Authority.get(3))
342        personInstance.addToAuthorities(Authority.get(4))
343        personInstance.addToAuthorities(Authority.get(6))
344        personInstance.addToAuthorities(Authority.get(8))
345        personInstance.addToPersonGroups(PersonGroup.get(3))
[149]346    }
347
348/***********************
349START OF UTILITIES
350***********************/
351
[265]352    //These can redefined by the site at deployment time.
[266]353    /// @todo: build an admin view so that only the value (definition) can be changed.
[265]354    def createBaseDefinitions() {
355        appConfigService.set("Department Definition", "A department as recongised by accounting.")
[393]356        appConfigService.set("Site Definition", "The plant, work or production site.")
357        appConfigService.set("Section Definition", "A logical grouping of assets, which may be an area, system or process \
358                                            as determined by design.")
359        appConfigService.set("Asset Definition",
360                                            "The complete asset as it is known on the site. \
361                                            Often purchased as a whole with the primary purpose of returning value by performing a function. \
362                                            An asset is made up of 1 or more sub assets and performs a complete function as specified by the designer.")
363        appConfigService.set("Asset Sub Item 1 Name",
364                                            "Sub Asset")
365        appConfigService.set("Asset Sub Item 1 Definition",
366                                            "A machine that performs part of a complete asset's function and often has a model number.")
367        appConfigService.set("Asset Sub Item 2 Name",
368                                            "Functional Assembly")
369        appConfigService.set("Asset Sub Item 2 Definition",
370                                            "Functional Assemblies are taken from the designer's functional list for the sub asset and are made up of sub \
371                                            assemblies that together perform that function.")
372        appConfigService.set("Asset Sub Item 3 Name",
373                                            "Sub Assembly Group")
374        appConfigService.set("Asset Sub Item 3 Definition",
375                                            "Group or type of part.")
376        appConfigService.set("Asset Sub Item 4 Name",
377                                            "Component Item")
378        appConfigService.set("Asset Sub Item 4 Definition",
379                                            "The smallest part that would be analysed for failure.")
[265]380    }
381
[149]382    def createDemoSites() {
383        //Site
384        def siteInstance
385
[321]386        siteInstance = new Site(name: "CSM",
[314]387                                                    description: "Creek Side Mill")
[149]388        saveAndTest(siteInstance)
389
[314]390        siteInstance = new Site(name: "Jasper Street Depot",
391                                                    description: "Storage depot on Jasper Street.")
[149]392        saveAndTest(siteInstance)
[162]393
[314]394        siteInstance = new Site(name: "River Press",
395                                                    description: "Printing press site")
[162]396        saveAndTest(siteInstance)
[149]397    }
398
[162]399    def createDemoDepartments() {
400
401        //Department
402        def departmentInstance
403
404        //Department #1
405        departmentInstance = new Department(name: "Print Centre",
[314]406                                                                                description: "Printing Department",
407                                                                                site: Site.get(1))
[162]408        saveAndTest(departmentInstance)
409
410        //Department #2
[321]411        departmentInstance = new Department(name: "Pulp Mill",
412                                                                                description: "Business Department",
[314]413                                                                                site: Site.get(2))
[162]414        saveAndTest(departmentInstance)
415    }
416
[149]417    def createBaseUnitsOfMeasure() {
418
419        //UnitOfMeasure
420        def unitOfMeasureInstance
421
422        //UnitOfMeasure #1
423        unitOfMeasureInstance = new UnitOfMeasure(name: "each")
424        saveAndTest(unitOfMeasureInstance)
425
426        //UnitOfMeasure #2
427        unitOfMeasureInstance = new UnitOfMeasure(name: "meter(s)")
428        saveAndTest(unitOfMeasureInstance)
429
430        //UnitOfMeasure #3
431        unitOfMeasureInstance = new UnitOfMeasure(name: "box(es)")
432        saveAndTest(unitOfMeasureInstance)
433
434        //UnitOfMeasure #4
435        unitOfMeasureInstance = new UnitOfMeasure(name: "litre(s)")
436        saveAndTest(unitOfMeasureInstance)
437
438        //UnitOfMeasure #5
439        unitOfMeasureInstance = new UnitOfMeasure(name: "kilogram(s)")
440        saveAndTest(unitOfMeasureInstance)
441    }
442
443    def createBasePeriods() {
444
445        //Period
446        def periodInstance
447
448        //Period #1
449        periodInstance = new Period(period: "Day(s)")
450        saveAndTest(periodInstance)
451
452        //Period #2
453        periodInstance = new Period(period: "Week(s)")
454        saveAndTest(periodInstance)
455
456        //Period #3
457        periodInstance = new Period(period: "Month(s)")
458        saveAndTest(periodInstance)
459
460        //Period #4
461        periodInstance = new Period(period: "Year(s)")
462        saveAndTest(periodInstance)
463    }
464
[397]465    def createBaseSupplierTypes() {
[175]466
467        // SupplierType
468        def supplierTypeInstance
469
470        // SupplierType #1
471        supplierTypeInstance = new SupplierType(name: "OEM",
472                                                                    description: "Original equipment supplier")
473        saveAndTest(supplierTypeInstance)
474
475        // SupplierType #2
476        supplierTypeInstance = new SupplierType(name: "Local",
477                                                                    description: "Local supplier")
478        saveAndTest(supplierTypeInstance)
479    }
480
[397]481    def createBaseManufacturerTypes() {
[175]482
483        // ManufacturerType
484        def manufacturerTypeInstance
485
486        // ManufacturerType #1
487        manufacturerTypeInstance = new ManufacturerType(name: "OEM",
488                                                                        description: "Original equipment manufacturer")
489        saveAndTest(manufacturerTypeInstance)
490
491        // ManufacturerType #2
492        manufacturerTypeInstance = new ManufacturerType(name: "Alternate",
493                                                                        description: "Not original equipment manufacturer")
494        saveAndTest(manufacturerTypeInstance)
495
496    }
497
[397]498    def createBaseAddressTypes() {
499
500        // AddressType
501        def addressTypeInstance
502
503        // AddressType #1
504        addressTypeInstance = new AddressType(name: "Postal",
505                                                                                description: "A postal address.")
506        saveAndTest(addressTypeInstance)
507
508        // AddressType #2
509        addressTypeInstance = new AddressType(name: "Physical",
510                                                                                description: "A physical address.")
511        saveAndTest(addressTypeInstance)
512
513        // AddressType #3
514        addressTypeInstance = new AddressType(name: "Postal & Physical",
515                                                                                description: "An address that is both the postal and physical address.")
516        saveAndTest(addressTypeInstance)
517
518        // AddressType #4
519        addressTypeInstance = new AddressType(name: "Invoice",
520                                                                                description: "An address to send invoices to.")
521        saveAndTest(addressTypeInstance)
522
523        // AddressType #5
524        addressTypeInstance = new AddressType(name: "Delivery",
525                                                                                description: "An address to send deliveries to.")
526        saveAndTest(addressTypeInstance)
527    }
528
[175]529    def createDemoSuppliers() {
530
531        // Supplier
532        def supplierInstance
533
534        // Supplier #1
535        supplierInstance = new Supplier(name: "OEM Distributors",
536                                                                        supplierType: SupplierType.get(1))
537        saveAndTest(supplierInstance)
538
539        // Supplier #2
540        supplierInstance = new Supplier(name: "Mex Holdings",
541                                                                        supplierType: SupplierType.get(2))
542        saveAndTest(supplierInstance)
543    }
544
545    def createDemoManufacturers() {
546
547        // Manufacturer
548        def manufacturerInstance
549
550        // Manufacturer #1
551        manufacturerInstance = new Manufacturer(name: "OEM Manufacturer",
552                                                                        manufacturerType: ManufacturerType.get(1))
553        saveAndTest(manufacturerInstance)
554
555        // Manufacturer #2
556        manufacturerInstance = new Manufacturer(name: "Laser Cutting Services Pty",
557                                                                        manufacturerType: ManufacturerType.get(2))
558        saveAndTest(manufacturerInstance)
559    }
560
[149]561/*********************
562START OF TASK
563*********************/
564
[180]565    def createBaseTaskGroups() {
[149]566        //TaskGroup
567        def taskGroupInstance
568
[258]569        //TaskGroup #1
[149]570        taskGroupInstance = new TaskGroup(name:"Engineering Activites",
571                                                                            description:"Engineering daily activities")
572        saveAndTest(taskGroupInstance)
573
[258]574        //TaskGroup #2
[149]575        taskGroupInstance = new TaskGroup(name:"Production Activites",
576                                                                            description:"Production daily activities")
577        saveAndTest(taskGroupInstance)
578
[258]579        //TaskGroup #3
[149]580        taskGroupInstance = new TaskGroup(name:"New Projects",
581                                                                            description:" ")
582        saveAndTest(taskGroupInstance)
583    }
584
585    def createBaseTaskStatus() {
586
587        //TaskStatus
588        def taskStatusInstance
589
[181]590        taskStatusInstance = new TaskStatus(name:"Not Started") // #1
[149]591        saveAndTest(taskStatusInstance)
592
[181]593        taskStatusInstance = new TaskStatus(name:"In Progress") // #2
[149]594        saveAndTest(taskStatusInstance)
595
[222]596        taskStatusInstance = new TaskStatus(name:"Complete") // #3
[149]597        saveAndTest(taskStatusInstance)
598    }
599
600    def createBaseTaskPriorities() {
601
602        //TaskPriority
603        def taskPriorityInstance
604
[199]605        taskPriorityInstance = new TaskPriority(name:"Normal") // #1
[149]606        saveAndTest(taskPriorityInstance)
607
[199]608        taskPriorityInstance = new TaskPriority(name:"Low") // #2
[149]609        saveAndTest(taskPriorityInstance)
610
[199]611        taskPriorityInstance = new TaskPriority(name:"High") // #3
[149]612        saveAndTest(taskPriorityInstance)
613
[199]614        taskPriorityInstance = new TaskPriority(name:"Immediate") // #4
[149]615        saveAndTest(taskPriorityInstance)
616    }
617
[252]618    def createBaseTaskBudgetStatus() {
619
620        //TaskBudgetStatus
621        def taskBudgetStatusInstance
622
623        taskBudgetStatusInstance = new TaskBudgetStatus(name:"Unplanned") // #1
624        saveAndTest(taskBudgetStatusInstance)
625
626        taskBudgetStatusInstance = new TaskBudgetStatus(name:"Planned") // #2
627        saveAndTest(taskBudgetStatusInstance)
628    }
629
[149]630    def createBaseTaskTypes() {
631
632        //TaskType
633        def taskTypeInstance
634
[199]635        taskTypeInstance = new TaskType(name:"Unscheduled Breakin") // #1
[149]636        saveAndTest(taskTypeInstance)
637
[199]638        taskTypeInstance = new TaskType(name:"Preventative Maintenance") // #2
[149]639        saveAndTest(taskTypeInstance)
640
[199]641        taskTypeInstance = new TaskType(name:"Project") // #3
[149]642        saveAndTest(taskTypeInstance)
643
[199]644        taskTypeInstance = new TaskType(name:"Turnaround") // #4
[149]645        saveAndTest(taskTypeInstance)
646
[199]647        taskTypeInstance = new TaskType(name:"Production Run") // #5
[149]648        saveAndTest(taskTypeInstance)
649    }
650
[180]651    def createBaseTaskModificationTypes() {
652
653        //ModificationType
654        def taskModificationTypeInstance
655        taskModificationTypeInstance = new TaskModificationType(name:"Created").save()  // #1
656        taskModificationTypeInstance = new TaskModificationType(name:"Started").save()  // #2
657        taskModificationTypeInstance = new TaskModificationType(name:"Modified").save()  // #3
658        taskModificationTypeInstance = new TaskModificationType(name:"Completed").save()  // #4
659        taskModificationTypeInstance = new TaskModificationType(name:"Reopened").save()  // #5
660        taskModificationTypeInstance = new TaskModificationType(name:"Trashed").save()  // #6
661        taskModificationTypeInstance = new TaskModificationType(name:"Restored").save()  // #7
662        taskModificationTypeInstance = new TaskModificationType(name:"Approved").save()  // #8
663        taskModificationTypeInstance = new TaskModificationType(name:"Renege approval").save()  // #9
[251]664        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Groups)").save()  // #10
665        taskModificationTypeInstance = new TaskModificationType(name:"Modified (Assigned Persons)").save()  // #11
[180]666    }
667
[149]668    def createDemoTasks() {
669
[180]670        def taskResult
671        def p = [:]
[149]672
673        //Task #1
[180]674        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
675                taskPriority:TaskPriority.get(2),
676                taskType:TaskType.get(1),
677                leadPerson:Person.get(2),
678                description:"Check specific level sensor",
679                comment:"Has been noted as problematic, try recalibrating.",
[210]680                targetStartDate: dateUtilService.today]
[149]681
[394]682        taskResult = taskService.save(p)
[180]683
[149]684        //Task #2
[180]685        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
[149]686                taskPriority:TaskPriority.get(2),
687                taskType:TaskType.get(1),
688                leadPerson:Person.get(5),
689                description:"Some follow-up work",
690                comment:"Some help required",
[210]691                targetStartDate: dateUtilService.tomorrow,
[180]692                parentTask: Task.get(1)]
[149]693
[394]694        taskResult = taskService.save(p)
[180]695
[149]696        //Task #3
[180]697        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
[149]698                taskPriority:TaskPriority.get(2),
699                taskType:TaskType.get(1),
700                leadPerson:Person.get(5),
[314]701                description:"A Sub Task can be created from the Sub Task's tab.",
[149]702                comment:"Some help required",
[210]703                targetStartDate: dateUtilService.yesterday,
[180]704                parentTask: Task.get(1)]
[149]705
[394]706        taskResult = taskService.save(p)
[180]707
[149]708        //Task #4
[180]709        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
[149]710                 taskPriority:TaskPriority.get(2),
711                 taskType:TaskType.get(1),
712                 leadPerson:Person.get(4),
713                 description:"Replace sensor at next opportunity.",
714                 comment:"Nothing else has worked.",
[210]715                targetStartDate: dateUtilService.oneWeekFromNow,
[180]716                parentTask: Task.get(1)]
[149]717
[394]718        taskResult = taskService.save(p)
[180]719
[149]720        //Task #5
[180]721        p = [taskGroup:TaskGroup.findByName("Production Activites"),
[149]722                 taskPriority:TaskPriority.get(2),
723                 taskType:TaskType.get(5),
724                 leadPerson:Person.get(6),
725                 description:"Production Report",
726                 comment:"Production report for specific production run or shift",
[210]727                targetStartDate: dateUtilService.today - 6]
[149]728
[394]729        taskResult = taskService.save(p)
[180]730
[149]731        //Task #6
[199]732        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
733                 taskPriority:TaskPriority.get(1),
734                 taskType:TaskType.get(2),
735                 leadPerson:Person.get(4),
736                 description:"This is a recurring task",
737                 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.",
[210]738                targetStartDate: dateUtilService.today]
[180]739
[394]740        taskResult = taskService.save(p)
[149]741    }
742
743    def createBaseEntryTypes() {
744
745        //EntryType
746        def entryTypeInstance
747
[190]748        entryTypeInstance = new EntryType(name:"Fault") // #1
[149]749        saveAndTest(entryTypeInstance)
750
[190]751        entryTypeInstance = new EntryType(name:"Work Done") // #2
[149]752        saveAndTest(entryTypeInstance)
753
[190]754        entryTypeInstance = new EntryType(name:"Production Note") // #3
[149]755        saveAndTest(entryTypeInstance)
756
[190]757        entryTypeInstance = new EntryType(name:"Work Request") // #4
[149]758        saveAndTest(entryTypeInstance)
759    }
760
761    def createDemoEntries() {
762
[190]763        def entryResult
764        def p = [:]
[149]765
766        //Entry #1
[190]767        p = [task: Task.get(1),
768                entryType: EntryType.get(1),
769                comment: "This level sensor is causing us trouble.",
770                durationMinute: 20]
[149]771
[394]772        entryResult = taskService.saveEntry(p)
[190]773
[149]774        //Entry #2
[190]775        p = [task: Task.get(1),
776                entryType: EntryType.get(2),
777                comment: "Cleaned sensor, see how it goes.",
778                durationMinute: 30]
[149]779
[394]780        entryResult = taskService.saveEntry(p)
[190]781
[149]782        //Entry #3
[190]783        p = [task: Task.get(1),
784                entryType: EntryType.get(2),
785                comment: "Checked up on it later and sensor is dropping out intermittently, created sub task to replace sensor.",
786                durationMinute: 20]
787
[394]788        entryResult = taskService.saveEntry(p)
[149]789    }
790
[242]791    def createDemoAssignedGroups() {
792
[251]793        def result
794        def p = [:]
[242]795
796        //AssignedGroup #1
[251]797        p = [personGroup: PersonGroup.get(1),
798                task: Task.get(1),
799                estimatedHour: 2,
800                estimatedMinute: 30]
801        result = assignedGroupService.save(p)
[242]802
803        //AssignedGroup #2
[251]804        p = [personGroup: PersonGroup.get(2),
805                task: Task.get(1),
806                estimatedHour: 1,
807                estimatedMinute: 0]
808        result = assignedGroupService.save(p)
[242]809    }
810
[241]811    def createDemoAssignedPersons() {
[149]812
[251]813        def result
814        def p = [:]
[149]815
[241]816        //AssignedPerson #1
[251]817        p = [person: Person.get(4),
818                task: Task.get(1),
819                estimatedHour: 1,
820                estimatedMinute: 20]
821        result = assignedPersonService.save(p)
[149]822
[241]823        //AssignedPerson #2
[251]824        p = [person: Person.get(5),
825                task: Task.get(1),
826                estimatedHour: 3,
827                estimatedMinute: 30]
828        result = assignedPersonService.save(p)
[149]829    }
830
831    def createDemoTaskRecurringSchedules() {
832
833        //TaskRecurringSchedule
834        def taskRecurringScheduleInstance
835
836        //TaskRecurringSchedule #1
837        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1),
838                                                                                                    recurEvery: 1,
[199]839                                                                                                    recurPeriod: Period.get(2),
[210]840                                                                                                    nextTargetStartDate: dateUtilService.today,
[149]841                                                                                                    generateAhead: 1,
[199]842                                                                                                    taskDuration: 2,
843                                                                                                    taskDurationPeriod: Period.get(1),
844                                                                                                    enabled: false)
[149]845        saveAndTest(taskRecurringScheduleInstance)
846
847        //TaskRecurringSchedule #2
[199]848        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(6),
[149]849                                                                                                    recurEvery: 1,
850                                                                                                    recurPeriod: Period.get(1),
[210]851                                                                                                    nextTargetStartDate: dateUtilService.today,
[149]852                                                                                                    generateAhead: 1,
853                                                                                                    taskDuration: 1,
[199]854                                                                                                    taskDurationPeriod: Period.get(1),
855                                                                                                    enabled: true)
[149]856        saveAndTest(taskRecurringScheduleInstance)
857    }
858
859/*************************
860START OF INVENTORY
861**************************/
862
863    def createDemoInventoryStores() {
864
865        //InventoryStore
866        def inventoryStoreInstance
867
868        inventoryStoreInstance = new InventoryStore(site: Site.get(1), name: "Store #1")
869        saveAndTest(inventoryStoreInstance)
870
871        inventoryStoreInstance = new InventoryStore(site: Site.get(2), name: "Store #2")
872        saveAndTest(inventoryStoreInstance)
873    }
874
[175]875    def createDemoInventoryLocations() {
[149]876
[175]877        // InventoryLocation
878        def inventoryLocation
[149]879
[175]880        inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(1), name: "A1-2")
881        saveAndTest(inventoryLocation)
[149]882
[175]883        inventoryLocation = new InventoryLocation(inventoryStore: InventoryStore.get(1), name: "C55")
884        saveAndTest(inventoryLocation)
[149]885    }
886
887    def createDemoInventoryGroups() {
888
889        //InventoryGroup
890        def inventoryGroupInstance
891
892        //InventoryGroup #1
893        inventoryGroupInstance = new InventoryGroup(name: "Misc")
894        saveAndTest(inventoryGroupInstance)
895
896        //InventoryGroup #2
897        inventoryGroupInstance = new InventoryGroup(name: "Electrical")
898        saveAndTest(inventoryGroupInstance)
899
900        //InventoryGroup #3
901        inventoryGroupInstance = new InventoryGroup(name: "Mechanical")
902        saveAndTest(inventoryGroupInstance)
903
904        //InventoryGroup #4
905        inventoryGroupInstance = new InventoryGroup(name: "Production")
906        saveAndTest(inventoryGroupInstance)
907    }
908
909    def createBaseInventoryTypes() {
910
911        //InventoryType
912        def inventoryTypeInstance
913
914        inventoryTypeInstance = new InventoryType(name: "Consumable")
915        saveAndTest(inventoryTypeInstance)
916
917        inventoryTypeInstance = new InventoryType(name: "Repairable")
918        saveAndTest(inventoryTypeInstance)
919    }
920
[175]921    def createBaseInventoryMovementTypes() {
922
923        // InventoryMovementType
924        def inventoryMovementTypeInstance
925
926        // InventoryMovementType #1
[177]927        inventoryMovementTypeInstance = new InventoryMovementType(name: "Used",
928                                                                                                                        incrementsInventory: false)
[175]929        saveAndTest(inventoryMovementTypeInstance)
930
931        // InventoryMovementType #2
[177]932        inventoryMovementTypeInstance = new InventoryMovementType(name: "Repaired",
933                                                                                                                        incrementsInventory: true)
[175]934        saveAndTest(inventoryMovementTypeInstance)
935
936        // InventoryMovementType #3
[177]937        inventoryMovementTypeInstance = new InventoryMovementType(name: "Purchase Received",
938                                                                                                                        incrementsInventory: true)
[175]939        saveAndTest(inventoryMovementTypeInstance)
[177]940
941        // InventoryMovementType #4
942        inventoryMovementTypeInstance = new InventoryMovementType(name: "Correction Increase",
943                                                                                                                        incrementsInventory: true)
944        saveAndTest(inventoryMovementTypeInstance)
945
946        // InventoryMovementType #5
947        inventoryMovementTypeInstance = new InventoryMovementType(name: "Correction Decrease",
948                                                                                                                        incrementsInventory: false)
949        saveAndTest(inventoryMovementTypeInstance)
[175]950    }
951
[149]952    def createDemoInventoryItems() {
953
954        //InventoryItem
955        def inventoryItemInstance
956
957        //InventoryItem #1
958        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
959                                                                                    inventoryType: InventoryType.get(1),
960                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
[175]961                                                                                    inventoryLocation: InventoryLocation.get(1),
[185]962                                                                                    name: "Hemp rope",
963                                                                                    description: "Natural hemp rope.",
[175]964                                                                                    unitsInStock: 2,
[149]965                                                                                    reorderPoint: 0)
966        saveAndTest(inventoryItemInstance)
967
968        //InventoryItem #2
969        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
970                                                                                    inventoryType: InventoryType.get(1),
971                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
[175]972                                                                                    inventoryLocation: InventoryLocation.get(1),
[185]973                                                                                    name: "Cotton Rope 12mm",
974                                                                                    description: "A soft natural rope made from cotton.",
[149]975                                                                                    alternateItems: InventoryItem.get(1),
[175]976                                                                                    unitsInStock: 2,
[149]977                                                                                    reorderPoint: 0)
978        saveAndTest(inventoryItemInstance)
979
980        //InventoryItem #3
981        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
982                                                                                    inventoryType: InventoryType.get(1),
983                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
[175]984                                                                                    inventoryLocation: InventoryLocation.get(2),
[149]985                                                                                    name: "2305-2RS",
986                                                                                    description: "Bearing 25x62x24mm double row self aligning ball",
[175]987                                                                                    unitsInStock: 3,
[149]988                                                                                    reorderPoint: 2)
989        saveAndTest(inventoryItemInstance)
990
991        //InventoryItem #4
992        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2),
993                                                                                    inventoryType: InventoryType.get(1),
994                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
[175]995                                                                                    inventoryLocation: InventoryLocation.get(2),
[149]996                                                                                    name: "L1592-K10",
997                                                                                    description: "10kW contactor",
[175]998                                                                                    unitsInStock: 4,
[149]999                                                                                    reorderPoint: 0)
1000        saveAndTest(inventoryItemInstance)
1001
1002        //InventoryItem #5
1003        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
1004                                                                                    inventoryType: InventoryType.get(1),
1005                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
[175]1006                                                                                    inventoryLocation: InventoryLocation.get(2),
[149]1007                                                                                    name: "6205-ZZ",
1008                                                                                    description: "Bearing 25x52x15mm single row ball shielded",
[175]1009                                                                                    unitsInStock: 5,
[149]1010                                                                                    reorderPoint: 2)
1011        saveAndTest(inventoryItemInstance)
1012    }
1013
1014/*******************
1015START OF ASSET
1016*******************/
1017
1018    def createDemoLifePlan() {
1019
1020        //LifePlan
1021        def lifeplanInstance
1022
1023        lifeplanInstance = new LifePlan(name: "Initial Plan")
1024        saveAndTest(lifeplanInstance)
1025    }
1026
[270]1027    def createBaseExtenededAttributeTypes() {
1028
1029        //ExtendedAttributeType
1030        def extendedAttributeTypeInstance
1031
1032        //ExtendedAttributeType #1
1033        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Model Number")
1034        saveAndTest(extendedAttributeTypeInstance)
1035
1036        //ExtendedAttributeType #2
1037        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Purchase Cost")
1038        saveAndTest(extendedAttributeTypeInstance)
1039
1040        //ExtendedAttributeType #3
1041        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Serial Number")
1042        saveAndTest(extendedAttributeTypeInstance)
1043
1044        //ExtendedAttributeType #4
1045        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufactured Date")
1046        saveAndTest(extendedAttributeTypeInstance)
1047
1048        //ExtendedAttributeType #5
1049        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Location Description")
1050        saveAndTest(extendedAttributeTypeInstance)
1051
1052        //ExtendedAttributeType #6
1053        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Cost Centre")
1054        saveAndTest(extendedAttributeTypeInstance)
1055
1056        //ExtendedAttributeType #7
1057        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Cost Code")
1058        saveAndTest(extendedAttributeTypeInstance)
1059
1060        //ExtendedAttributeType #8
1061        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Manufacturer's Number")
1062        saveAndTest(extendedAttributeTypeInstance)
1063
1064        //ExtendedAttributeType #9
1065        extendedAttributeTypeInstance = new ExtendedAttributeType(name: "Inventory Number")
1066        saveAndTest(extendedAttributeTypeInstance)
1067    }
1068
[149]1069    def createBaseMaintenancePolicies() {
1070
1071        //MaintenancePolicy
1072        def maintenancePolicyInstance
1073
1074        //MaintenancePolicy #1
1075        maintenancePolicyInstance = new MaintenancePolicy(name: "Fixed Time")
1076        saveAndTest(maintenancePolicyInstance)
1077
1078        //MaintenancePolicy #2
1079        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Online")
1080        saveAndTest(maintenancePolicyInstance)
1081
1082        //MaintenancePolicy #3
1083        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Offline")
1084        saveAndTest(maintenancePolicyInstance)
1085
1086        //MaintenancePolicy #4
1087        maintenancePolicyInstance = new MaintenancePolicy(name: "Design Out")
1088        saveAndTest(maintenancePolicyInstance)
1089
1090        //MaintenancePolicy #5
1091        maintenancePolicyInstance = new MaintenancePolicy(name: "Operate To Failure")
1092        saveAndTest(maintenancePolicyInstance)
[275]1093
1094        //MaintenancePolicy #6
1095        maintenancePolicyInstance = new MaintenancePolicy(name: "Regulatory Requirement")
1096        saveAndTest(maintenancePolicyInstance)
1097
1098        //MaintenancePolicy #7
1099        maintenancePolicyInstance = new MaintenancePolicy(name: "Hidden Function Test")
1100        saveAndTest(maintenancePolicyInstance)
[149]1101    }
1102
1103    def createDemoTaskProcedure() {
1104
1105        //TaskProcedure
1106        def taskProcedureInstance
1107
1108        taskProcedureInstance = new TaskProcedure(name: "Daily check")
1109        saveAndTest(taskProcedureInstance)
1110        taskProcedureInstance.addToTasks(Task.get(1))
1111    }
1112
1113    def createDemoMaintenanceActions() {
1114
1115        //MaintenanceAction
1116        def maintenanceActionInstance
1117
1118        //MaintenanceAction #1
1119        maintenanceActionInstance = new MaintenanceAction(description: "Check all E-stops, activate E-stops S1-S12 and ensure machine cannot run",
1120                                                                                                        procedureStepNumber: 1,
1121                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1122                                                                                                        taskProcedure: TaskProcedure.get(1))
1123        saveAndTest(maintenanceActionInstance)
1124
1125        //MaintenanceAction #2
1126        maintenanceActionInstance = new MaintenanceAction(description: "Do more pushups",
1127                                                                                                        procedureStepNumber: 2,
1128                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1129                                                                                                        taskProcedure: TaskProcedure.get(1))
1130        saveAndTest(maintenanceActionInstance)
1131
1132        //MaintenanceAction #3
1133        maintenanceActionInstance = new MaintenanceAction(description: "Ok just one more pushup",
1134                                                                                                        procedureStepNumber: 3,
1135                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
1136                                                                                                        taskProcedure: TaskProcedure.get(1))
1137        saveAndTest(maintenanceActionInstance)
1138    }
1139
[268]1140    def createDemoSections() {
[149]1141
[268]1142        //Section
1143        def sectionInstance
[149]1144
[268]1145        //Section #1
[314]1146        sectionInstance = new Section(name: "Press",
1147                                                                description: "Press Section",
1148                                                                site: Site.get(3),
1149                                                                department: Department.get(1))
[268]1150        saveAndTest(sectionInstance)
[149]1151
[268]1152        //Section #2
[321]1153        sectionInstance = new Section(name: "CSM-Delig",
[314]1154                                                                description: "Pulp Delignification",
1155                                                                site: Site.get(1),
1156                                                                department: Department.get(2))
[268]1157        saveAndTest(sectionInstance)
[149]1158
[268]1159        //Section #3
[321]1160        sectionInstance = new Section(name: "CSM-Aux",
[314]1161                                                                description: "Auxilliary Section",
1162                                                                site: Site.get(1),
1163                                                                department: Department.get(1))
[268]1164        saveAndTest(sectionInstance)
[149]1165    }
1166
[276]1167    def createDemoAssetTree() {
[149]1168
[270]1169        //Asset
1170        def assetInstance
[149]1171
[270]1172        //Asset #1
[276]1173        def assetInstance1 = new Asset(name: "Print Tower 22",
[314]1174                                                                description: "Complete Printing Asset #22",
1175                                                                section: Section.get(1))
[276]1176        saveAndTest(assetInstance1)
[270]1177//        assetInstance.addToMaintenanceActions(MaintenanceAction.get(1))
[149]1178
[270]1179        //Asset #2
[276]1180        def assetInstance2 = new Asset(name: "Print Tower 21",
[314]1181                                                                description: "Complete Printing Asset #21",
1182                                                                section: Section.get(1))
[276]1183        saveAndTest(assetInstance2)
[149]1184
[270]1185        //Asset #3
[276]1186        def assetInstance3 = new Asset(name: "Print Tower 23",
[314]1187                                                                description: "Complete Printing Asset #23",
1188                                                                section: Section.get(1))
[276]1189        saveAndTest(assetInstance3)
[149]1190
[270]1191        //Asset #4
[321]1192        def assetInstance4 = new Asset(name: "C579",
[314]1193                                                                description: "RO #1",
1194                                                                section: Section.get(2))
[276]1195        saveAndTest(assetInstance4)
[149]1196
[270]1197        //AssetSubItem
1198        def assetSubItemInstance
[149]1199
[276]1200        //AssetSubItem #1 Level1
[314]1201        def assetSubItemInstance1 = new AssetSubItem(name: "Print Tower",
1202                                                                                            description: "Common sub asset.")
[276]1203        saveAndTest(assetSubItemInstance1)
[149]1204
[276]1205        // Add assetSubItemInstance1 to some assets.
1206        assetInstance1.addToAssetSubItems(assetSubItemInstance1)
1207        assetInstance2.addToAssetSubItems(assetSubItemInstance1)
1208        assetInstance3.addToAssetSubItems(assetSubItemInstance1)
1209
1210        //AssetSubItem #2 Level1
[321]1211        def assetSubItemInstance2 = new AssetSubItem(name: "C579-44",
1212                                                                                            description: "Tanks and towers")
[276]1213        saveAndTest(assetSubItemInstance2)
1214
1215        // Add assetSubItemInstance2 to some assets.
1216        assetInstance4.addToAssetSubItems(assetSubItemInstance2)
1217
1218        //AssetSubItem #3 Level1
[321]1219        def assetSubItemInstance3 = new AssetSubItem(name: "C579-20",
1220                                                                                            description: "Control Loops")
[276]1221        saveAndTest(assetSubItemInstance3)
1222
1223        // Add assetSubItemInstance3 to some assets.
1224        assetInstance4.addToAssetSubItems(assetSubItemInstance3)
1225
1226        //AssetSubItem #4 Level2
[321]1227        assetSubItemInstance = new AssetSubItem(name: "C579-TK-0022",
1228                                                                                            description: "Blow Tank",
1229                                                                                            parentItem: AssetSubItem.get(2))
1230        saveAndTest(assetSubItemInstance)
1231
1232        //AssetSubItem #5 Level2
1233        assetSubItemInstance = new AssetSubItem(name: "C579-TK-0023",
1234                                                                                            description: "Reactor Tower",
1235                                                                                            parentItem: AssetSubItem.get(2))
1236        saveAndTest(assetSubItemInstance)
1237
1238        //AssetSubItem #6 Level2
[314]1239        assetSubItemInstance = new AssetSubItem(name: "Print Unit",
1240                                                                                    description: "Print Unit - Common Level 2 sub item.",
1241                                                                                    parentItem: AssetSubItem.get(1))
[270]1242        saveAndTest(assetSubItemInstance)
[149]1243
[321]1244        //AssetSubItem #7 Level2
1245        assetSubItemInstance = new AssetSubItem(name: "1925365",
1246                                                                                    description: "Agitator",
1247                                                                                    parentItem: AssetSubItem.get(4))
[270]1248        saveAndTest(assetSubItemInstance)
[149]1249
[321]1250        //AssetSubItem #8 Level2
1251        assetSubItemInstance = new AssetSubItem(name: "1925366",
1252                                                                                    description: "Scraper",
1253                                                                                    parentItem: AssetSubItem.get(4))
[276]1254        saveAndTest(assetSubItemInstance)
1255
[321]1256        //AssetSubItem #9 Level3
[276]1257        assetSubItemInstance = new AssetSubItem(name: "Motor",
[314]1258                                                                                    description: "Motor - Level 3 sub item",
[321]1259                                                                                    parentItem: AssetSubItem.get(6))
[276]1260        saveAndTest(assetSubItemInstance)
1261
[321]1262        //AssetSubItem #10 Level3
[276]1263        assetSubItemInstance = new AssetSubItem(name: "Gearbox",
[314]1264                                                                                    description: "Gearbox - Level 3 sub item, gearbox",
[321]1265                                                                                    parentItem: AssetSubItem.get(6))
[276]1266        saveAndTest(assetSubItemInstance)
1267
[321]1268        //AssetSubItem #11 Level4
[276]1269        assetSubItemInstance = new AssetSubItem(name: "DS Bearing",
[314]1270                                                                                    description: "Drive Side Bearing",
[321]1271                                                                                    parentItem: AssetSubItem.get(9))
[276]1272        saveAndTest(assetSubItemInstance)
1273
[321]1274        //AssetSubItem #12 Level4
[276]1275        assetSubItemInstance = new AssetSubItem(name: "NDS Bearing",
[314]1276                                                                                    description: "Non Drive Side Bearing",
[321]1277                                                                                    parentItem: AssetSubItem.get(9))
[276]1278        saveAndTest(assetSubItemInstance)
[321]1279
1280        //AssetSubItem #13 Level2
1281        assetSubItemInstance = new AssetSubItem(name: "C579-F-0001",
1282                                                                                    description: "Weak Caustic Flow",
1283                                                                                    parentItem: AssetSubItem.get(3))
1284        saveAndTest(assetSubItemInstance)
1285
1286        //AssetSubItem #14 Level3
1287        assetSubItemInstance = new AssetSubItem(name: "C579-FT-0002",
1288                                                                                    description: "Weak Caustic Flow Transmitter",
1289                                                                                    parentItem: AssetSubItem.get(13))
1290        saveAndTest(assetSubItemInstance)
1291
1292        //AssetSubItem #15 Level3
1293        assetSubItemInstance = new AssetSubItem(name: "C579-PT-0003",
1294                                                                                    description: "Weak Caustic Pressure Transmitter",
1295                                                                                    parentItem: AssetSubItem.get(13))
1296        saveAndTest(assetSubItemInstance)
[276]1297    } // createDemoAssetTree()
1298
[149]1299    def createDemoAssetExtenedAttributes() {
1300
[270]1301        //AssetExtendedAttribute
1302        def assetExtendedAttributeInstance
1303
1304        //AssetExtendedAttribute #1
1305        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "PU Mark 2",
1306                                                                                                                    asset: Asset.get(1),
1307                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(1))
1308        saveAndTest(assetExtendedAttributeInstance)
1309
1310        //AssetExtendedAttribute #2
1311        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5",
1312                                                                                                                    asset: Asset.get(1),
1313                                                                                                                    extendedAttributeType: ExtendedAttributeType.get(5))
1314        saveAndTest(assetExtendedAttributeInstance)
[149]1315    }
1316
1317
1318/****************************************
1319Call this function instead of .save()
1320*****************************************/
1321    private boolean saveAndTest(object) {
1322        if(!object.save()) {
1323//             DemoDataSuccessful = false
[199]1324            log.error "'${object}' failed to save!"
1325            log.error object.errors
[149]1326            return false
1327        }
1328        return true
1329    }
1330}
Note: See TracBrowser for help on using the repository browser.