source: branches/util-apps/DomainUtil/grails-app/controllers/UtilController.groovy @ 766

Last change on this file since 766 was 766, checked in by gav, 13 years ago

Add branches/util-apps/DomainUtil application.

File size: 2.6 KB
Line 
1class UtilController {
2
3    def index = { redirect(action:createData,params:params) }
4
5    def run = {
6
7        def tp
8        def m
9
10        if(!TaskProcedure.count()) {
11            println "Creating."
12            tp = new TaskProcedure(linkedTask: Task.get(1))
13        }
14        else {
15            tp = TaskProcedure.list()[-1]
16            println "Use existing: ${tp}"
17        }
18
19        m = new MaintenanceAction(taskProcedure:tp, description: "action")
20        tp.addToMaintenanceActions(m)
21        tp.save()
22
23        def s = "TaskProcedure: ${tp.id} - ${tp.description}, ${tp.maintenanceActions} <br />"
24        s += "MaintenanceAction: ${MaintenanceAction.list()[-1].taskProcedure.description} <br />"
25        render  s
26
27    }
28
29    def createData = {
30
31        def p = [:]
32
33        //Base.
34        createBasePersons()
35        createBaseTasks()
36        //Demo.
37        createDemoTasks()
38
39        render Task.list()
40    }
41
42    def private createBasePersons() {
43        def p = [:]
44
45        if(!Authority.count())
46            def authority = new Authority(description:"Admin", authority: "ROLE_Admin") .save(failOnError:true)
47
48        if(!Person.count()) {
49            p = [loginName: 'admin',
50                    firstName: 'admin',
51                    lastName: 'Powers',
52                    pass: 'pass',
53                    password: 'pass']
54            def person = new Person(p) .save(failOnError:true)
55        }
56
57    }
58
59    def private createBaseTasks() {
60        def p = [:]
61
62        if(!TaskGroup.count())
63            def taskGroup = new TaskGroup(name:"Engineering Activites").save(failOnError:true)
64
65        if(!TaskStatus.count())
66            def taskStatus = new TaskStatus(name:'Not Started').save(failOnError:true)
67
68        if(!TaskPriority.count())
69            def taskPriority = new TaskPriority(name:'High').save(failOnError:true)
70
71        if(!TaskBudgetStatus.count())
72            def taskBudgetStatus = new TaskBudgetStatus(name:"Planned").save(failOnError:true)
73
74        if(!TaskType.count())
75            def taskType = new TaskType(name:"Immediate Callout") .save(failOnError:true)
76
77    }
78
79    def private createDemoTasks() {
80        def p = [:]
81
82        if(!Task.list()) {
83
84            //Task #1
85            p = [taskGroup:TaskGroup.get(1),
86                    taskStatus:TaskStatus.get(1),
87                    taskPriority:TaskPriority.get(1),
88                    taskBudgetStatus:TaskBudgetStatus.get(1),
89                    taskType:TaskType.get(1),
90                    leadPerson: Person.get(1),
91                    description:"100hr Service"]
92
93            def task = new Task(p).save(failOnError:true)
94        }
95
96    }
97
98}
Note: See TracBrowser for help on using the repository browser.