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