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

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

Add address feature.

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