Changeset 199 for trunk/grails-app/services
- Timestamp:
- Nov 28, 2009, 2:17:34 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 1 stacktrace.log1 *.log 2 2 *.war
-
- Property svn:ignore
-
trunk/grails-app/services/CreateDataService.groovy
r190 r199 18 18 19 19 /** 20 * Always call this at startup to ensure admin access. 20 * Always call this at startup to ensure that we have admin access 21 * and that the system pseudo person is available. 21 22 */ 22 def ensure AdminAccess() {23 def ensureSystemAndAdminAccess() { 23 24 if(!Authority.findByAuthority("ROLE_AppAdmin") ) { 24 println "ROLE_AppAdmin not found, calling createAdminAuthority()."25 log.warn "ROLE_AppAdmin not found, calling createAdminAuthority()." 25 26 createAdminAuthority() 26 27 } 28 if(!Person.findByloginName("system") ) { 29 log.warn "LoginName 'system' not found, calling createSystemPerson()." 30 createSystemPerson() 31 } 27 32 if(!Person.findByloginName("admin") ) { 28 println "LoginName 'admin' not found, calling createAdminPerson()."33 log.warn "LoginName 'admin' not found, calling createAdminPerson()." 29 34 createAdminPerson() 30 35 } … … 35 40 */ 36 41 def createBaseData() { 37 println"Creating base data..."42 log.info "Creating base data..." 38 43 // Person and Utils 39 44 createBaseAuthorities() 40 45 createBasePersonGroups() 41 createBasePersons()42 46 createBaseUnitsOfMeasure() 43 47 createBasePeriods() … … 64 68 */ 65 69 def createDemoData() { 66 println"Creating demo data..."70 log.info "Creating demo data..." 67 71 // Person and Utils 68 72 createDemoPersons() … … 148 152 } 149 153 154 def createSystemPerson() { 155 //Person 156 def passClearText = "pass" 157 def passwordEncoded = personService.encodePassword(passClearText) 158 def personInstance 159 160 //Person #1 161 personInstance = new Person(loginName:"system", 162 firstName:"gnuMims", 163 lastName:"System", 164 description:'''This is a pseudo person that the application uses to insert data. DO NOT 165 assign login authorities or change the details of this person.''', 166 pass:passClearText, 167 password:passwordEncoded, 168 email:"system@example.com") 169 saveAndTest(personInstance) 170 } 171 150 172 def createAdminPerson() { 151 173 //Person … … 154 176 def personInstance 155 177 156 //Person # 1178 //Person #2 157 179 personInstance = new Person(loginName:"admin", 158 180 firstName:"Admin", 159 181 lastName:"Powers", 182 description:'''Every time the application starts it ensures that the 'admin' login name is available. 183 DO update the password and other details but keep the login name as 'admin'. ''', 160 184 pass:passClearText, 161 185 password:passwordEncoded, … … 166 190 167 191 def createBasePersons() { 192 } 193 194 def createDemoPersons() { 168 195 //Person 169 196 def passClearText = "pass" … … 171 198 def personInstance 172 199 173 //Person #1 is admin. 174 175 //Person #2 200 //Person #1 is system. 201 //Person #2 is admin. 202 203 //Person #3 176 204 personInstance = new Person(loginName:"manager", 177 205 firstName:"Demo", … … 185 213 personInstance.addToPersonGroups(PersonGroup.get(5)) 186 214 187 //Person # 3215 //Person #4 188 216 personInstance = new Person(loginName:"user", 189 217 firstName:"Demo", … … 195 223 personInstance.addToAuthorities(Authority.get(3)) 196 224 personInstance.addToPersonGroups(PersonGroup.get(1)) 197 } 198 199 def createDemoPersons() { 200 //Person 201 def passClearText = "pass" 202 def passwordEncoded = personService.encodePassword(passClearText) 203 def personInstance 204 205 //Person #4 225 226 //Person #5 206 227 personInstance = new Person(loginName:"craig", 207 228 firstName:"Craig", … … 214 235 personInstance.addToPersonGroups(PersonGroup.get(1)) 215 236 216 //Person # 5237 //Person #6 217 238 personInstance = new Person(loginName:"john", 218 239 firstName:"John", … … 225 246 personInstance.addToPersonGroups(PersonGroup.get(2)) 226 247 227 //Person # 6248 //Person #7 228 249 personInstance = new Person(loginName:"mann", 229 250 firstName:"Production", … … 425 446 def taskPriorityInstance 426 447 427 taskPriorityInstance = new TaskPriority(name:"Normal") 448 taskPriorityInstance = new TaskPriority(name:"Normal") // #1 428 449 saveAndTest(taskPriorityInstance) 429 450 430 taskPriorityInstance = new TaskPriority(name:"Low") 451 taskPriorityInstance = new TaskPriority(name:"Low") // #2 431 452 saveAndTest(taskPriorityInstance) 432 453 433 taskPriorityInstance = new TaskPriority(name:"High") 454 taskPriorityInstance = new TaskPriority(name:"High") // #3 434 455 saveAndTest(taskPriorityInstance) 435 456 436 taskPriorityInstance = new TaskPriority(name:"Immediate") 457 taskPriorityInstance = new TaskPriority(name:"Immediate") // #4 437 458 saveAndTest(taskPriorityInstance) 438 459 } … … 443 464 def taskTypeInstance 444 465 445 taskTypeInstance = new TaskType(name:"Unscheduled Breakin") 466 taskTypeInstance = new TaskType(name:"Unscheduled Breakin") // #1 446 467 saveAndTest(taskTypeInstance) 447 468 448 taskTypeInstance = new TaskType(name:"Preventative Maintenance") 469 taskTypeInstance = new TaskType(name:"Preventative Maintenance") // #2 449 470 saveAndTest(taskTypeInstance) 450 471 451 taskTypeInstance = new TaskType(name:"Project") 472 taskTypeInstance = new TaskType(name:"Project") // #3 452 473 saveAndTest(taskTypeInstance) 453 474 454 taskTypeInstance = new TaskType(name:"Turnaround") 475 taskTypeInstance = new TaskType(name:"Turnaround") // #4 455 476 saveAndTest(taskTypeInstance) 456 477 457 taskTypeInstance = new TaskType(name:"Production Run") 478 taskTypeInstance = new TaskType(name:"Production Run") // #5 458 479 saveAndTest(taskTypeInstance) 459 480 } … … 481 502 //Task #1 482 503 p = [taskGroup:TaskGroup.findByName("Engineering Activites"), 483 taskStatus:TaskStatus.findByName("Not Started"),484 504 taskPriority:TaskPriority.get(2), 485 505 taskType:TaskType.get(1), … … 493 513 //Task #2 494 514 p = [taskGroup:TaskGroup.findByName("Engineering Activites"), 495 taskStatus:TaskStatus.findByName("Not Started"),496 515 taskPriority:TaskPriority.get(2), 497 516 taskType:TaskType.get(1), … … 506 525 //Task #3 507 526 p = [taskGroup:TaskGroup.findByName("Engineering Activites"), 508 taskStatus:TaskStatus.findByName("Not Started"),509 527 taskPriority:TaskPriority.get(2), 510 528 taskType:TaskType.get(1), … … 519 537 //Task #4 520 538 p = [taskGroup:TaskGroup.findByName("Engineering Activites"), 521 taskStatus:TaskStatus.findByName("Not Started"),522 539 taskPriority:TaskPriority.get(2), 523 540 taskType:TaskType.get(1), … … 532 549 //Task #5 533 550 p = [taskGroup:TaskGroup.findByName("Production Activites"), 534 taskStatus:TaskStatus.findByName("Not Started"),535 551 taskPriority:TaskPriority.get(2), 536 552 taskType:TaskType.get(5), … … 538 554 description:"Production Report", 539 555 comment:"Production report for specific production run or shift", 540 targetStartDate:new Date()- 7]556 targetStartDate:new Date()-6] 541 557 542 558 taskResult = taskService.create(p) 543 559 544 560 //Task #6 545 p = [taskGroup:TaskGroup.findByName("New Projects"), 546 taskStatus:TaskStatus.findByName("Not Started"), 547 taskPriority:TaskPriority.get(2), 548 taskType:TaskType.get(3), 549 leadPerson:Person.get(1), 550 description:"Make killer CMMS app", 551 comment:"Use Grails and get a move on!", 552 targetStartDate:new Date()-6] 561 p = [taskGroup:TaskGroup.findByName("Engineering Activites"), 562 taskPriority:TaskPriority.get(1), 563 taskType:TaskType.get(2), 564 leadPerson:Person.get(4), 565 description:"This is a recurring task", 566 comment:"If there is a parent task specified then this is a generated sub task, if there is a recurring schedule specified then this is a parent task.", 567 targetStartDate:new Date()] 553 568 554 569 taskResult = taskService.create(p) … … 631 646 taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1), 632 647 recurEvery: 1, 633 recurPeriod: Period.get( 1),634 startDate: new Date(),648 recurPeriod: Period.get(2), 649 nextTargetStartDate: new Date(), 635 650 generateAhead: 1, 636 generateAheadPeriod: Period.get(1),637 taskDuration : 1,638 taskDurationPeriod: Period.get(1))651 taskDuration: 2, 652 taskDurationPeriod: Period.get(1), 653 enabled: false) 639 654 saveAndTest(taskRecurringScheduleInstance) 640 655 641 656 //TaskRecurringSchedule #2 642 taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get( 2),657 taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(6), 643 658 recurEvery: 1, 644 659 recurPeriod: Period.get(1), 645 startDate: new Date(),660 nextTargetStartDate: new Date(), 646 661 generateAhead: 1, 647 generateAheadPeriod: Period.get(1),648 662 taskDuration: 1, 649 taskDurationPeriod: Period.get(1)) 663 taskDurationPeriod: Period.get(1), 664 enabled: true) 650 665 saveAndTest(taskRecurringScheduleInstance) 651 666 } … … 1051 1066 if(!object.save()) { 1052 1067 // DemoDataSuccessful = false 1053 println"'${object}' failed to save!"1054 printlnobject.errors1068 log.error "'${object}' failed to save!" 1069 log.error object.errors 1055 1070 return false 1056 1071 }
Note: See TracChangeset
for help on using the changeset viewer.