source: trunk/grails-app/conf/BootStrap.groovy @ 136

Last change on this file since 136 was 136, checked in by gav, 15 years ago

Work on TaskRecurringSchedule?.

File size: 36.4 KB
Line 
1import grails.util.GrailsUtil
2
3class BootStrap 
4{
5    //Required to be right here for Acegi plugin.
6    def authenticateService
7    Boolean BootStrapDemoDataSuccessful = true
8
9    def init = { servletContext ->
10
11    println "**** BootStrap GrailsUtil.environment = ${GrailsUtil.environment}"
12   
13        switch (GrailsUtil.environment)
14        {
15            case "development":
16                        bootStrapDemoData()
17                        break
18            case "test":
19                        break
20            case "production":
21                        bootStrapDemoData()
22                        break 
23        }
24   
25    }
26
27    def destroy = {
28    }
29
30    //Insert some demo/startup data.
31    void bootStrapDemoData()
32    {
33        println "BootStrapping demo data..."
34        3.times{println it}
35
36/***********************
37START OF UTILITIES
38***********************/
39
40//Site
41        def siteInstance
42
43        siteInstance = new Site(name: "Creek Mill")
44        BootStrapSaveAndTest(siteInstance)
45
46        siteInstance = new Site(name: "Jasper Street Depot")
47        BootStrapSaveAndTest(siteInstance)
48
49//UnitOfMeasure
50        def unitOfMeasureInstance
51
52        //UnitOfMeasure #1
53        unitOfMeasureInstance = new UnitOfMeasure(name: "each")
54        BootStrapSaveAndTest(unitOfMeasureInstance)
55
56        //UnitOfMeasure #2
57        unitOfMeasureInstance = new UnitOfMeasure(name: "meter(s)")
58        BootStrapSaveAndTest(unitOfMeasureInstance)
59
60        //UnitOfMeasure #3
61        unitOfMeasureInstance = new UnitOfMeasure(name: "box(es)")
62        BootStrapSaveAndTest(unitOfMeasureInstance)
63
64        //UnitOfMeasure #4
65        unitOfMeasureInstance = new UnitOfMeasure(name: "litre(s)")
66        BootStrapSaveAndTest(unitOfMeasureInstance)
67
68        //UnitOfMeasure #5
69        unitOfMeasureInstance = new UnitOfMeasure(name: "kilogram(s)")
70        BootStrapSaveAndTest(unitOfMeasureInstance)
71
72//Period
73        def periodInstance
74
75        //Period #1
76        periodInstance = new Period(period: "Day(s)")
77        BootStrapSaveAndTest(periodInstance)
78
79        //Period #2
80        periodInstance = new Period(period: "Week(s)")
81        BootStrapSaveAndTest(periodInstance)
82
83        //Period #3
84        periodInstance = new Period(period: "Month(s)")
85        BootStrapSaveAndTest(periodInstance)
86
87        //Period #4
88        periodInstance = new Period(period: "Year(s)")
89        BootStrapSaveAndTest(periodInstance)
90
91/*********************
92START OF PERSON
93*********************/
94
95//TypeOfPersonGroup
96        def personGroupTypeInstance
97        personGroupTypeInstance = new PersonGroupType(name:"Department")
98        BootStrapSaveAndTest(personGroupTypeInstance)
99        personGroupTypeInstance = new PersonGroupType(name:"Contractor")
100        BootStrapSaveAndTest(personGroupTypeInstance)
101        personGroupTypeInstance = new PersonGroupType(name:"ProjectTeam")
102        BootStrapSaveAndTest(personGroupTypeInstance)
103   
104//PersonGroup
105        def personGroupInstance
106        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.findByName("Department"),
107                        name:"Electrical")
108        BootStrapSaveAndTest(personGroupInstance)
109        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.findByName("Department"),
110                        name:"Mechanical")
111        BootStrapSaveAndTest(personGroupInstance)
112        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.findByName("Department"),
113                        name:"Production")
114        BootStrapSaveAndTest(personGroupInstance)
115        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(2),
116                        name:"Kewl AirCon Guys")
117        BootStrapSaveAndTest(personGroupInstance)
118        personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(3),
119                        name:"gnuMims")
120        BootStrapSaveAndTest(personGroupInstance)
121
122//Authority
123        def authInstance
124
125        authInstance = new Authority(description:"Application Admin, not required for daily use! Grants full admin access to the application.",
126                                        authority:"ROLE_AppAdmin")
127        BootStrapSaveAndTest(authInstance)
128
129        authInstance = new Authority(description:"Business manager, grants full management access.",
130                                        authority:"ROLE_Manager")
131        BootStrapSaveAndTest(authInstance)
132
133        authInstance = new Authority(description:"Application User, all application users need this base role to allow login.",
134                                        authority:"ROLE_AppUser")
135        BootStrapSaveAndTest(authInstance)
136           
137//Person
138        def passClearText = "pass"
139        def passwordEncoded = authenticateService.encodePassword(passClearText)
140        def personInstance
141
142        //Person #1
143        personInstance = new Person(loginName:"admin",
144                                    firstName:"Admin",
145                                    lastName:"Powers",
146                                    pass:passClearText,
147                                    password:passwordEncoded,
148                                    email:"admin@example.com")
149        BootStrapSaveAndTest(personInstance)
150        personInstance.addToAuthorities(Authority.get(1))
151        personInstance.addToAuthorities(Authority.get(2))
152        personInstance.addToAuthorities(Authority.get(3))
153        personInstance.addToPersonGroups(PersonGroup.findByName("gnuMims"))
154
155        //Person #2
156        personInstance = new Person(loginName:"manager",
157                                    firstName:"Meca",
158                                    lastName:"Manager",
159                                    pass:passClearText,
160                                    password:passwordEncoded,
161                                    email:"manager@example.com")
162        BootStrapSaveAndTest(personInstance)
163        personInstance.addToAuthorities(Authority.get(2))
164        personInstance.addToAuthorities(Authority.get(3))
165        personInstance.addToPersonGroups(PersonGroup.findByName("gnuMims"))
166
167        //Person #3
168        personInstance = new Person(loginName:"user",
169                                    firstName:"Demo",
170                                    lastName:"User",
171                                    pass:passClearText,
172                                    password:passwordEncoded,
173                                    email:"user@example.com")
174        BootStrapSaveAndTest(personInstance)
175        personInstance.addToAuthorities(Authority.get(3))
176        personInstance.addToPersonGroups(PersonGroup.findByName("Electrical"))
177
178        //Person #4
179        personInstance = new Person(loginName:"craig",
180                                    firstName:"Craig",
181                                    lastName:"SuperSparky",
182                                    pass:passClearText,
183                                    password:passwordEncoded,
184                                    email:"user@example.com")
185        BootStrapSaveAndTest(personInstance)
186        personInstance.addToAuthorities(Authority.get(3))
187        personInstance.addToPersonGroups(PersonGroup.findByName("Electrical"))
188
189        //Person #5
190        personInstance = new Person(loginName:"john",
191                                    firstName:"John",
192                                    lastName:"SuperFitter",
193                                    pass:passClearText,
194                                    password:passwordEncoded,
195                                    email:"user@example.com")
196        BootStrapSaveAndTest(personInstance)
197        personInstance.addToAuthorities(Authority.get(3))
198        personInstance.addToPersonGroups(PersonGroup.findByName("Mechanical"))
199
200        //Person #6
201        personInstance = new Person(loginName:"mann",
202                                    firstName:"Production",
203                                    lastName:"Mann",
204                                    pass:passClearText,
205                                    password:passwordEncoded,
206                                    email:"user@example.com")
207        BootStrapSaveAndTest(personInstance)
208        personInstance.addToAuthorities(Authority.get(3))
209        personInstance.addToPersonGroups(PersonGroup.findByName("Production"))
210
211/*********************
212START OF TASK
213*********************/
214
215//TaskGroup
216        def taskGroupInstance
217
218        taskGroupInstance = new TaskGroup(name:"Engineering Activites",
219                                                                            description:"Engineering daily activities")
220        BootStrapSaveAndTest(taskGroupInstance)
221
222        taskGroupInstance = new TaskGroup(name:"Production Activites",
223                                                                            description:"Production daily activities")
224        BootStrapSaveAndTest(taskGroupInstance)
225
226        taskGroupInstance = new TaskGroup(name:"New Projects",
227                                                                            description:" ")
228        BootStrapSaveAndTest(taskGroupInstance)
229
230//TaskStatus
231        def taskStatusInstance
232   
233        taskStatusInstance = new TaskStatus(name:"Not Started")
234        BootStrapSaveAndTest(taskStatusInstance)
235
236        taskStatusInstance = new TaskStatus(name:"In Progress")
237        BootStrapSaveAndTest(taskStatusInstance)
238
239        taskStatusInstance = new TaskStatus(name:"Completed")
240        BootStrapSaveAndTest(taskStatusInstance)
241
242//TaskPriority
243        def taskPriorityInstance
244
245        taskPriorityInstance = new TaskPriority(name:"Normal")
246        BootStrapSaveAndTest(taskPriorityInstance)
247
248        taskPriorityInstance = new TaskPriority(name:"Low")
249        BootStrapSaveAndTest(taskPriorityInstance)
250
251        taskPriorityInstance = new TaskPriority(name:"High")
252        BootStrapSaveAndTest(taskPriorityInstance)
253
254        taskPriorityInstance = new TaskPriority(name:"Immediate")
255        BootStrapSaveAndTest(taskPriorityInstance)
256
257//TaskType
258        def taskTypeInstance
259
260        taskTypeInstance = new TaskType(name:"Unscheduled Breakin")
261        BootStrapSaveAndTest(taskTypeInstance)
262
263        taskTypeInstance = new TaskType(name:"Preventative Maintenance")
264        BootStrapSaveAndTest(taskTypeInstance)
265
266        taskTypeInstance = new TaskType(name:"Project")
267        BootStrapSaveAndTest(taskTypeInstance)
268
269        taskTypeInstance = new TaskType(name:"Turnaround")
270        BootStrapSaveAndTest(taskTypeInstance)
271
272        taskTypeInstance = new TaskType(name:"Production Run")
273        BootStrapSaveAndTest(taskTypeInstance)
274
275//Task
276        def taskInstance
277
278        //Task #1
279        taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"),
280                 taskStatus:TaskStatus.findByName("Not Started"),
281                 taskPriority:TaskPriority.get(2),
282                 taskType:TaskType.get(1),
283                 leadPerson:Person.get(3),
284                 description:"Check specific level sensor",
285                 comment:"Has been noted as problematic, try recalibrating.")
286        BootStrapSaveAndTest(taskInstance)
287
288        //Task #2
289        taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"),
290                taskStatus:TaskStatus.findByName("Not Started"),
291                taskPriority:TaskPriority.get(2),
292                taskType:TaskType.get(1),
293                leadPerson:Person.get(5),
294                description:"Some follow-up work",
295                comment:"Some help required",
296                parentTask: Task.get(1))
297        BootStrapSaveAndTest(taskInstance)
298
299        //Task #3
300        taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"),
301                taskStatus:TaskStatus.findByName("Not Started"),
302                taskPriority:TaskPriority.get(2),
303                taskType:TaskType.get(1),
304                leadPerson:Person.get(5),
305                description:"A Sub Task can be created by setting the Parent Task value",
306                comment:"Some help required",
307                parentTask: Task.get(1))
308        BootStrapSaveAndTest(taskInstance)
309
310        //Task #4
311        taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"),
312                 taskStatus:TaskStatus.findByName("Not Started"),
313                 taskPriority:TaskPriority.get(2),
314                 taskType:TaskType.get(1),
315                 leadPerson:Person.get(4),
316                 description:"Replace sensor at next opportunity.",
317                 comment:"Nothing else has worked.",
318                parentTask: Task.get(1))
319        BootStrapSaveAndTest(taskInstance)
320
321        //Task #5
322        taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"),
323                 taskStatus:TaskStatus.findByName("Not Started"),
324                 taskPriority:TaskPriority.get(2),
325                 taskType:TaskType.get(5),
326                 leadPerson:Person.get(6),
327                 description:"Production Report",
328                 comment:"Production report for specific production run or shift")
329        BootStrapSaveAndTest(taskInstance)
330
331        //Task #6
332        taskInstance = new Task(taskGroup:TaskGroup.findByName("New Projects"),
333                 taskStatus:TaskStatus.findByName("Not Started"),
334                 taskPriority:TaskPriority.get(2),
335                 taskType:TaskType.get(3),
336                 leadPerson:Person.get(1),
337                 description:"Make killer CMMS app",
338                 comment:"Use Grails and get a move on!")
339        BootStrapSaveAndTest(taskInstance)
340
341//EntryType
342        def entryTypeInstance
343
344        entryTypeInstance = new EntryType(name:"Fault")
345        BootStrapSaveAndTest(entryTypeInstance)
346
347        entryTypeInstance = new EntryType(name:"WorkDone")
348        BootStrapSaveAndTest(entryTypeInstance)
349
350        entryTypeInstance = new EntryType(name:"Production Note")
351        BootStrapSaveAndTest(entryTypeInstance)
352
353        entryTypeInstance = new EntryType(name:"Work Request")
354        BootStrapSaveAndTest(entryTypeInstance)
355
356//Entry
357        def entryInstance
358
359        //Entry #1
360        entryInstance = new Entry(enteredBy: Person.get(6),
361                                                    task: Task.get(1),
362                                                    entryType: EntryType.findByName("Fault"),
363                                                    comment: "This level sensor is causing us trouble.",
364                                                    durationMinute: 20)
365        BootStrapSaveAndTest(entryInstance)
366
367        //Entry #2
368        entryInstance = new Entry(enteredBy: Person.get(4),
369                                                    task: Task.get(1),
370                                                    entryType: EntryType.findByName("WorkDone"),
371                                                    comment: "Cleaned sensor, see how it goes.",
372                                                    durationMinute: 30)
373        BootStrapSaveAndTest(entryInstance)
374
375        //Entry #3
376        entryInstance = new Entry(enteredBy: Person.get(4),
377                                                    task: Task.get(1),
378                                                    entryType: EntryType.findByName("WorkDone"),
379                                                    comment: "Checked up on it later and sensor is dropping out intermittently, created subTask to replace sensor.",
380                                                    durationMinute: 20)
381        BootStrapSaveAndTest(entryInstance)
382
383//ModificationType
384        def taskModificationTypeInstance
385        taskModificationTypeInstance = new TaskModificationType(name:"Created").save()
386        taskModificationTypeInstance = new TaskModificationType(name:"Completed").save()
387        taskModificationTypeInstance = new TaskModificationType(name:"Closed").save()
388        taskModificationTypeInstance = new TaskModificationType(name:"Altered").save()
389        taskModificationTypeInstance = new TaskModificationType(name:"TargetDateModified").save()
390        taskModificationTypeInstance = new TaskModificationType(name:"ScheduledDateModified").save()
391        taskModificationTypeInstance = new TaskModificationType(name:"DescriptionModified").save()
392        taskModificationTypeInstance = new TaskModificationType(name:"AssignedToModified").save()
393        taskModificationTypeInstance = new TaskModificationType(name:"NameModified").save()
394   
395//AssignedPerson
396        def assignedPersonInstance
397
398        //AssignedPerson #1
399        assignedPersonInstance = new AssignedPerson(person: Person.get(4),
400                                                                                        task: Task.get(1),
401                                                                                        estimatedHour: 1,
402                                                                                        estimatedMinute: 20)
403        BootStrapSaveAndTest(assignedPersonInstance)
404
405        //AssignedPerson #2
406        assignedPersonInstance = new AssignedPerson(person: Person.get(5),
407                                                                                        task: Task.get(1),
408                                                                                        estimatedHour: 3,
409                                                                                        estimatedMinute: 30)
410        BootStrapSaveAndTest(assignedPersonInstance)
411
412//TaskRecurringSchedule
413        def taskRecurringScheduleInstance
414
415        //TaskRecurringSchedule #1
416        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1),
417                                                                                                    recurEvery: 1,
418                                                                                                    recurPeriod: Period.get(1),
419                                                                                                    startDate: new Date(),
420                                                                                                    generateAhead: 1,
421                                                                                                    generateAheadPeriod: Period.get(1),
422                                                                                                    taskDuration: 1,
423                                                                                                    taskDurationPeriod: Period.get(1))
424        BootStrapSaveAndTest(taskRecurringScheduleInstance)
425
426        //TaskRecurringSchedule #2
427        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(2),
428                                                                                                    recurEvery: 1,
429                                                                                                    recurPeriod: Period.get(1),
430                                                                                                    startDate: new Date(),
431                                                                                                    generateAhead: 1,
432                                                                                                    generateAheadPeriod: Period.get(1),
433                                                                                                    taskDuration: 1,
434                                                                                                    taskDurationPeriod: Period.get(1))
435        BootStrapSaveAndTest(taskRecurringScheduleInstance)
436
437/*************************
438START OF INVENTORY
439**************************/
440
441//InventoryStore
442        def inventoryStoreInstance
443
444        inventoryStoreInstance = new InventoryStore(site: Site.get(1), name: "Store #1")
445        BootStrapSaveAndTest(inventoryStoreInstance)
446
447        inventoryStoreInstance = new InventoryStore(site: Site.get(2), name: "Store #2")
448        BootStrapSaveAndTest(inventoryStoreInstance)
449
450//StoreLocation
451        def storeLocation
452       
453        storeLocation = new StoreLocation(inventoryStore: InventoryStore.get(1), bin: "A1-2")
454        BootStrapSaveAndTest(storeLocation)
455
456        storeLocation = new StoreLocation(inventoryStore: InventoryStore.get(1), bin: "C55")
457        BootStrapSaveAndTest(storeLocation)
458
459//InventoryGroup
460        def inventoryGroupInstance
461
462        //InventoryGroup #1
463        inventoryGroupInstance = new InventoryGroup(name: "Misc")
464        BootStrapSaveAndTest(inventoryGroupInstance)
465
466        //InventoryGroup #2
467        inventoryGroupInstance = new InventoryGroup(name: "Electrical")
468        BootStrapSaveAndTest(inventoryGroupInstance)
469
470        //InventoryGroup #3
471        inventoryGroupInstance = new InventoryGroup(name: "Mechanical")
472        BootStrapSaveAndTest(inventoryGroupInstance)
473
474        //InventoryGroup #4
475        inventoryGroupInstance = new InventoryGroup(name: "Production")
476        BootStrapSaveAndTest(inventoryGroupInstance)
477
478//InventoryType
479        def inventoryTypeInstance
480
481        inventoryTypeInstance = new InventoryType(name: "Consumable")
482        BootStrapSaveAndTest(inventoryTypeInstance)
483
484        inventoryTypeInstance = new InventoryType(name: "Repairable")
485        BootStrapSaveAndTest(inventoryTypeInstance)
486
487//InventoryItem
488        def inventoryItemInstance
489
490        //InventoryItem #1
491        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
492                                                                                    inventoryType: InventoryType.get(1),
493                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
494                                                                                    name: "J-Rope",
495                                                                                    description: "Twine wound J-Rope",
496                                                                                    reorderPoint: 0)
497        BootStrapSaveAndTest(inventoryItemInstance)
498
499        //InventoryItem #2
500        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
501                                                                                    inventoryType: InventoryType.get(1),
502                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
503                                                                                    name: "L-Rope",
504                                                                                    description: "Twine wound L-Rope",
505                                                                                    alternateItems: InventoryItem.get(1),
506                                                                                    reorderPoint: 0)
507        BootStrapSaveAndTest(inventoryItemInstance)
508
509        //InventoryItem #3
510        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
511                                                                                    inventoryType: InventoryType.get(1),
512                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
513                                                                                    name: "2305-2RS",
514                                                                                    description: "Bearing 25x62x24mm double row self aligning ball",
515                                                                                    reorderPoint: 2)
516        BootStrapSaveAndTest(inventoryItemInstance)
517
518        //InventoryItem #4
519        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2),
520                                                                                    inventoryType: InventoryType.get(1),
521                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
522                                                                                    name: "L1592-K10",
523                                                                                    description: "10kW contactor",
524                                                                                    reorderPoint: 0)
525        BootStrapSaveAndTest(inventoryItemInstance)
526
527        //InventoryItem #5
528        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
529                                                                                    inventoryType: InventoryType.get(1),
530                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
531                                                                                    name: "6205-ZZ",
532                                                                                    description: "Bearing 25x52x15mm single row ball shielded",
533                                                                                    reorderPoint: 2)
534        BootStrapSaveAndTest(inventoryItemInstance)
535
536//StoredItem
537        def storedItemInstance
538
539        //StoredItem #1
540        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(1),
541                                                                            storeLocation: StoreLocation.get(1),
542                                                                            quantity: 8)
543        BootStrapSaveAndTest(storedItemInstance)
544
545        //StoredItem #2
546        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(1),
547                                                                            storeLocation: StoreLocation.get(2),
548                                                                            quantity: 4)
549        BootStrapSaveAndTest(storedItemInstance)
550
551        //StoredItem #3
552        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(2),
553                                                                            storeLocation: StoreLocation.get(1),
554                                                                            quantity: 2)
555        BootStrapSaveAndTest(storedItemInstance)
556
557        //StoredItem #4
558        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(3),
559                                                                            storeLocation: StoreLocation.get(1),
560                                                                            quantity: 2)
561        BootStrapSaveAndTest(storedItemInstance)
562
563        //StoredItem #5
564        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(4),
565                                                                            storeLocation: StoreLocation.get(1),
566                                                                            quantity: 30)
567        BootStrapSaveAndTest(storedItemInstance)
568
569/*******************
570START OF ASSET
571*******************/
572
573//LifePlan
574        def lifeplanInstance
575
576        lifeplanInstance = new LifePlan(name: "Initial Plan")
577        BootStrapSaveAndTest(lifeplanInstance)
578
579//MaintenancePolicy
580        def maintenancePolicyInstance
581
582        //MaintenancePolicy #1
583        maintenancePolicyInstance = new MaintenancePolicy(name: "Fixed Time")
584        BootStrapSaveAndTest(maintenancePolicyInstance)
585
586        //MaintenancePolicy #2
587        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Online")
588        BootStrapSaveAndTest(maintenancePolicyInstance)
589
590        //MaintenancePolicy #3
591        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Offline")
592        BootStrapSaveAndTest(maintenancePolicyInstance)
593
594        //MaintenancePolicy #4
595        maintenancePolicyInstance = new MaintenancePolicy(name: "Design Out")
596        BootStrapSaveAndTest(maintenancePolicyInstance)
597
598        //MaintenancePolicy #5
599        maintenancePolicyInstance = new MaintenancePolicy(name: "Operate To Failure")
600        BootStrapSaveAndTest(maintenancePolicyInstance)
601
602//TaskProcedure
603        def taskProcedureInstance
604
605        taskProcedureInstance = new TaskProcedure(name: "Daily check")
606        BootStrapSaveAndTest(taskProcedureInstance)
607        taskProcedureInstance.addToTasks(Task.get(1))
608
609//MaintenanceAction
610        def maintenanceActionInstance
611
612        //MaintenanceAction #1
613        maintenanceActionInstance = new MaintenanceAction(description: "Check all E-stops, active E-stop S1-S12 and ensure machine cannot run",
614                                                                                                        procedureStepNumber: 1,
615                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
616                                                                                                        taskProcedure: TaskProcedure.get(1))
617        BootStrapSaveAndTest(maintenanceActionInstance)
618
619        //MaintenanceAction #2
620        maintenanceActionInstance = new MaintenanceAction(description: "Do more pushups",
621                                                                                                        procedureStepNumber: 2,
622                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
623                                                                                                        taskProcedure: TaskProcedure.get(1))
624        BootStrapSaveAndTest(maintenanceActionInstance)
625
626        //MaintenanceAction #3
627        maintenanceActionInstance = new MaintenanceAction(description: "Ok just one more pushup",
628                                                                                                        procedureStepNumber: 3,
629                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
630                                                                                                        taskProcedure: TaskProcedure.get(1))
631        BootStrapSaveAndTest(maintenanceActionInstance)
632                                                                                                   
633//SystemSection
634    def systemSectionInstance
635
636    //SystemSection #1
637    systemSectionInstance = new SystemSection(name: "Press Section",
638                                                                                   site: Site.get(1))
639    BootStrapSaveAndTest(systemSectionInstance)
640
641    //SystemSection #2
642    systemSectionInstance = new SystemSection(name: "RO System",
643                                                                                   site: Site.get(2))
644    BootStrapSaveAndTest(systemSectionInstance)
645
646    //SystemSection #3
647    systemSectionInstance = new SystemSection(name: "Auxilliray Section",
648                                                                                   site: Site.get(1))
649    BootStrapSaveAndTest(systemSectionInstance)
650
651//AssetType
652        def assetTypeInstance
653
654        //AssetType #1
655        assetTypeInstance = new AssetType(name: "Print Unit")
656        BootStrapSaveAndTest(assetTypeInstance)
657
658        //AssetType #2
659        assetTypeInstance = new AssetType(name: "Reactor Tower")
660        BootStrapSaveAndTest(assetTypeInstance)
661   
662//Assembly
663        def assemblyInstance
664
665        //Assembly #1
666        assemblyInstance = new Assembly(name: "Print Couple",
667                                                                        assetType: AssetType.get(1))
668        BootStrapSaveAndTest(assemblyInstance)
669//        assemblyInstance.addToMaintenanceActions(MaintenanceAction.get(1))
670       
671        //Assembly #2
672        assemblyInstance = new Assembly(name: "Agitator",
673                                                                        assetType: AssetType.get(2))
674        BootStrapSaveAndTest(assemblyInstance)
675
676//SubAssembly
677        def subAssemblyInstance
678
679        //SubAssembly #1
680        subAssemblyInstance = new SubAssembly(name: "Cylinder",
681                                                                                    assembly: Assembly.get(1))
682        BootStrapSaveAndTest(subAssemblyInstance)
683 
684         //SubAssembly #2
685        subAssemblyInstance = new SubAssembly(name: "Gearmotor",
686                                                                                    assembly: Assembly.get(2))
687        BootStrapSaveAndTest(subAssemblyInstance)
688
689//ComponentItem
690        def componentItemInstance
691   
692        //ComponentItem #1
693        componentItemInstance = new ComponentItem(name: "Bearing",
694                                                                                            subAssembly: SubAssembly.get(1))
695        BootStrapSaveAndTest(componentItemInstance)
696
697         //ComponentItem #2
698        componentItemInstance = new ComponentItem(name: "Drive shaft oil seal",
699                                                                                            subAssembly: SubAssembly.get(2))
700        BootStrapSaveAndTest(componentItemInstance)
701
702//Asset
703        def assetInstance
704
705        //Asset #1
706        assetInstance = new Asset(name: "Print Unit 22",
707                                                        assetType: AssetType.get(1),
708                                                        systemSection: SystemSection.get(1))
709        BootStrapSaveAndTest(assetInstance)
710//        assetInstance.addToMaintenanceActions(MaintenanceAction.get(1))
711
712        //Asset #2
713        assetInstance = new Asset(name: "Print Unit 21",
714                                                        assetType: AssetType.get(1),
715                                                        systemSection: SystemSection.get(1))
716        BootStrapSaveAndTest(assetInstance)
717
718        //Asset #3
719        assetInstance = new Asset(name: "Print Unit 23",
720                                                        assetType: AssetType.get(1),
721                                                        systemSection: SystemSection.get(1))
722        BootStrapSaveAndTest(assetInstance)
723
724        //Asset #4
725        assetInstance = new Asset(name: "RO 1",
726                                                        assetType: AssetType.get(2),
727                                                        systemSection: SystemSection.get(2))
728        BootStrapSaveAndTest(assetInstance)
729
730//AssetExtendedAttributeType
731        def assetExtendedAttributeInstanceType
732
733        //AssetExtendedAttributeType #1
734        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Model Number")
735        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
736
737        //AssetExtendedAttributeType #2
738        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Purchase Cost")
739        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
740
741        //AssetExtendedAttributeType #3
742        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Serial Number")
743        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
744
745        //AssetExtendedAttributeType #4
746        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Manufactured Date")
747        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
748
749        //AssetExtendedAttributeType #5
750        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Location Description")
751        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
752
753//AssetExtendedAttribute
754        def assetExtendedAttributeInstance
755
756        //AssetExtendedAttribute #1
757        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "PU Mark 2",
758                                                                                                                    asset: Asset.get(1),
759                                                                                                                    assetExtendedAttributeType: AssetExtendedAttributeType.get(1))
760        BootStrapSaveAndTest(assetExtendedAttributeInstance)
761
762        //AssetExtendedAttribute #2
763        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5",
764                                                                                                                    asset: Asset.get(1),
765                                                                                                                    assetExtendedAttributeType: AssetExtendedAttributeType.get(5))
766        BootStrapSaveAndTest(assetExtendedAttributeInstance)
767
768/*************************
769Finally did it all work.
770**************************/       
771        if(BootStrapDemoDataSuccessful) {
772            println "BootStrapping demo data...successful."
773        }
774        else println "BootStrapping demo data...failed."
775    }
776
777/****************************************
778Call this function instead of .save()
779*****************************************/   
780    void BootStrapSaveAndTest(object) {
781        if(!object.save()) {
782            BootStrapDemoDataSuccessful = false
783            println "'${object}' failed to save!"
784            println object.errors
785
786        }
787    } 
788}
Note: See TracBrowser for help on using the repository browser.