Ignore:
Timestamp:
Dec 24, 2009, 10:22:35 AM (14 years ago)
Author:
gav
Message:

Implement copying of assigned groups and persons to auto generated sub tasks.
As per ticket #55.

File:
1 edited

Legend:

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

    r241 r243  
    5757                }
    5858
    59                 // If we get here all went well.
     59                //Add the assignedGroups, provided by a new ArrayList(task.assignedGroups)
     60                if(params.assignedGroups) {
     61                    def assignedGroupInstance
     62                    params.assignedGroups.each() {
     63                        assignedGroupInstance = new AssignedGroup(personGroup: it.personGroup,
     64                                                                                                        task: taskInstance,
     65                                                                                                        estimatedHour: it.estimatedHour,
     66                                                                                                        estimatedMinute: it.estimatedMinute)
     67
     68                        if(!assignedGroupInstance.save()) {
     69                            status.setRollbackOnly()
     70                            taskInstance.errors.rejectValue("assignedGroups", "task.assignedGroups.failedToSave")
     71                            result.error = true
     72                            return result
     73                        }
     74                    }
     75                }
     76
     77                //Add the assignedPersons, provided by a new ArrayList(task.assignedPersons)
     78                if(params.assignedPersons) {
     79                    def assignedPersonInstance
     80                    params.assignedPersons.each() {
     81                        assignedPersonInstance = new AssignedPerson(person: it.person,
     82                                                                                                            task: taskInstance,
     83                                                                                                            estimatedHour: it.estimatedHour,
     84                                                                                                            estimatedMinute: it.estimatedMinute)
     85
     86                        if(!assignedPersonInstance.save()) {
     87                            status.setRollbackOnly()
     88                            taskInstance.errors.rejectValue("assignedPersons", "task.assignedPersons.failedToSave")
     89                            result.error = true
     90                            return result
     91                        }
     92                    }
     93                }
     94
     95                // Success.
    6096                return result
    6197            }
     
    71107    * Creates a subTask copying attributes from the parentTask unless otherwise specified.
    72108    * The taskProcedure is only assigned to the sub task if given in params.
     109    * The assignedPersons and assignedGroups are only added to the sub task if given as new ArrayList's in params.
    73110    * @param parentTask The parent task to get attributes from, also set as the parent.
    74111    * @param params Overrides the parent task values if specified.
     
    96133
    97134        if(params.taskProcedure) p.taskProcedure = params.taskProcedure
    98 
    99                     //Set the assignedPersons
    100 //                     taskInstance.assignedPersons.each() {
    101 //
    102 //                     def assignedPerson = new AssignedPerson(person: it.person,
    103 //                                                                                             task: subTaskInstance,
    104 //                                                                                             estimatedHour: it.estimatedHour,
    105 //                                                                                             estimatedMinute: it.estimatedMinute).save()
    106 //                     }
     135        if(params.assignedGroups) p.assignedGroups = params.assignedGroups
     136        if(params.assignedPersons) p.assignedPersons = params.assignedPersons
    107137
    108138        result = create(p)
Note: See TracChangeset for help on using the changeset viewer.