Ignore:
Timestamp:
Nov 24, 2009, 7:57:30 AM (15 years ago)
Author:
gav
Message:

Exclude tasks in trash from subTask lists.
Add create subTask functionality.
Move possibleParentList() to TaskService.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/TaskService.groovy

    r191 r196  
     1/*
     2* Provides a service for the Task domain class.
     3*
     4*/
    15class TaskService {
    26
     
    610    def personService
    711
     12    /*
     13    * Determines and returns a possible parent list
     14    * @taskInstance The task to use when determining the possible parent list.
     15    * @returns A list of the possible parents.
     16    */
     17    def possibleParentList(taskInstance) {
     18        def criteria = taskInstance.createCriteria()
     19        def possibleParentList = criteria {
     20            and {
     21                notEqual('trash', true)
     22                notEqual('id', taskInstance.id)
     23                taskInstance.subTasks.each() { notEqual('id', it.id) }
     24                }
     25        }
     26    }
     27
     28    /*
     29    * Creates a new task with the given params.
     30    * @params The params to use when creating the new task.
     31    * @returns A map containing result.error=true (if any error) and result.taskInstance.
     32    */
    833    def create(params) {
    934        Task.withTransaction { status ->
     
    1338            def taskInstance = new Task(params)
    1439            result.taskInstance = taskInstance
     40
     41            if(result.taskInstance.parentTask?.trash) {
     42                status.setRollbackOnly()
     43                result.taskInstance.errors.rejectValue("parentTask", "task.operationNotPermittedOnTaskInTrash")
     44                result.error = true
     45                return result
     46            }
    1547
    1648            if(taskInstance.save()) {
     
    2658                }
    2759
     60                // If we get here all went well.
    2861                return result
    2962            }
     
    3669    } // end create()
    3770
     71    /*
     72    * Creates a subTask copying attributes from the parentTask unless otherwise specified.
     73    * @param parentTask The parent task to get attributes from, also set as the parent.
     74    * @param params Overrides the parent task values if specified.
     75    * @returns A map containing result.error=true (if any error) and result.taskInstance.
     76    */
     77    def createSubTask(parentTask, params = [:]) {
     78
     79        def result = [:]
     80
     81        //Make our new Task a subTask and set the required properites.
     82        def p = [:]
     83        p.parentTask = parentTask
     84        p.description = params.description ?: parentTask.description
     85        p.comment = params.comment ?: parentTask.comment
     86
     87        p.taskGroup = params.taskGroup ?: parentTask.taskGroup
     88        p.taskStatus = TaskStatus.get(1) // A new subTask must always be "Not Started".
     89        p.taskPriority = parentTask.taskPriority
     90        p.taskType = params.taskType ?: parentTask.taskType
     91        p.leadPerson = params.leadPerson ?: parentTask.leadPerson
     92        p.primaryAsset = params.primaryAsset ?: parentTask.primaryAsset
     93
     94        p.targetStartDate = params.targetStartDate ?: parentTask.targetStartDate
     95        p.targetCompletionDate = params.targetCompletionDate ?: parentTask.targetCompletionDate
     96
     97                    //Set the assignedPersons
     98//                     taskInstance.assignedPersons.each() {
     99//
     100//                     def assignedPerson = new AssignedPerson(person: it.person,
     101//                                                                                             task: subTaskInstance,
     102//                                                                                             estimatedHour: it.estimatedHour,
     103//                                                                                             estimatedMinute: it.estimatedMinute).save()
     104//                     }
     105
     106        result = create(p)
     107
     108    } // end createSubTask()
     109
     110    /*
     111    * Creates a new task entry.
     112    * @params The params to use when creating the new entry.
     113    * @returns A map containing result.error=true (if any error), result.entryInstance and result.taskId.
     114    */
    38115    def createEntry(params) {
    39116        Task.withTransaction { status ->
Note: See TracChangeset for help on using the changeset viewer.