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

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

Minor bootstrap change, adjust security to accept all /plugin/ urls.
Tested every dateChooser under the sun only to come back to RichUI, only needs to support "EEE, dd-MMM-yyyy" format and have dropdowns for year and month and it would be perfect.
Placed a dateChooser on Task Create view.

File size: 36.7 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:"Demo",
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(2),
284                 description:"Check specific level sensor",
285                 comment:"Has been noted as problematic, try recalibrating.",
286                targetStartDate:new Date())
287        BootStrapSaveAndTest(taskInstance)
288
289        //Task #2
290        taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"),
291                taskStatus:TaskStatus.findByName("Not Started"),
292                taskPriority:TaskPriority.get(2),
293                taskType:TaskType.get(1),
294                leadPerson:Person.get(5),
295                description:"Some follow-up work",
296                comment:"Some help required",
297                targetStartDate:new Date()+1,
298                parentTask: Task.get(1))
299        BootStrapSaveAndTest(taskInstance)
300
301        //Task #3
302        taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"),
303                taskStatus:TaskStatus.findByName("Not Started"),
304                taskPriority:TaskPriority.get(2),
305                taskType:TaskType.get(1),
306                leadPerson:Person.get(5),
307                description:"A Sub Task can be created by setting the Parent Task value",
308                comment:"Some help required",
309                targetStartDate:new Date()-1,
310                parentTask: Task.get(1))
311        BootStrapSaveAndTest(taskInstance)
312
313        //Task #4
314        taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"),
315                 taskStatus:TaskStatus.findByName("Not Started"),
316                 taskPriority:TaskPriority.get(2),
317                 taskType:TaskType.get(1),
318                 leadPerson:Person.get(4),
319                 description:"Replace sensor at next opportunity.",
320                 comment:"Nothing else has worked.",
321                targetStartDate:new Date()+7,
322                parentTask: Task.get(1))
323        BootStrapSaveAndTest(taskInstance)
324
325        //Task #5
326        taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"),
327                 taskStatus:TaskStatus.findByName("Not Started"),
328                 taskPriority:TaskPriority.get(2),
329                 taskType:TaskType.get(5),
330                 leadPerson:Person.get(6),
331                 description:"Production Report",
332                 comment:"Production report for specific production run or shift",
333                targetStartDate:new Date()-7)
334        BootStrapSaveAndTest(taskInstance)
335
336        //Task #6
337        taskInstance = new Task(taskGroup:TaskGroup.findByName("New Projects"),
338                 taskStatus:TaskStatus.findByName("Not Started"),
339                 taskPriority:TaskPriority.get(2),
340                 taskType:TaskType.get(3),
341                 leadPerson:Person.get(1),
342                 description:"Make killer CMMS app",
343                 comment:"Use Grails and get a move on!",
344                targetStartDate:new Date()-6)
345        BootStrapSaveAndTest(taskInstance)
346
347//EntryType
348        def entryTypeInstance
349
350        entryTypeInstance = new EntryType(name:"Fault")
351        BootStrapSaveAndTest(entryTypeInstance)
352
353        entryTypeInstance = new EntryType(name:"WorkDone")
354        BootStrapSaveAndTest(entryTypeInstance)
355
356        entryTypeInstance = new EntryType(name:"Production Note")
357        BootStrapSaveAndTest(entryTypeInstance)
358
359        entryTypeInstance = new EntryType(name:"Work Request")
360        BootStrapSaveAndTest(entryTypeInstance)
361
362//Entry
363        def entryInstance
364
365        //Entry #1
366        entryInstance = new Entry(enteredBy: Person.get(3),
367                                                    task: Task.get(1),
368                                                    entryType: EntryType.findByName("Fault"),
369                                                    comment: "This level sensor is causing us trouble.",
370                                                    durationMinute: 20)
371        BootStrapSaveAndTest(entryInstance)
372
373        //Entry #2
374        entryInstance = new Entry(enteredBy: Person.get(4),
375                                                    task: Task.get(1),
376                                                    entryType: EntryType.findByName("WorkDone"),
377                                                    comment: "Cleaned sensor, see how it goes.",
378                                                    durationMinute: 30)
379        BootStrapSaveAndTest(entryInstance)
380
381        //Entry #3
382        entryInstance = new Entry(enteredBy: Person.get(4),
383                                                    task: Task.get(1),
384                                                    entryType: EntryType.findByName("WorkDone"),
385                                                    comment: "Checked up on it later and sensor is dropping out intermittently, created subTask to replace sensor.",
386                                                    durationMinute: 20)
387        BootStrapSaveAndTest(entryInstance)
388
389//ModificationType
390        def taskModificationTypeInstance
391        taskModificationTypeInstance = new TaskModificationType(name:"Created").save()
392        taskModificationTypeInstance = new TaskModificationType(name:"Completed").save()
393        taskModificationTypeInstance = new TaskModificationType(name:"Closed").save()
394        taskModificationTypeInstance = new TaskModificationType(name:"Altered").save()
395        taskModificationTypeInstance = new TaskModificationType(name:"TargetDateModified").save()
396        taskModificationTypeInstance = new TaskModificationType(name:"ScheduledDateModified").save()
397        taskModificationTypeInstance = new TaskModificationType(name:"DescriptionModified").save()
398        taskModificationTypeInstance = new TaskModificationType(name:"AssignedToModified").save()
399        taskModificationTypeInstance = new TaskModificationType(name:"NameModified").save()
400   
401//AssignedPerson
402        def assignedPersonInstance
403
404        //AssignedPerson #1
405        assignedPersonInstance = new AssignedPerson(person: Person.get(4),
406                                                                                        task: Task.get(1),
407                                                                                        estimatedHour: 1,
408                                                                                        estimatedMinute: 20)
409        BootStrapSaveAndTest(assignedPersonInstance)
410
411        //AssignedPerson #2
412        assignedPersonInstance = new AssignedPerson(person: Person.get(5),
413                                                                                        task: Task.get(1),
414                                                                                        estimatedHour: 3,
415                                                                                        estimatedMinute: 30)
416        BootStrapSaveAndTest(assignedPersonInstance)
417
418//TaskRecurringSchedule
419        def taskRecurringScheduleInstance
420
421        //TaskRecurringSchedule #1
422        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1),
423                                                                                                    recurEvery: 1,
424                                                                                                    recurPeriod: Period.get(1),
425                                                                                                    startDate: new Date(),
426                                                                                                    generateAhead: 1,
427                                                                                                    generateAheadPeriod: Period.get(1),
428                                                                                                    taskDuration: 1,
429                                                                                                    taskDurationPeriod: Period.get(1))
430        BootStrapSaveAndTest(taskRecurringScheduleInstance)
431
432        //TaskRecurringSchedule #2
433        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(2),
434                                                                                                    recurEvery: 1,
435                                                                                                    recurPeriod: Period.get(1),
436                                                                                                    startDate: new Date(),
437                                                                                                    generateAhead: 1,
438                                                                                                    generateAheadPeriod: Period.get(1),
439                                                                                                    taskDuration: 1,
440                                                                                                    taskDurationPeriod: Period.get(1))
441        BootStrapSaveAndTest(taskRecurringScheduleInstance)
442
443/*************************
444START OF INVENTORY
445**************************/
446
447//InventoryStore
448        def inventoryStoreInstance
449
450        inventoryStoreInstance = new InventoryStore(site: Site.get(1), name: "Store #1")
451        BootStrapSaveAndTest(inventoryStoreInstance)
452
453        inventoryStoreInstance = new InventoryStore(site: Site.get(2), name: "Store #2")
454        BootStrapSaveAndTest(inventoryStoreInstance)
455
456//StoreLocation
457        def storeLocation
458       
459        storeLocation = new StoreLocation(inventoryStore: InventoryStore.get(1), bin: "A1-2")
460        BootStrapSaveAndTest(storeLocation)
461
462        storeLocation = new StoreLocation(inventoryStore: InventoryStore.get(1), bin: "C55")
463        BootStrapSaveAndTest(storeLocation)
464
465//InventoryGroup
466        def inventoryGroupInstance
467
468        //InventoryGroup #1
469        inventoryGroupInstance = new InventoryGroup(name: "Misc")
470        BootStrapSaveAndTest(inventoryGroupInstance)
471
472        //InventoryGroup #2
473        inventoryGroupInstance = new InventoryGroup(name: "Electrical")
474        BootStrapSaveAndTest(inventoryGroupInstance)
475
476        //InventoryGroup #3
477        inventoryGroupInstance = new InventoryGroup(name: "Mechanical")
478        BootStrapSaveAndTest(inventoryGroupInstance)
479
480        //InventoryGroup #4
481        inventoryGroupInstance = new InventoryGroup(name: "Production")
482        BootStrapSaveAndTest(inventoryGroupInstance)
483
484//InventoryType
485        def inventoryTypeInstance
486
487        inventoryTypeInstance = new InventoryType(name: "Consumable")
488        BootStrapSaveAndTest(inventoryTypeInstance)
489
490        inventoryTypeInstance = new InventoryType(name: "Repairable")
491        BootStrapSaveAndTest(inventoryTypeInstance)
492
493//InventoryItem
494        def inventoryItemInstance
495
496        //InventoryItem #1
497        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
498                                                                                    inventoryType: InventoryType.get(1),
499                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
500                                                                                    name: "J-Rope",
501                                                                                    description: "Twine wound J-Rope",
502                                                                                    reorderPoint: 0)
503        BootStrapSaveAndTest(inventoryItemInstance)
504
505        //InventoryItem #2
506        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1),
507                                                                                    inventoryType: InventoryType.get(1),
508                                                                                    unitOfMeasure: UnitOfMeasure.get(2),
509                                                                                    name: "L-Rope",
510                                                                                    description: "Twine wound L-Rope",
511                                                                                    alternateItems: InventoryItem.get(1),
512                                                                                    reorderPoint: 0)
513        BootStrapSaveAndTest(inventoryItemInstance)
514
515        //InventoryItem #3
516        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
517                                                                                    inventoryType: InventoryType.get(1),
518                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
519                                                                                    name: "2305-2RS",
520                                                                                    description: "Bearing 25x62x24mm double row self aligning ball",
521                                                                                    reorderPoint: 2)
522        BootStrapSaveAndTest(inventoryItemInstance)
523
524        //InventoryItem #4
525        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2),
526                                                                                    inventoryType: InventoryType.get(1),
527                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
528                                                                                    name: "L1592-K10",
529                                                                                    description: "10kW contactor",
530                                                                                    reorderPoint: 0)
531        BootStrapSaveAndTest(inventoryItemInstance)
532
533        //InventoryItem #5
534        inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3),
535                                                                                    inventoryType: InventoryType.get(1),
536                                                                                    unitOfMeasure: UnitOfMeasure.get(1),
537                                                                                    name: "6205-ZZ",
538                                                                                    description: "Bearing 25x52x15mm single row ball shielded",
539                                                                                    reorderPoint: 2)
540        BootStrapSaveAndTest(inventoryItemInstance)
541
542//StoredItem
543        def storedItemInstance
544
545        //StoredItem #1
546        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(1),
547                                                                            storeLocation: StoreLocation.get(1),
548                                                                            quantity: 8)
549        BootStrapSaveAndTest(storedItemInstance)
550
551        //StoredItem #2
552        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(1),
553                                                                            storeLocation: StoreLocation.get(2),
554                                                                            quantity: 4)
555        BootStrapSaveAndTest(storedItemInstance)
556
557        //StoredItem #3
558        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(2),
559                                                                            storeLocation: StoreLocation.get(1),
560                                                                            quantity: 2)
561        BootStrapSaveAndTest(storedItemInstance)
562
563        //StoredItem #4
564        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(3),
565                                                                            storeLocation: StoreLocation.get(1),
566                                                                            quantity: 2)
567        BootStrapSaveAndTest(storedItemInstance)
568
569        //StoredItem #5
570        storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(4),
571                                                                            storeLocation: StoreLocation.get(1),
572                                                                            quantity: 30)
573        BootStrapSaveAndTest(storedItemInstance)
574
575/*******************
576START OF ASSET
577*******************/
578
579//LifePlan
580        def lifeplanInstance
581
582        lifeplanInstance = new LifePlan(name: "Initial Plan")
583        BootStrapSaveAndTest(lifeplanInstance)
584
585//MaintenancePolicy
586        def maintenancePolicyInstance
587
588        //MaintenancePolicy #1
589        maintenancePolicyInstance = new MaintenancePolicy(name: "Fixed Time")
590        BootStrapSaveAndTest(maintenancePolicyInstance)
591
592        //MaintenancePolicy #2
593        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Online")
594        BootStrapSaveAndTest(maintenancePolicyInstance)
595
596        //MaintenancePolicy #3
597        maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Offline")
598        BootStrapSaveAndTest(maintenancePolicyInstance)
599
600        //MaintenancePolicy #4
601        maintenancePolicyInstance = new MaintenancePolicy(name: "Design Out")
602        BootStrapSaveAndTest(maintenancePolicyInstance)
603
604        //MaintenancePolicy #5
605        maintenancePolicyInstance = new MaintenancePolicy(name: "Operate To Failure")
606        BootStrapSaveAndTest(maintenancePolicyInstance)
607
608//TaskProcedure
609        def taskProcedureInstance
610
611        taskProcedureInstance = new TaskProcedure(name: "Daily check")
612        BootStrapSaveAndTest(taskProcedureInstance)
613        taskProcedureInstance.addToTasks(Task.get(1))
614
615//MaintenanceAction
616        def maintenanceActionInstance
617
618        //MaintenanceAction #1
619        maintenanceActionInstance = new MaintenanceAction(description: "Check all E-stops, activate E-stops S1-S12 and ensure machine cannot run",
620                                                                                                        procedureStepNumber: 1,
621                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
622                                                                                                        taskProcedure: TaskProcedure.get(1))
623        BootStrapSaveAndTest(maintenanceActionInstance)
624
625        //MaintenanceAction #2
626        maintenanceActionInstance = new MaintenanceAction(description: "Do more pushups",
627                                                                                                        procedureStepNumber: 2,
628                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
629                                                                                                        taskProcedure: TaskProcedure.get(1))
630        BootStrapSaveAndTest(maintenanceActionInstance)
631
632        //MaintenanceAction #3
633        maintenanceActionInstance = new MaintenanceAction(description: "Ok just one more pushup",
634                                                                                                        procedureStepNumber: 3,
635                                                                                                        maintenancePolicy: MaintenancePolicy.get(1),
636                                                                                                        taskProcedure: TaskProcedure.get(1))
637        BootStrapSaveAndTest(maintenanceActionInstance)
638                                                                                                   
639//SystemSection
640    def systemSectionInstance
641
642    //SystemSection #1
643    systemSectionInstance = new SystemSection(name: "Press Section",
644                                                                                   site: Site.get(1))
645    BootStrapSaveAndTest(systemSectionInstance)
646
647    //SystemSection #2
648    systemSectionInstance = new SystemSection(name: "RO System",
649                                                                                   site: Site.get(2))
650    BootStrapSaveAndTest(systemSectionInstance)
651
652    //SystemSection #3
653    systemSectionInstance = new SystemSection(name: "Auxilliray Section",
654                                                                                   site: Site.get(1))
655    BootStrapSaveAndTest(systemSectionInstance)
656
657//AssetType
658        def assetTypeInstance
659
660        //AssetType #1
661        assetTypeInstance = new AssetType(name: "Print Unit")
662        BootStrapSaveAndTest(assetTypeInstance)
663
664        //AssetType #2
665        assetTypeInstance = new AssetType(name: "Reactor Tower")
666        BootStrapSaveAndTest(assetTypeInstance)
667   
668//Assembly
669        def assemblyInstance
670
671        //Assembly #1
672        assemblyInstance = new Assembly(name: "Print Couple",
673                                                                        assetType: AssetType.get(1))
674        BootStrapSaveAndTest(assemblyInstance)
675//        assemblyInstance.addToMaintenanceActions(MaintenanceAction.get(1))
676       
677        //Assembly #2
678        assemblyInstance = new Assembly(name: "Agitator",
679                                                                        assetType: AssetType.get(2))
680        BootStrapSaveAndTest(assemblyInstance)
681
682//SubAssembly
683        def subAssemblyInstance
684
685        //SubAssembly #1
686        subAssemblyInstance = new SubAssembly(name: "Cylinder",
687                                                                                    assembly: Assembly.get(1))
688        BootStrapSaveAndTest(subAssemblyInstance)
689 
690         //SubAssembly #2
691        subAssemblyInstance = new SubAssembly(name: "Gearmotor",
692                                                                                    assembly: Assembly.get(2))
693        BootStrapSaveAndTest(subAssemblyInstance)
694
695//ComponentItem
696        def componentItemInstance
697   
698        //ComponentItem #1
699        componentItemInstance = new ComponentItem(name: "Bearing",
700                                                                                            subAssembly: SubAssembly.get(1))
701        BootStrapSaveAndTest(componentItemInstance)
702
703         //ComponentItem #2
704        componentItemInstance = new ComponentItem(name: "Drive shaft oil seal",
705                                                                                            subAssembly: SubAssembly.get(2))
706        BootStrapSaveAndTest(componentItemInstance)
707
708//Asset
709        def assetInstance
710
711        //Asset #1
712        assetInstance = new Asset(name: "Print Unit 22",
713                                                        assetType: AssetType.get(1),
714                                                        systemSection: SystemSection.get(1))
715        BootStrapSaveAndTest(assetInstance)
716//        assetInstance.addToMaintenanceActions(MaintenanceAction.get(1))
717
718        //Asset #2
719        assetInstance = new Asset(name: "Print Unit 21",
720                                                        assetType: AssetType.get(1),
721                                                        systemSection: SystemSection.get(1))
722        BootStrapSaveAndTest(assetInstance)
723
724        //Asset #3
725        assetInstance = new Asset(name: "Print Unit 23",
726                                                        assetType: AssetType.get(1),
727                                                        systemSection: SystemSection.get(1))
728        BootStrapSaveAndTest(assetInstance)
729
730        //Asset #4
731        assetInstance = new Asset(name: "RO 1",
732                                                        assetType: AssetType.get(2),
733                                                        systemSection: SystemSection.get(2))
734        BootStrapSaveAndTest(assetInstance)
735
736//AssetExtendedAttributeType
737        def assetExtendedAttributeInstanceType
738
739        //AssetExtendedAttributeType #1
740        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Model Number")
741        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
742
743        //AssetExtendedAttributeType #2
744        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Purchase Cost")
745        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
746
747        //AssetExtendedAttributeType #3
748        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Serial Number")
749        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
750
751        //AssetExtendedAttributeType #4
752        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Manufactured Date")
753        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
754
755        //AssetExtendedAttributeType #5
756        assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Location Description")
757        BootStrapSaveAndTest(assetExtendedAttributeInstanceType)
758
759//AssetExtendedAttribute
760        def assetExtendedAttributeInstance
761
762        //AssetExtendedAttribute #1
763        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "PU Mark 2",
764                                                                                                                    asset: Asset.get(1),
765                                                                                                                    assetExtendedAttributeType: AssetExtendedAttributeType.get(1))
766        BootStrapSaveAndTest(assetExtendedAttributeInstance)
767
768        //AssetExtendedAttribute #2
769        assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5",
770                                                                                                                    asset: Asset.get(1),
771                                                                                                                    assetExtendedAttributeType: AssetExtendedAttributeType.get(5))
772        BootStrapSaveAndTest(assetExtendedAttributeInstance)
773
774/*************************
775Finally did it all work.
776**************************/       
777        if(BootStrapDemoDataSuccessful) {
778            println "BootStrapping demo data...successful."
779        }
780        else println "BootStrapping demo data...failed."
781    }
782
783/****************************************
784Call this function instead of .save()
785*****************************************/   
786    void BootStrapSaveAndTest(object) {
787        if(!object.save()) {
788            BootStrapDemoDataSuccessful = false
789            println "'${object}' failed to save!"
790            println object.errors
791
792        }
793    } 
794}
Note: See TracBrowser for help on using the repository browser.