1 | /** |
---|
2 | * Provides a data service to create base and demo data. |
---|
3 | */ |
---|
4 | class CreateDataService { |
---|
5 | |
---|
6 | def authenticateService |
---|
7 | boolean transactional = false |
---|
8 | |
---|
9 | /******************************************* |
---|
10 | Start of Group methods. |
---|
11 | Generally use these methods to create data. |
---|
12 | *******************************************/ |
---|
13 | |
---|
14 | /** |
---|
15 | * Always call this at startup to ensure admin access. |
---|
16 | */ |
---|
17 | def ensureAdminAccess() { |
---|
18 | if(!Authority.findByAuthority("ROLE_AppAdmin") ) { |
---|
19 | println "ROLE_AppAdmin not found, calling createAdminAuthority()." |
---|
20 | createAdminAuthority() |
---|
21 | } |
---|
22 | if(!Person.findByloginName("admin") ) { |
---|
23 | println "LoginName 'admin' not found, calling createAdminPerson()." |
---|
24 | createAdminPerson() |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | /** |
---|
29 | * Create the base data required for the application to function. |
---|
30 | */ |
---|
31 | def createBaseData() { |
---|
32 | println "Creating base data..." |
---|
33 | // Person and Utils |
---|
34 | createBaseAuthorities() |
---|
35 | createBasePersonGroups() |
---|
36 | createBasePersons() |
---|
37 | createBaseUnitsOfMeasure() |
---|
38 | createBasePeriods() |
---|
39 | // Tasks |
---|
40 | createBaseTaskStatus() |
---|
41 | createBaseTaskPriorities() |
---|
42 | createBaseTaskTypes() |
---|
43 | createBaseEntryTypes() |
---|
44 | createBaseModificationTypes() |
---|
45 | // Inventory |
---|
46 | createBaseInventoryTypes() |
---|
47 | createBaseMaintenancePolicies() |
---|
48 | // Assets |
---|
49 | createBaseAssetExtenededAttributeTypes() |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Create demo data for some example sites. |
---|
55 | */ |
---|
56 | def createDemoData() { |
---|
57 | println "Creating demo data..." |
---|
58 | // Person and Utils |
---|
59 | createDemoPersons() |
---|
60 | createDemoSites() |
---|
61 | createDemoDepartments() |
---|
62 | // Tasks |
---|
63 | createDemoTaskGroups() /// @todo: Perhaps this should be BaseData? |
---|
64 | createDemoTasks() |
---|
65 | createDemoEntries() |
---|
66 | createDemoAssignedPersons() |
---|
67 | createDemoTaskRecurringSchedules() |
---|
68 | // Inventory |
---|
69 | createDemoInventoryStores() /// @todo: Perhaps a 'createQuickStartData' method? |
---|
70 | createDemoStoreLocations() |
---|
71 | createDemoInventoryGroups() /// @todo: Perhaps a 'createQuickStartData' method? |
---|
72 | createDemoInventoryItems() |
---|
73 | createDemoStoredItems() |
---|
74 | // Assets |
---|
75 | createDemoLifePlan() |
---|
76 | createDemoTaskProcedure() |
---|
77 | createDemoMaintenanceActions() |
---|
78 | createDemoSystemSections() |
---|
79 | createDemoAssetTypes() |
---|
80 | createDemoAssemblies() |
---|
81 | createDemoSubAssemblies() |
---|
82 | createDemoComponentItems() |
---|
83 | createDemoAssets() |
---|
84 | createDemoAssetExtenedAttributes() |
---|
85 | } |
---|
86 | |
---|
87 | /****************** |
---|
88 | Start of Person |
---|
89 | *******************/ |
---|
90 | |
---|
91 | def createAdminAuthority() { |
---|
92 | def authInstance |
---|
93 | |
---|
94 | authInstance = new Authority(description:"Application Admin, not required for daily use! Grants full admin access to the application.", |
---|
95 | authority:"ROLE_AppAdmin") |
---|
96 | saveAndTest(authInstance) |
---|
97 | } |
---|
98 | |
---|
99 | def createBaseAuthorities() { |
---|
100 | |
---|
101 | def authInstance |
---|
102 | |
---|
103 | authInstance = new Authority(description:"Business manager, grants full management access.", |
---|
104 | authority:"ROLE_Manager") |
---|
105 | saveAndTest(authInstance) |
---|
106 | |
---|
107 | authInstance = new Authority(description:"Application User, all application users need this base role to allow login.", |
---|
108 | authority:"ROLE_AppUser") |
---|
109 | saveAndTest(authInstance) |
---|
110 | } |
---|
111 | |
---|
112 | void createBasePersonGroups() { |
---|
113 | //TypeOfPersonGroup |
---|
114 | def personGroupTypeInstance |
---|
115 | personGroupTypeInstance = new PersonGroupType(name:"Team") |
---|
116 | saveAndTest(personGroupTypeInstance) |
---|
117 | personGroupTypeInstance = new PersonGroupType(name:"Contractor") |
---|
118 | saveAndTest(personGroupTypeInstance) |
---|
119 | personGroupTypeInstance = new PersonGroupType(name:"ProjectTeam") |
---|
120 | saveAndTest(personGroupTypeInstance) |
---|
121 | |
---|
122 | //PersonGroup |
---|
123 | def personGroupInstance |
---|
124 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1), |
---|
125 | name:"Electrical") |
---|
126 | saveAndTest(personGroupInstance) |
---|
127 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1), |
---|
128 | name:"Mechanical") |
---|
129 | saveAndTest(personGroupInstance) |
---|
130 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(1), |
---|
131 | name:"Production") |
---|
132 | saveAndTest(personGroupInstance) |
---|
133 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(2), |
---|
134 | name:"Kewl AirCon Guys") |
---|
135 | saveAndTest(personGroupInstance) |
---|
136 | personGroupInstance = new PersonGroup(personGroupType:PersonGroupType.get(3), |
---|
137 | name:"gnuMims") |
---|
138 | saveAndTest(personGroupInstance) |
---|
139 | } |
---|
140 | |
---|
141 | def createAdminPerson() { |
---|
142 | //Person |
---|
143 | def passClearText = "pass" |
---|
144 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
---|
145 | def personInstance |
---|
146 | |
---|
147 | //Person #1 |
---|
148 | personInstance = new Person(loginName:"admin", |
---|
149 | firstName:"Admin", |
---|
150 | lastName:"Powers", |
---|
151 | pass:passClearText, |
---|
152 | password:passwordEncoded, |
---|
153 | email:"admin@example.com") |
---|
154 | saveAndTest(personInstance) |
---|
155 | personInstance.addToAuthorities(Authority.get(1)) |
---|
156 | } |
---|
157 | |
---|
158 | def createBasePersons() { |
---|
159 | //Person |
---|
160 | def passClearText = "pass" |
---|
161 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
---|
162 | def personInstance |
---|
163 | |
---|
164 | //Person #1 is admin. |
---|
165 | |
---|
166 | //Person #2 |
---|
167 | personInstance = new Person(loginName:"manager", |
---|
168 | firstName:"Demo", |
---|
169 | lastName:"Manager", |
---|
170 | pass:passClearText, |
---|
171 | password:passwordEncoded, |
---|
172 | email:"manager@example.com") |
---|
173 | saveAndTest(personInstance) |
---|
174 | personInstance.addToAuthorities(Authority.get(2)) |
---|
175 | personInstance.addToAuthorities(Authority.get(3)) |
---|
176 | personInstance.addToPersonGroups(PersonGroup.get(5)) |
---|
177 | |
---|
178 | //Person #3 |
---|
179 | personInstance = new Person(loginName:"user", |
---|
180 | firstName:"Demo", |
---|
181 | lastName:"User", |
---|
182 | pass:passClearText, |
---|
183 | password:passwordEncoded, |
---|
184 | email:"user@example.com") |
---|
185 | saveAndTest(personInstance) |
---|
186 | personInstance.addToAuthorities(Authority.get(3)) |
---|
187 | personInstance.addToPersonGroups(PersonGroup.get(1)) |
---|
188 | } |
---|
189 | |
---|
190 | def createDemoPersons() { |
---|
191 | //Person |
---|
192 | def passClearText = "pass" |
---|
193 | def passwordEncoded = authenticateService.encodePassword(passClearText) |
---|
194 | def personInstance |
---|
195 | |
---|
196 | //Person #4 |
---|
197 | personInstance = new Person(loginName:"craig", |
---|
198 | firstName:"Craig", |
---|
199 | lastName:"SuperSparky", |
---|
200 | pass:passClearText, |
---|
201 | password:passwordEncoded, |
---|
202 | email:"user@example.com") |
---|
203 | saveAndTest(personInstance) |
---|
204 | personInstance.addToAuthorities(Authority.get(3)) |
---|
205 | personInstance.addToPersonGroups(PersonGroup.get(1)) |
---|
206 | |
---|
207 | //Person #5 |
---|
208 | personInstance = new Person(loginName:"john", |
---|
209 | firstName:"John", |
---|
210 | lastName:"SuperFitter", |
---|
211 | pass:passClearText, |
---|
212 | password:passwordEncoded, |
---|
213 | email:"user@example.com") |
---|
214 | saveAndTest(personInstance) |
---|
215 | personInstance.addToAuthorities(Authority.get(3)) |
---|
216 | personInstance.addToPersonGroups(PersonGroup.get(2)) |
---|
217 | |
---|
218 | //Person #6 |
---|
219 | personInstance = new Person(loginName:"mann", |
---|
220 | firstName:"Production", |
---|
221 | lastName:"Mann", |
---|
222 | pass:passClearText, |
---|
223 | password:passwordEncoded, |
---|
224 | email:"user@example.com") |
---|
225 | saveAndTest(personInstance) |
---|
226 | personInstance.addToAuthorities(Authority.get(3)) |
---|
227 | personInstance.addToPersonGroups(PersonGroup.get(3)) |
---|
228 | } |
---|
229 | |
---|
230 | /*********************** |
---|
231 | START OF UTILITIES |
---|
232 | ***********************/ |
---|
233 | |
---|
234 | def createDemoSites() { |
---|
235 | //Site |
---|
236 | def siteInstance |
---|
237 | |
---|
238 | siteInstance = new Site(name: "Creek Mill") |
---|
239 | saveAndTest(siteInstance) |
---|
240 | |
---|
241 | siteInstance = new Site(name: "Jasper Street Depot") |
---|
242 | saveAndTest(siteInstance) |
---|
243 | |
---|
244 | siteInstance = new Site(name: "River Press") |
---|
245 | saveAndTest(siteInstance) |
---|
246 | } |
---|
247 | |
---|
248 | def createDemoDepartments() { |
---|
249 | |
---|
250 | //Department |
---|
251 | def departmentInstance |
---|
252 | |
---|
253 | //Department #1 |
---|
254 | departmentInstance = new Department(name: "Print Centre", |
---|
255 | site: Site.get(1)) |
---|
256 | saveAndTest(departmentInstance) |
---|
257 | |
---|
258 | //Department #2 |
---|
259 | departmentInstance = new Department(name: "Pulp Mill 2", |
---|
260 | site: Site.get(2)) |
---|
261 | saveAndTest(departmentInstance) |
---|
262 | } |
---|
263 | |
---|
264 | def createBaseUnitsOfMeasure() { |
---|
265 | |
---|
266 | //UnitOfMeasure |
---|
267 | def unitOfMeasureInstance |
---|
268 | |
---|
269 | //UnitOfMeasure #1 |
---|
270 | unitOfMeasureInstance = new UnitOfMeasure(name: "each") |
---|
271 | saveAndTest(unitOfMeasureInstance) |
---|
272 | |
---|
273 | //UnitOfMeasure #2 |
---|
274 | unitOfMeasureInstance = new UnitOfMeasure(name: "meter(s)") |
---|
275 | saveAndTest(unitOfMeasureInstance) |
---|
276 | |
---|
277 | //UnitOfMeasure #3 |
---|
278 | unitOfMeasureInstance = new UnitOfMeasure(name: "box(es)") |
---|
279 | saveAndTest(unitOfMeasureInstance) |
---|
280 | |
---|
281 | //UnitOfMeasure #4 |
---|
282 | unitOfMeasureInstance = new UnitOfMeasure(name: "litre(s)") |
---|
283 | saveAndTest(unitOfMeasureInstance) |
---|
284 | |
---|
285 | //UnitOfMeasure #5 |
---|
286 | unitOfMeasureInstance = new UnitOfMeasure(name: "kilogram(s)") |
---|
287 | saveAndTest(unitOfMeasureInstance) |
---|
288 | } |
---|
289 | |
---|
290 | def createBasePeriods() { |
---|
291 | |
---|
292 | //Period |
---|
293 | def periodInstance |
---|
294 | |
---|
295 | //Period #1 |
---|
296 | periodInstance = new Period(period: "Day(s)") |
---|
297 | saveAndTest(periodInstance) |
---|
298 | |
---|
299 | //Period #2 |
---|
300 | periodInstance = new Period(period: "Week(s)") |
---|
301 | saveAndTest(periodInstance) |
---|
302 | |
---|
303 | //Period #3 |
---|
304 | periodInstance = new Period(period: "Month(s)") |
---|
305 | saveAndTest(periodInstance) |
---|
306 | |
---|
307 | //Period #4 |
---|
308 | periodInstance = new Period(period: "Year(s)") |
---|
309 | saveAndTest(periodInstance) |
---|
310 | } |
---|
311 | |
---|
312 | /********************* |
---|
313 | START OF TASK |
---|
314 | *********************/ |
---|
315 | |
---|
316 | def createDemoTaskGroups() { |
---|
317 | //TaskGroup |
---|
318 | def taskGroupInstance |
---|
319 | |
---|
320 | taskGroupInstance = new TaskGroup(name:"Engineering Activites", |
---|
321 | description:"Engineering daily activities") |
---|
322 | saveAndTest(taskGroupInstance) |
---|
323 | |
---|
324 | taskGroupInstance = new TaskGroup(name:"Production Activites", |
---|
325 | description:"Production daily activities") |
---|
326 | saveAndTest(taskGroupInstance) |
---|
327 | |
---|
328 | taskGroupInstance = new TaskGroup(name:"New Projects", |
---|
329 | description:" ") |
---|
330 | saveAndTest(taskGroupInstance) |
---|
331 | } |
---|
332 | |
---|
333 | def createBaseTaskStatus() { |
---|
334 | |
---|
335 | //TaskStatus |
---|
336 | def taskStatusInstance |
---|
337 | |
---|
338 | taskStatusInstance = new TaskStatus(name:"Not Started") |
---|
339 | saveAndTest(taskStatusInstance) |
---|
340 | |
---|
341 | taskStatusInstance = new TaskStatus(name:"In Progress") |
---|
342 | saveAndTest(taskStatusInstance) |
---|
343 | |
---|
344 | taskStatusInstance = new TaskStatus(name:"Completed") |
---|
345 | saveAndTest(taskStatusInstance) |
---|
346 | } |
---|
347 | |
---|
348 | def createBaseTaskPriorities() { |
---|
349 | |
---|
350 | //TaskPriority |
---|
351 | def taskPriorityInstance |
---|
352 | |
---|
353 | taskPriorityInstance = new TaskPriority(name:"Normal") |
---|
354 | saveAndTest(taskPriorityInstance) |
---|
355 | |
---|
356 | taskPriorityInstance = new TaskPriority(name:"Low") |
---|
357 | saveAndTest(taskPriorityInstance) |
---|
358 | |
---|
359 | taskPriorityInstance = new TaskPriority(name:"High") |
---|
360 | saveAndTest(taskPriorityInstance) |
---|
361 | |
---|
362 | taskPriorityInstance = new TaskPriority(name:"Immediate") |
---|
363 | saveAndTest(taskPriorityInstance) |
---|
364 | } |
---|
365 | |
---|
366 | def createBaseTaskTypes() { |
---|
367 | |
---|
368 | //TaskType |
---|
369 | def taskTypeInstance |
---|
370 | |
---|
371 | taskTypeInstance = new TaskType(name:"Unscheduled Breakin") |
---|
372 | saveAndTest(taskTypeInstance) |
---|
373 | |
---|
374 | taskTypeInstance = new TaskType(name:"Preventative Maintenance") |
---|
375 | saveAndTest(taskTypeInstance) |
---|
376 | |
---|
377 | taskTypeInstance = new TaskType(name:"Project") |
---|
378 | saveAndTest(taskTypeInstance) |
---|
379 | |
---|
380 | taskTypeInstance = new TaskType(name:"Turnaround") |
---|
381 | saveAndTest(taskTypeInstance) |
---|
382 | |
---|
383 | taskTypeInstance = new TaskType(name:"Production Run") |
---|
384 | saveAndTest(taskTypeInstance) |
---|
385 | } |
---|
386 | |
---|
387 | def createDemoTasks() { |
---|
388 | |
---|
389 | //Task |
---|
390 | def taskInstance |
---|
391 | |
---|
392 | //Task #1 |
---|
393 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
394 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
395 | taskPriority:TaskPriority.get(2), |
---|
396 | taskType:TaskType.get(1), |
---|
397 | leadPerson:Person.get(2), |
---|
398 | description:"Check specific level sensor", |
---|
399 | comment:"Has been noted as problematic, try recalibrating.", |
---|
400 | targetStartDate:new Date()) |
---|
401 | saveAndTest(taskInstance) |
---|
402 | |
---|
403 | //Task #2 |
---|
404 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
405 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
406 | taskPriority:TaskPriority.get(2), |
---|
407 | taskType:TaskType.get(1), |
---|
408 | leadPerson:Person.get(5), |
---|
409 | description:"Some follow-up work", |
---|
410 | comment:"Some help required", |
---|
411 | targetStartDate:new Date()+1, |
---|
412 | parentTask: Task.get(1)) |
---|
413 | saveAndTest(taskInstance) |
---|
414 | |
---|
415 | //Task #3 |
---|
416 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
417 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
418 | taskPriority:TaskPriority.get(2), |
---|
419 | taskType:TaskType.get(1), |
---|
420 | leadPerson:Person.get(5), |
---|
421 | description:"A Sub Task can be created by setting the Parent Task value", |
---|
422 | comment:"Some help required", |
---|
423 | targetStartDate:new Date()-1, |
---|
424 | parentTask: Task.get(1)) |
---|
425 | saveAndTest(taskInstance) |
---|
426 | |
---|
427 | //Task #4 |
---|
428 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Engineering Activites"), |
---|
429 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
430 | taskPriority:TaskPriority.get(2), |
---|
431 | taskType:TaskType.get(1), |
---|
432 | leadPerson:Person.get(4), |
---|
433 | description:"Replace sensor at next opportunity.", |
---|
434 | comment:"Nothing else has worked.", |
---|
435 | targetStartDate:new Date()+7, |
---|
436 | parentTask: Task.get(1)) |
---|
437 | saveAndTest(taskInstance) |
---|
438 | |
---|
439 | //Task #5 |
---|
440 | taskInstance = new Task(taskGroup:TaskGroup.findByName("Production Activites"), |
---|
441 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
442 | taskPriority:TaskPriority.get(2), |
---|
443 | taskType:TaskType.get(5), |
---|
444 | leadPerson:Person.get(6), |
---|
445 | description:"Production Report", |
---|
446 | comment:"Production report for specific production run or shift", |
---|
447 | targetStartDate:new Date()-7) |
---|
448 | saveAndTest(taskInstance) |
---|
449 | |
---|
450 | //Task #6 |
---|
451 | taskInstance = new Task(taskGroup:TaskGroup.findByName("New Projects"), |
---|
452 | taskStatus:TaskStatus.findByName("Not Started"), |
---|
453 | taskPriority:TaskPriority.get(2), |
---|
454 | taskType:TaskType.get(3), |
---|
455 | leadPerson:Person.get(1), |
---|
456 | description:"Make killer CMMS app", |
---|
457 | comment:"Use Grails and get a move on!", |
---|
458 | targetStartDate:new Date()-6) |
---|
459 | saveAndTest(taskInstance) |
---|
460 | } |
---|
461 | |
---|
462 | def createBaseEntryTypes() { |
---|
463 | |
---|
464 | //EntryType |
---|
465 | def entryTypeInstance |
---|
466 | |
---|
467 | entryTypeInstance = new EntryType(name:"Fault") |
---|
468 | saveAndTest(entryTypeInstance) |
---|
469 | |
---|
470 | entryTypeInstance = new EntryType(name:"WorkDone") |
---|
471 | saveAndTest(entryTypeInstance) |
---|
472 | |
---|
473 | entryTypeInstance = new EntryType(name:"Production Note") |
---|
474 | saveAndTest(entryTypeInstance) |
---|
475 | |
---|
476 | entryTypeInstance = new EntryType(name:"Work Request") |
---|
477 | saveAndTest(entryTypeInstance) |
---|
478 | } |
---|
479 | |
---|
480 | def createDemoEntries() { |
---|
481 | |
---|
482 | //Entry |
---|
483 | def entryInstance |
---|
484 | |
---|
485 | //Entry #1 |
---|
486 | entryInstance = new Entry(enteredBy: Person.get(3), |
---|
487 | task: Task.get(1), |
---|
488 | entryType: EntryType.findByName("Fault"), |
---|
489 | comment: "This level sensor is causing us trouble.", |
---|
490 | durationMinute: 20) |
---|
491 | saveAndTest(entryInstance) |
---|
492 | |
---|
493 | //Entry #2 |
---|
494 | entryInstance = new Entry(enteredBy: Person.get(4), |
---|
495 | task: Task.get(1), |
---|
496 | entryType: EntryType.findByName("WorkDone"), |
---|
497 | comment: "Cleaned sensor, see how it goes.", |
---|
498 | durationMinute: 30) |
---|
499 | saveAndTest(entryInstance) |
---|
500 | |
---|
501 | //Entry #3 |
---|
502 | entryInstance = new Entry(enteredBy: Person.get(4), |
---|
503 | task: Task.get(1), |
---|
504 | entryType: EntryType.findByName("WorkDone"), |
---|
505 | comment: "Checked up on it later and sensor is dropping out intermittently, created subTask to replace sensor.", |
---|
506 | durationMinute: 20) |
---|
507 | saveAndTest(entryInstance) |
---|
508 | } |
---|
509 | |
---|
510 | def createBaseModificationTypes() { |
---|
511 | |
---|
512 | //ModificationType |
---|
513 | def taskModificationTypeInstance |
---|
514 | taskModificationTypeInstance = new TaskModificationType(name:"Created").save() |
---|
515 | taskModificationTypeInstance = new TaskModificationType(name:"Completed").save() |
---|
516 | taskModificationTypeInstance = new TaskModificationType(name:"Closed").save() |
---|
517 | taskModificationTypeInstance = new TaskModificationType(name:"Altered").save() |
---|
518 | taskModificationTypeInstance = new TaskModificationType(name:"TargetDateModified").save() |
---|
519 | taskModificationTypeInstance = new TaskModificationType(name:"ScheduledDateModified").save() |
---|
520 | taskModificationTypeInstance = new TaskModificationType(name:"DescriptionModified").save() |
---|
521 | taskModificationTypeInstance = new TaskModificationType(name:"AssignedToModified").save() |
---|
522 | taskModificationTypeInstance = new TaskModificationType(name:"NameModified").save() |
---|
523 | } |
---|
524 | |
---|
525 | def createDemoAssignedPersons() { |
---|
526 | |
---|
527 | //AssignedPerson |
---|
528 | def assignedPersonInstance |
---|
529 | |
---|
530 | //AssignedPerson #1 |
---|
531 | assignedPersonInstance = new AssignedPerson(person: Person.get(4), |
---|
532 | task: Task.get(1), |
---|
533 | estimatedHour: 1, |
---|
534 | estimatedMinute: 20) |
---|
535 | saveAndTest(assignedPersonInstance) |
---|
536 | |
---|
537 | //AssignedPerson #2 |
---|
538 | assignedPersonInstance = new AssignedPerson(person: Person.get(5), |
---|
539 | task: Task.get(1), |
---|
540 | estimatedHour: 3, |
---|
541 | estimatedMinute: 30) |
---|
542 | saveAndTest(assignedPersonInstance) |
---|
543 | } |
---|
544 | |
---|
545 | def createDemoTaskRecurringSchedules() { |
---|
546 | |
---|
547 | //TaskRecurringSchedule |
---|
548 | def taskRecurringScheduleInstance |
---|
549 | |
---|
550 | //TaskRecurringSchedule #1 |
---|
551 | taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1), |
---|
552 | recurEvery: 1, |
---|
553 | recurPeriod: Period.get(1), |
---|
554 | startDate: new Date(), |
---|
555 | generateAhead: 1, |
---|
556 | generateAheadPeriod: Period.get(1), |
---|
557 | taskDuration: 1, |
---|
558 | taskDurationPeriod: Period.get(1)) |
---|
559 | saveAndTest(taskRecurringScheduleInstance) |
---|
560 | |
---|
561 | //TaskRecurringSchedule #2 |
---|
562 | taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(2), |
---|
563 | recurEvery: 1, |
---|
564 | recurPeriod: Period.get(1), |
---|
565 | startDate: new Date(), |
---|
566 | generateAhead: 1, |
---|
567 | generateAheadPeriod: Period.get(1), |
---|
568 | taskDuration: 1, |
---|
569 | taskDurationPeriod: Period.get(1)) |
---|
570 | saveAndTest(taskRecurringScheduleInstance) |
---|
571 | } |
---|
572 | |
---|
573 | /************************* |
---|
574 | START OF INVENTORY |
---|
575 | **************************/ |
---|
576 | |
---|
577 | def createDemoInventoryStores() { |
---|
578 | |
---|
579 | //InventoryStore |
---|
580 | def inventoryStoreInstance |
---|
581 | |
---|
582 | inventoryStoreInstance = new InventoryStore(site: Site.get(1), name: "Store #1") |
---|
583 | saveAndTest(inventoryStoreInstance) |
---|
584 | |
---|
585 | inventoryStoreInstance = new InventoryStore(site: Site.get(2), name: "Store #2") |
---|
586 | saveAndTest(inventoryStoreInstance) |
---|
587 | } |
---|
588 | |
---|
589 | def createDemoStoreLocations() { |
---|
590 | |
---|
591 | //StoreLocation |
---|
592 | def storeLocation |
---|
593 | |
---|
594 | storeLocation = new StoreLocation(inventoryStore: InventoryStore.get(1), bin: "A1-2") |
---|
595 | saveAndTest(storeLocation) |
---|
596 | |
---|
597 | storeLocation = new StoreLocation(inventoryStore: InventoryStore.get(1), bin: "C55") |
---|
598 | saveAndTest(storeLocation) |
---|
599 | } |
---|
600 | |
---|
601 | def createDemoInventoryGroups() { |
---|
602 | |
---|
603 | //InventoryGroup |
---|
604 | def inventoryGroupInstance |
---|
605 | |
---|
606 | //InventoryGroup #1 |
---|
607 | inventoryGroupInstance = new InventoryGroup(name: "Misc") |
---|
608 | saveAndTest(inventoryGroupInstance) |
---|
609 | |
---|
610 | //InventoryGroup #2 |
---|
611 | inventoryGroupInstance = new InventoryGroup(name: "Electrical") |
---|
612 | saveAndTest(inventoryGroupInstance) |
---|
613 | |
---|
614 | //InventoryGroup #3 |
---|
615 | inventoryGroupInstance = new InventoryGroup(name: "Mechanical") |
---|
616 | saveAndTest(inventoryGroupInstance) |
---|
617 | |
---|
618 | //InventoryGroup #4 |
---|
619 | inventoryGroupInstance = new InventoryGroup(name: "Production") |
---|
620 | saveAndTest(inventoryGroupInstance) |
---|
621 | } |
---|
622 | |
---|
623 | def createBaseInventoryTypes() { |
---|
624 | |
---|
625 | //InventoryType |
---|
626 | def inventoryTypeInstance |
---|
627 | |
---|
628 | inventoryTypeInstance = new InventoryType(name: "Consumable") |
---|
629 | saveAndTest(inventoryTypeInstance) |
---|
630 | |
---|
631 | inventoryTypeInstance = new InventoryType(name: "Repairable") |
---|
632 | saveAndTest(inventoryTypeInstance) |
---|
633 | } |
---|
634 | |
---|
635 | def createDemoInventoryItems() { |
---|
636 | |
---|
637 | //InventoryItem |
---|
638 | def inventoryItemInstance |
---|
639 | |
---|
640 | //InventoryItem #1 |
---|
641 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1), |
---|
642 | inventoryType: InventoryType.get(1), |
---|
643 | unitOfMeasure: UnitOfMeasure.get(2), |
---|
644 | name: "J-Rope", |
---|
645 | description: "Twine wound J-Rope", |
---|
646 | reorderPoint: 0) |
---|
647 | saveAndTest(inventoryItemInstance) |
---|
648 | |
---|
649 | //InventoryItem #2 |
---|
650 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(1), |
---|
651 | inventoryType: InventoryType.get(1), |
---|
652 | unitOfMeasure: UnitOfMeasure.get(2), |
---|
653 | name: "L-Rope", |
---|
654 | description: "Twine wound L-Rope", |
---|
655 | alternateItems: InventoryItem.get(1), |
---|
656 | reorderPoint: 0) |
---|
657 | saveAndTest(inventoryItemInstance) |
---|
658 | |
---|
659 | //InventoryItem #3 |
---|
660 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3), |
---|
661 | inventoryType: InventoryType.get(1), |
---|
662 | unitOfMeasure: UnitOfMeasure.get(1), |
---|
663 | name: "2305-2RS", |
---|
664 | description: "Bearing 25x62x24mm double row self aligning ball", |
---|
665 | reorderPoint: 2) |
---|
666 | saveAndTest(inventoryItemInstance) |
---|
667 | |
---|
668 | //InventoryItem #4 |
---|
669 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(2), |
---|
670 | inventoryType: InventoryType.get(1), |
---|
671 | unitOfMeasure: UnitOfMeasure.get(1), |
---|
672 | name: "L1592-K10", |
---|
673 | description: "10kW contactor", |
---|
674 | reorderPoint: 0) |
---|
675 | saveAndTest(inventoryItemInstance) |
---|
676 | |
---|
677 | //InventoryItem #5 |
---|
678 | inventoryItemInstance = new InventoryItem(inventoryGroup: InventoryGroup.get(3), |
---|
679 | inventoryType: InventoryType.get(1), |
---|
680 | unitOfMeasure: UnitOfMeasure.get(1), |
---|
681 | name: "6205-ZZ", |
---|
682 | description: "Bearing 25x52x15mm single row ball shielded", |
---|
683 | reorderPoint: 2) |
---|
684 | saveAndTest(inventoryItemInstance) |
---|
685 | } |
---|
686 | |
---|
687 | def createDemoStoredItems() { |
---|
688 | |
---|
689 | //StoredItem |
---|
690 | def storedItemInstance |
---|
691 | |
---|
692 | //StoredItem #1 |
---|
693 | storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(1), |
---|
694 | storeLocation: StoreLocation.get(1), |
---|
695 | quantity: 8) |
---|
696 | saveAndTest(storedItemInstance) |
---|
697 | |
---|
698 | //StoredItem #2 |
---|
699 | storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(1), |
---|
700 | storeLocation: StoreLocation.get(2), |
---|
701 | quantity: 4) |
---|
702 | saveAndTest(storedItemInstance) |
---|
703 | |
---|
704 | //StoredItem #3 |
---|
705 | storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(2), |
---|
706 | storeLocation: StoreLocation.get(1), |
---|
707 | quantity: 2) |
---|
708 | saveAndTest(storedItemInstance) |
---|
709 | |
---|
710 | //StoredItem #4 |
---|
711 | storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(3), |
---|
712 | storeLocation: StoreLocation.get(1), |
---|
713 | quantity: 2) |
---|
714 | saveAndTest(storedItemInstance) |
---|
715 | |
---|
716 | //StoredItem #5 |
---|
717 | storedItemInstance = new StoredItem(inventoryItem: InventoryItem.get(4), |
---|
718 | storeLocation: StoreLocation.get(1), |
---|
719 | quantity: 30) |
---|
720 | saveAndTest(storedItemInstance) |
---|
721 | } |
---|
722 | |
---|
723 | /******************* |
---|
724 | START OF ASSET |
---|
725 | *******************/ |
---|
726 | |
---|
727 | def createDemoLifePlan() { |
---|
728 | |
---|
729 | //LifePlan |
---|
730 | def lifeplanInstance |
---|
731 | |
---|
732 | lifeplanInstance = new LifePlan(name: "Initial Plan") |
---|
733 | saveAndTest(lifeplanInstance) |
---|
734 | } |
---|
735 | |
---|
736 | def createBaseMaintenancePolicies() { |
---|
737 | |
---|
738 | //MaintenancePolicy |
---|
739 | def maintenancePolicyInstance |
---|
740 | |
---|
741 | //MaintenancePolicy #1 |
---|
742 | maintenancePolicyInstance = new MaintenancePolicy(name: "Fixed Time") |
---|
743 | saveAndTest(maintenancePolicyInstance) |
---|
744 | |
---|
745 | //MaintenancePolicy #2 |
---|
746 | maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Online") |
---|
747 | saveAndTest(maintenancePolicyInstance) |
---|
748 | |
---|
749 | //MaintenancePolicy #3 |
---|
750 | maintenancePolicyInstance = new MaintenancePolicy(name: "Condition Based Offline") |
---|
751 | saveAndTest(maintenancePolicyInstance) |
---|
752 | |
---|
753 | //MaintenancePolicy #4 |
---|
754 | maintenancePolicyInstance = new MaintenancePolicy(name: "Design Out") |
---|
755 | saveAndTest(maintenancePolicyInstance) |
---|
756 | |
---|
757 | //MaintenancePolicy #5 |
---|
758 | maintenancePolicyInstance = new MaintenancePolicy(name: "Operate To Failure") |
---|
759 | saveAndTest(maintenancePolicyInstance) |
---|
760 | } |
---|
761 | |
---|
762 | def createDemoTaskProcedure() { |
---|
763 | |
---|
764 | //TaskProcedure |
---|
765 | def taskProcedureInstance |
---|
766 | |
---|
767 | taskProcedureInstance = new TaskProcedure(name: "Daily check") |
---|
768 | saveAndTest(taskProcedureInstance) |
---|
769 | taskProcedureInstance.addToTasks(Task.get(1)) |
---|
770 | } |
---|
771 | |
---|
772 | def createDemoMaintenanceActions() { |
---|
773 | |
---|
774 | //MaintenanceAction |
---|
775 | def maintenanceActionInstance |
---|
776 | |
---|
777 | //MaintenanceAction #1 |
---|
778 | maintenanceActionInstance = new MaintenanceAction(description: "Check all E-stops, activate E-stops S1-S12 and ensure machine cannot run", |
---|
779 | procedureStepNumber: 1, |
---|
780 | maintenancePolicy: MaintenancePolicy.get(1), |
---|
781 | taskProcedure: TaskProcedure.get(1)) |
---|
782 | saveAndTest(maintenanceActionInstance) |
---|
783 | |
---|
784 | //MaintenanceAction #2 |
---|
785 | maintenanceActionInstance = new MaintenanceAction(description: "Do more pushups", |
---|
786 | procedureStepNumber: 2, |
---|
787 | maintenancePolicy: MaintenancePolicy.get(1), |
---|
788 | taskProcedure: TaskProcedure.get(1)) |
---|
789 | saveAndTest(maintenanceActionInstance) |
---|
790 | |
---|
791 | //MaintenanceAction #3 |
---|
792 | maintenanceActionInstance = new MaintenanceAction(description: "Ok just one more pushup", |
---|
793 | procedureStepNumber: 3, |
---|
794 | maintenancePolicy: MaintenancePolicy.get(1), |
---|
795 | taskProcedure: TaskProcedure.get(1)) |
---|
796 | saveAndTest(maintenanceActionInstance) |
---|
797 | } |
---|
798 | |
---|
799 | def createDemoSystemSections() { |
---|
800 | |
---|
801 | //SystemSection |
---|
802 | def systemSectionInstance |
---|
803 | |
---|
804 | //SystemSection #1 |
---|
805 | systemSectionInstance = new SystemSection(name: "Press Section", |
---|
806 | site: Site.get(1), |
---|
807 | department: Department.get(1)) |
---|
808 | saveAndTest(systemSectionInstance) |
---|
809 | |
---|
810 | //SystemSection #2 |
---|
811 | systemSectionInstance = new SystemSection(name: "RO System", |
---|
812 | site: Site.get(2), |
---|
813 | department: Department.get(2)) |
---|
814 | saveAndTest(systemSectionInstance) |
---|
815 | |
---|
816 | //SystemSection #3 |
---|
817 | systemSectionInstance = new SystemSection(name: "Auxilliray Section", |
---|
818 | site: Site.get(1), |
---|
819 | department: Department.get(1)) |
---|
820 | saveAndTest(systemSectionInstance) |
---|
821 | } |
---|
822 | |
---|
823 | def createDemoAssetTypes() { |
---|
824 | |
---|
825 | //AssetType |
---|
826 | def assetTypeInstance |
---|
827 | |
---|
828 | //AssetType #1 |
---|
829 | assetTypeInstance = new AssetType(name: "Print Unit") |
---|
830 | saveAndTest(assetTypeInstance) |
---|
831 | |
---|
832 | //AssetType #2 |
---|
833 | assetTypeInstance = new AssetType(name: "Reactor Tower") |
---|
834 | saveAndTest(assetTypeInstance) |
---|
835 | } |
---|
836 | |
---|
837 | def createDemoAssemblies() { |
---|
838 | |
---|
839 | //Assembly |
---|
840 | def assemblyInstance |
---|
841 | |
---|
842 | //Assembly #1 |
---|
843 | assemblyInstance = new Assembly(name: "Print Couple", |
---|
844 | assetType: AssetType.get(1)) |
---|
845 | saveAndTest(assemblyInstance) |
---|
846 | // assemblyInstance.addToMaintenanceActions(MaintenanceAction.get(1)) |
---|
847 | |
---|
848 | //Assembly #2 |
---|
849 | assemblyInstance = new Assembly(name: "Agitator", |
---|
850 | assetType: AssetType.get(2)) |
---|
851 | saveAndTest(assemblyInstance) |
---|
852 | } |
---|
853 | |
---|
854 | def createDemoSubAssemblies() { |
---|
855 | |
---|
856 | //SubAssembly |
---|
857 | def subAssemblyInstance |
---|
858 | |
---|
859 | //SubAssembly #1 |
---|
860 | subAssemblyInstance = new SubAssembly(name: "Cylinder", |
---|
861 | assembly: Assembly.get(1)) |
---|
862 | saveAndTest(subAssemblyInstance) |
---|
863 | |
---|
864 | //SubAssembly #2 |
---|
865 | subAssemblyInstance = new SubAssembly(name: "Gearmotor", |
---|
866 | assembly: Assembly.get(2)) |
---|
867 | saveAndTest(subAssemblyInstance) |
---|
868 | } |
---|
869 | |
---|
870 | def createDemoComponentItems() { |
---|
871 | |
---|
872 | //ComponentItem |
---|
873 | def componentItemInstance |
---|
874 | |
---|
875 | //ComponentItem #1 |
---|
876 | componentItemInstance = new ComponentItem(name: "Bearing", |
---|
877 | subAssembly: SubAssembly.get(1)) |
---|
878 | saveAndTest(componentItemInstance) |
---|
879 | |
---|
880 | //ComponentItem #2 |
---|
881 | componentItemInstance = new ComponentItem(name: "Drive shaft oil seal", |
---|
882 | subAssembly: SubAssembly.get(2)) |
---|
883 | saveAndTest(componentItemInstance) |
---|
884 | } |
---|
885 | |
---|
886 | def createDemoAssets() { |
---|
887 | |
---|
888 | //Asset |
---|
889 | def assetInstance |
---|
890 | |
---|
891 | //Asset #1 |
---|
892 | assetInstance = new Asset(name: "Print Unit 22", |
---|
893 | assetType: AssetType.get(1), |
---|
894 | systemSection: SystemSection.get(1)) |
---|
895 | saveAndTest(assetInstance) |
---|
896 | // assetInstance.addToMaintenanceActions(MaintenanceAction.get(1)) |
---|
897 | |
---|
898 | //Asset #2 |
---|
899 | assetInstance = new Asset(name: "Print Unit 21", |
---|
900 | assetType: AssetType.get(1), |
---|
901 | systemSection: SystemSection.get(1)) |
---|
902 | saveAndTest(assetInstance) |
---|
903 | |
---|
904 | //Asset #3 |
---|
905 | assetInstance = new Asset(name: "Print Unit 23", |
---|
906 | assetType: AssetType.get(1), |
---|
907 | systemSection: SystemSection.get(1)) |
---|
908 | saveAndTest(assetInstance) |
---|
909 | |
---|
910 | //Asset #4 |
---|
911 | assetInstance = new Asset(name: "RO 1", |
---|
912 | assetType: AssetType.get(2), |
---|
913 | systemSection: SystemSection.get(2)) |
---|
914 | saveAndTest(assetInstance) |
---|
915 | } |
---|
916 | |
---|
917 | def createBaseAssetExtenededAttributeTypes() { |
---|
918 | |
---|
919 | //AssetExtendedAttributeType |
---|
920 | def assetExtendedAttributeInstanceType |
---|
921 | |
---|
922 | //AssetExtendedAttributeType #1 |
---|
923 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Model Number") |
---|
924 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
925 | |
---|
926 | //AssetExtendedAttributeType #2 |
---|
927 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Purchase Cost") |
---|
928 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
929 | |
---|
930 | //AssetExtendedAttributeType #3 |
---|
931 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Serial Number") |
---|
932 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
933 | |
---|
934 | //AssetExtendedAttributeType #4 |
---|
935 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Manufactured Date") |
---|
936 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
937 | |
---|
938 | //AssetExtendedAttributeType #5 |
---|
939 | assetExtendedAttributeInstanceType = new AssetExtendedAttributeType(name: "Location Description") |
---|
940 | saveAndTest(assetExtendedAttributeInstanceType) |
---|
941 | } |
---|
942 | |
---|
943 | def createDemoAssetExtenedAttributes() { |
---|
944 | |
---|
945 | //AssetExtendedAttribute |
---|
946 | def assetExtendedAttributeInstance |
---|
947 | |
---|
948 | //AssetExtendedAttribute #1 |
---|
949 | assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "PU Mark 2", |
---|
950 | asset: Asset.get(1), |
---|
951 | assetExtendedAttributeType: AssetExtendedAttributeType.get(1)) |
---|
952 | saveAndTest(assetExtendedAttributeInstance) |
---|
953 | |
---|
954 | //AssetExtendedAttribute #2 |
---|
955 | assetExtendedAttributeInstance = new AssetExtendedAttribute(value: "On the far side of Tank 5", |
---|
956 | asset: Asset.get(1), |
---|
957 | assetExtendedAttributeType: AssetExtendedAttributeType.get(5)) |
---|
958 | saveAndTest(assetExtendedAttributeInstance) |
---|
959 | } |
---|
960 | |
---|
961 | |
---|
962 | /**************************************** |
---|
963 | Call this function instead of .save() |
---|
964 | *****************************************/ |
---|
965 | private boolean saveAndTest(object) { |
---|
966 | if(!object.save()) { |
---|
967 | // DemoDataSuccessful = false |
---|
968 | println "'${object}' failed to save!" |
---|
969 | println object.errors |
---|
970 | return false |
---|
971 | } |
---|
972 | return true |
---|
973 | } |
---|
974 | } |
---|