Index: trunk/grails-app/services/CreateDataService.groovy
===================================================================
--- trunk/grails-app/services/CreateDataService.groovy	(revision 190)
+++ trunk/grails-app/services/CreateDataService.groovy	(revision 199)
@@ -18,13 +18,18 @@
 
     /**
-    * Always call this at startup to ensure admin access.
+    * Always call this at startup to ensure that we have admin access
+    * and that the system pseudo person is available.
     */
-    def ensureAdminAccess() {
+    def ensureSystemAndAdminAccess() {
         if(!Authority.findByAuthority("ROLE_AppAdmin") ) {
-            println "ROLE_AppAdmin not found, calling createAdminAuthority()."
+            log.warn "ROLE_AppAdmin not found, calling createAdminAuthority()."
             createAdminAuthority()
         }
+        if(!Person.findByloginName("system") ) {
+            log.warn "LoginName 'system' not found, calling createSystemPerson()."
+            createSystemPerson()
+        }
         if(!Person.findByloginName("admin") ) {
-            println "LoginName 'admin' not found, calling createAdminPerson()."
+            log.warn "LoginName 'admin' not found, calling createAdminPerson()."
             createAdminPerson()
         }
@@ -35,9 +40,8 @@
     */
     def createBaseData() {
-        println "Creating base data..."
+        log.info "Creating base data..."
         // Person and Utils
         createBaseAuthorities()
         createBasePersonGroups()
-        createBasePersons()
         createBaseUnitsOfMeasure()
         createBasePeriods()
@@ -64,5 +68,5 @@
     */
     def createDemoData() {
-        println "Creating demo data..."
+        log.info "Creating demo data..."
         // Person and Utils
         createDemoPersons()
@@ -148,4 +152,22 @@
     }
 
+    def createSystemPerson() {
+        //Person
+        def passClearText = "pass"
+        def passwordEncoded = personService.encodePassword(passClearText)
+        def personInstance
+
+        //Person #1
+        personInstance = new Person(loginName:"system",
+                                    firstName:"gnuMims",
+                                    lastName:"System",
+                                    description:'''This is a pseudo person that the application uses to insert data. DO NOT
+                                                        assign login authorities or change the details of this person.''',
+                                    pass:passClearText,
+                                    password:passwordEncoded,
+                                    email:"system@example.com")
+        saveAndTest(personInstance)
+    }
+
     def createAdminPerson() {
         //Person
@@ -154,8 +176,10 @@
         def personInstance
 
-        //Person #1
+        //Person #2
         personInstance = new Person(loginName:"admin",
                                     firstName:"Admin",
                                     lastName:"Powers",
+                                    description:'''Every time the application starts it ensures that the 'admin' login name is available.
+                                                        DO update the password and other details but keep the login name as 'admin'. ''',
                                     pass:passClearText,
                                     password:passwordEncoded,
@@ -166,4 +190,7 @@
 
     def createBasePersons() {
+    }
+
+    def createDemoPersons() {
         //Person
         def passClearText = "pass"
@@ -171,7 +198,8 @@
         def personInstance
 
-        //Person #1 is admin.
-
-        //Person #2
+        //Person #1 is system.
+        //Person #2 is admin.
+
+        //Person #3
         personInstance = new Person(loginName:"manager",
                                     firstName:"Demo",
@@ -185,5 +213,5 @@
         personInstance.addToPersonGroups(PersonGroup.get(5))
 
-        //Person #3
+        //Person #4
         personInstance = new Person(loginName:"user",
                                     firstName:"Demo",
@@ -195,13 +223,6 @@
         personInstance.addToAuthorities(Authority.get(3))
         personInstance.addToPersonGroups(PersonGroup.get(1))
-    }
-
-    def createDemoPersons() {
-        //Person
-        def passClearText = "pass"
-        def passwordEncoded = personService.encodePassword(passClearText)
-        def personInstance
-
-        //Person #4
+
+        //Person #5
         personInstance = new Person(loginName:"craig",
                                     firstName:"Craig",
@@ -214,5 +235,5 @@
         personInstance.addToPersonGroups(PersonGroup.get(1))
 
-        //Person #5
+        //Person #6
         personInstance = new Person(loginName:"john",
                                     firstName:"John",
@@ -225,5 +246,5 @@
         personInstance.addToPersonGroups(PersonGroup.get(2))
 
-        //Person #6
+        //Person #7
         personInstance = new Person(loginName:"mann",
                                     firstName:"Production",
@@ -425,14 +446,14 @@
         def taskPriorityInstance
 
-        taskPriorityInstance = new TaskPriority(name:"Normal")
+        taskPriorityInstance = new TaskPriority(name:"Normal") // #1
         saveAndTest(taskPriorityInstance)
 
-        taskPriorityInstance = new TaskPriority(name:"Low")
+        taskPriorityInstance = new TaskPriority(name:"Low") // #2
         saveAndTest(taskPriorityInstance)
 
-        taskPriorityInstance = new TaskPriority(name:"High")
+        taskPriorityInstance = new TaskPriority(name:"High") // #3
         saveAndTest(taskPriorityInstance)
 
-        taskPriorityInstance = new TaskPriority(name:"Immediate")
+        taskPriorityInstance = new TaskPriority(name:"Immediate") // #4
         saveAndTest(taskPriorityInstance)
     }
@@ -443,17 +464,17 @@
         def taskTypeInstance
 
-        taskTypeInstance = new TaskType(name:"Unscheduled Breakin")
+        taskTypeInstance = new TaskType(name:"Unscheduled Breakin") // #1
         saveAndTest(taskTypeInstance)
 
-        taskTypeInstance = new TaskType(name:"Preventative Maintenance")
+        taskTypeInstance = new TaskType(name:"Preventative Maintenance") // #2
         saveAndTest(taskTypeInstance)
 
-        taskTypeInstance = new TaskType(name:"Project")
+        taskTypeInstance = new TaskType(name:"Project") // #3
         saveAndTest(taskTypeInstance)
 
-        taskTypeInstance = new TaskType(name:"Turnaround")
+        taskTypeInstance = new TaskType(name:"Turnaround") // #4
         saveAndTest(taskTypeInstance)
 
-        taskTypeInstance = new TaskType(name:"Production Run")
+        taskTypeInstance = new TaskType(name:"Production Run") // #5
         saveAndTest(taskTypeInstance)
     }
@@ -481,5 +502,4 @@
         //Task #1
         p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
-                taskStatus:TaskStatus.findByName("Not Started"),
                 taskPriority:TaskPriority.get(2),
                 taskType:TaskType.get(1),
@@ -493,5 +513,4 @@
         //Task #2
         p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
-                taskStatus:TaskStatus.findByName("Not Started"),
                 taskPriority:TaskPriority.get(2),
                 taskType:TaskType.get(1),
@@ -506,5 +525,4 @@
         //Task #3
         p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
-                taskStatus:TaskStatus.findByName("Not Started"),
                 taskPriority:TaskPriority.get(2),
                 taskType:TaskType.get(1),
@@ -519,5 +537,4 @@
         //Task #4
         p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
-                 taskStatus:TaskStatus.findByName("Not Started"),
                  taskPriority:TaskPriority.get(2),
                  taskType:TaskType.get(1),
@@ -532,5 +549,4 @@
         //Task #5
         p = [taskGroup:TaskGroup.findByName("Production Activites"),
-                 taskStatus:TaskStatus.findByName("Not Started"),
                  taskPriority:TaskPriority.get(2),
                  taskType:TaskType.get(5),
@@ -538,17 +554,16 @@
                  description:"Production Report",
                  comment:"Production report for specific production run or shift",
-                targetStartDate:new Date()-7]
+                targetStartDate:new Date()-6]
 
         taskResult = taskService.create(p)
 
         //Task #6
-        p = [taskGroup:TaskGroup.findByName("New Projects"),
-                 taskStatus:TaskStatus.findByName("Not Started"),
-                 taskPriority:TaskPriority.get(2),
-                 taskType:TaskType.get(3),
-                 leadPerson:Person.get(1),
-                 description:"Make killer CMMS app",
-                 comment:"Use Grails and get a move on!",
-                targetStartDate:new Date()-6]
+        p = [taskGroup:TaskGroup.findByName("Engineering Activites"),
+                 taskPriority:TaskPriority.get(1),
+                 taskType:TaskType.get(2),
+                 leadPerson:Person.get(4),
+                 description:"This is a recurring task",
+                 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.",
+                targetStartDate:new Date()]
 
         taskResult = taskService.create(p)
@@ -631,21 +646,21 @@
         taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(1),
                                                                                                     recurEvery: 1,
-                                                                                                    recurPeriod: Period.get(1),
-                                                                                                    startDate: new Date(),
+                                                                                                    recurPeriod: Period.get(2),
+                                                                                                    nextTargetStartDate: new Date(),
                                                                                                     generateAhead: 1,
-                                                                                                    generateAheadPeriod: Period.get(1),
-                                                                                                    taskDuration: 1,
-                                                                                                    taskDurationPeriod: Period.get(1))
+                                                                                                    taskDuration: 2,
+                                                                                                    taskDurationPeriod: Period.get(1),
+                                                                                                    enabled: false)
         saveAndTest(taskRecurringScheduleInstance)
 
         //TaskRecurringSchedule #2
-        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(2),
+        taskRecurringScheduleInstance = new TaskRecurringSchedule(task: Task.get(6),
                                                                                                     recurEvery: 1,
                                                                                                     recurPeriod: Period.get(1),
-                                                                                                    startDate: new Date(),
+                                                                                                    nextTargetStartDate: new Date(),
                                                                                                     generateAhead: 1,
-                                                                                                    generateAheadPeriod: Period.get(1),
                                                                                                     taskDuration: 1,
-                                                                                                    taskDurationPeriod: Period.get(1))
+                                                                                                    taskDurationPeriod: Period.get(1),
+                                                                                                    enabled: true)
         saveAndTest(taskRecurringScheduleInstance)
     }
@@ -1051,6 +1066,6 @@
         if(!object.save()) {
 //             DemoDataSuccessful = false
-            println "'${object}' failed to save!"
-            println object.errors
+            log.error "'${object}' failed to save!"
+            log.error object.errors
             return false
         }
