class UtilController { def index = { redirect(action:createData,params:params) } def run = { def tp def m if(!TaskProcedure.count()) { println "Creating." tp = new TaskProcedure(linkedTask: Task.get(1)) } else { tp = TaskProcedure.list()[-1] println "Use existing: ${tp}" } m = new MaintenanceAction(taskProcedure:tp, description: "action") tp.addToMaintenanceActions(m) tp.save() def s = "TaskProcedure: ${tp.id} - ${tp.description}, ${tp.maintenanceActions}
" s += "MaintenanceAction: ${MaintenanceAction.list()[-1].taskProcedure.description}
" render s } def createData = { def p = [:] //Base. createBasePersons() createBaseTasks() //Demo. createDemoTasks() render Task.list() } def private createBasePersons() { def p = [:] if(!Authority.count()) def authority = new Authority(description:"Admin", authority: "ROLE_Admin") .save(failOnError:true) if(!Person.count()) { p = [loginName: 'admin', firstName: 'admin', lastName: 'Powers', pass: 'pass', password: 'pass'] def person = new Person(p) .save(failOnError:true) } } def private createBaseTasks() { def p = [:] if(!TaskGroup.count()) def taskGroup = new TaskGroup(name:"Engineering Activites").save(failOnError:true) if(!TaskStatus.count()) def taskStatus = new TaskStatus(name:'Not Started').save(failOnError:true) if(!TaskPriority.count()) def taskPriority = new TaskPriority(name:'High').save(failOnError:true) if(!TaskBudgetStatus.count()) def taskBudgetStatus = new TaskBudgetStatus(name:"Planned").save(failOnError:true) if(!TaskType.count()) def taskType = new TaskType(name:"Immediate Callout") .save(failOnError:true) } def private createDemoTasks() { def p = [:] if(!Task.list()) { //Task #1 p = [taskGroup:TaskGroup.get(1), taskStatus:TaskStatus.get(1), taskPriority:TaskPriority.get(1), taskBudgetStatus:TaskBudgetStatus.get(1), taskType:TaskType.get(1), leadPerson: Person.get(1), description:"100hr Service"] def task = new Task(p).save(failOnError:true) } } }