Index: trunk/grails-app/services/TaskService.groovy
===================================================================
--- trunk/grails-app/services/TaskService.groovy	(revision 180)
+++ trunk/grails-app/services/TaskService.groovy	(revision 181)
@@ -9,4 +9,6 @@
         Task.withTransaction { status ->
             def result = [:]
+            // Default status to "not started" if not supplied.
+            params.taskStatus = params.taskStatus ?: TaskStatus.get(1)
             def taskInstance = new Task(params)
             result.taskInstance = taskInstance
@@ -59,5 +61,4 @@
                 }
 
-
                 result.taskInstance.properties = params
 
@@ -86,26 +87,260 @@
     }  // end update()
 
-    def complete() {
-        //TaskModificationType.get(4)
+    def complete(params) {
+        Task.withTransaction { status ->
+            def result = [:]
+            result.taskInstance = Task.get(params.id)
+            if(result.taskInstance) {
+
+                // Optimistic locking check.
+                if(params.version) {
+                    def version = params.version.toLong()
+                    if(result.taskInstance.version > version) {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
+                        result.error = true
+                        return result
+                    }
+                }
+
+                result.taskInstance.taskStatus = TaskStatus.get(3)
+
+                if(result.taskInstance.save()) {
+                    def taskModification = new TaskModification(person:Person.get(authenticateService.userDomain().id),
+                                                            taskModificationType: TaskModificationType.get(4),
+                                                            task: result.taskInstance)
+                    if(taskModification.save()) {
+                        // All went well.
+                        return result
+                    }
+                    else {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("taskModifications", "task.modifications.failedToSave")
+                        result.error = true
+                        return result
+                    }
+                }
+            }
+            // Something failed.
+            status.setRollbackOnly()
+            result.error = true
+            return result
+
+        } //end withTransaction
     }  // end complete()
 
-    def reopen() {
-        //TaskModificationType.get(5)
+    def reopen(params) {
+        Task.withTransaction { status ->
+            def result = [:]
+            result.taskInstance = Task.get(params.id)
+            if(result.taskInstance) {
+
+                // Optimistic locking check.
+                if(params.version) {
+                    def version = params.version.toLong()
+                    if(result.taskInstance.version > version) {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
+                        result.error = true
+                        return result
+                    }
+                }
+
+                result.taskInstance.taskStatus = TaskStatus.get(2)
+
+                if(result.taskInstance.save()) {
+                    def taskModification = new TaskModification(person:Person.get(authenticateService.userDomain().id),
+                                                            taskModificationType: TaskModificationType.get(5),
+                                                            task: result.taskInstance)
+                    if(taskModification.save()) {
+                        // All went well.
+                        return result
+                    }
+                    else {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("taskModifications", "task.modifications.failedToSave")
+                        result.error = true
+                        return result
+                    }
+                }
+            }
+            // Something failed.
+            status.setRollbackOnly()
+            result.error = true
+            return result
+
+        } //end withTransaction
     }  // end reopen()
 
-    def trash() {
-        //TaskModificationType.get(6)
+    def trash(params) {
+        Task.withTransaction { status ->
+            def result = [:]
+            result.taskInstance = Task.get(params.id)
+            if(result.taskInstance) {
+
+                // Optimistic locking check.
+                if(params.version) {
+                    def version = params.version.toLong()
+                    if(result.taskInstance.version > version) {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
+                        result.error = true
+                        return result
+                    }
+                }
+
+                result.taskInstance.trash = true
+
+                if(result.taskInstance.save()) {
+                    def taskModification = new TaskModification(person:Person.get(authenticateService.userDomain().id),
+                                                            taskModificationType: TaskModificationType.get(6),
+                                                            task: result.taskInstance)
+                    if(taskModification.save()) {
+                        // All went well.
+                        return result
+                    }
+                    else {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("taskModifications", "task.modifications.failedToSave")
+                        result.error = true
+                        return result
+                    }
+                }
+            }
+            // Something failed.
+            status.setRollbackOnly()
+            result.error = true
+            return result
+
+        } //end withTransaction
     }  // end trash()
 
-    def restore() {
-        //TaskModificationType.get(7)
+    def restore(params) {
+        Task.withTransaction { status ->
+            def result = [:]
+            result.taskInstance = Task.get(params.id)
+            if(result.taskInstance) {
+
+                // Optimistic locking check.
+                if(params.version) {
+                    def version = params.version.toLong()
+                    if(result.taskInstance.version > version) {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
+                        result.error = true
+                        return result
+                    }
+                }
+
+                result.taskInstance.trash = false
+
+                if(result.taskInstance.save()) {
+                    def taskModification = new TaskModification(person:Person.get(authenticateService.userDomain().id),
+                                                            taskModificationType: TaskModificationType.get(7),
+                                                            task: result.taskInstance)
+                    if(taskModification.save()) {
+                        // All went well.
+                        return result
+                    }
+                    else {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("taskModifications", "task.modifications.failedToSave")
+                        result.error = true
+                        return result
+                    }
+                }
+            }
+            // Something failed.
+            status.setRollbackOnly()
+            result.error = true
+            return result
+
+        } //end withTransaction
     }  // end restore()
 
-    def approve() {
-        //TaskModificationType.get(8)
+    def approve(params) {
+        Task.withTransaction { status ->
+            def result = [:]
+            result.taskInstance = Task.get(params.id)
+            if(result.taskInstance) {
+
+                // Optimistic locking check.
+                if(params.version) {
+                    def version = params.version.toLong()
+                    if(result.taskInstance.version > version) {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
+                        result.error = true
+                        return result
+                    }
+                }
+
+                result.taskInstance.approved = true
+
+                if(result.taskInstance.save()) {
+                    def taskModification = new TaskModification(person:Person.get(authenticateService.userDomain().id),
+                                                            taskModificationType: TaskModificationType.get(8),
+                                                            task: result.taskInstance)
+                    if(taskModification.save()) {
+                        // All went well.
+                        return result
+                    }
+                    else {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("taskModifications", "task.modifications.failedToSave")
+                        result.error = true
+                        return result
+                    }
+                }
+            }
+            // Something failed.
+            status.setRollbackOnly()
+            result.error = true
+            return result
+
+        } //end withTransaction
     }  // end approve()
 
-    def renegeApproval() {
-        //TaskModificationType.get(9)
+    def renegeApproval(params) {
+        Task.withTransaction { status ->
+            def result = [:]
+            result.taskInstance = Task.get(params.id)
+            if(result.taskInstance) {
+
+                // Optimistic locking check.
+                if(params.version) {
+                    def version = params.version.toLong()
+                    if(result.taskInstance.version > version) {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("version", "task.optimistic.locking.failure", "Another user has updated this Task while you were editing.")
+                        result.error = true
+                        return result
+                    }
+                }
+
+                result.taskInstance.approved = false
+
+                if(result.taskInstance.save()) {
+                    def taskModification = new TaskModification(person:Person.get(authenticateService.userDomain().id),
+                                                            taskModificationType: TaskModificationType.get(9),
+                                                            task: result.taskInstance)
+                    if(taskModification.save()) {
+                        // All went well.
+                        return result
+                    }
+                    else {
+                        status.setRollbackOnly()
+                        result.taskInstance.errors.rejectValue("taskModifications", "task.modifications.failedToSave")
+                        result.error = true
+                        return result
+                    }
+                }
+            }
+            // Something failed.
+            status.setRollbackOnly()
+            result.error = true
+            return result
+
+        } //end withTransaction
     }  // end renegeApproval()
 
