Ignore:
Timestamp:
Dec 24, 2009, 1:37:01 PM (14 years ago)
Author:
gav
Message:

Improve TaskService.createSubTask() with sane attribute and collection assignment.

File:
1 edited

Legend:

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

    r243 r245  
    1111    /**
    1212    * Determines and returns a possible parent list for a task.
     13    * @todo Create and use another method that limits the results to say the latest 20 or 100 tasks?
    1314    * @param taskInstance The task to use when determining the possible parent list.
    1415    * @returns A list of the possible parents.
     
    105106
    106107    /**
    107     * Creates a subTask copying attributes from the parentTask unless otherwise specified.
    108     * 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.
     108    * Creates a subTask copying sane attributes from the parentTask unless otherwise specified in params.
     109    * The taskProcedure is only assigned to the sub task if supplied in params.
     110    * The assignedPersons and assignedGroups are only added to the sub task if supplied in params.
     111    * Collections in params must be supplied as new ArrayList's.
     112    * This method is not intended to be a copyTask method.
     113    * There should be no reason to copy tasks, try to find a better solution.
    110114    * @param parentTask The parent task to get attributes from, also set as the parent.
    111115    * @param params Overrides the parent task values if specified.
     
    121125        p.description = params.description ?: parentTask.description
    122126        p.comment = params.comment ?: parentTask.comment
     127        p.targetStartDate = params.targetStartDate ?: parentTask.targetStartDate
     128        p.targetCompletionDate = params.targetCompletionDate ?: parentTask.targetCompletionDate
    123129
    124130        p.taskGroup = params.taskGroup ?: parentTask.taskGroup
     
    128134        p.leadPerson = params.leadPerson ?: parentTask.leadPerson
    129135        p.primaryAsset = params.primaryAsset ?: parentTask.primaryAsset
    130 
    131         p.targetStartDate = params.targetStartDate ?: parentTask.targetStartDate
    132         p.targetCompletionDate = params.targetCompletionDate ?: parentTask.targetCompletionDate
    133 
     136        p.associatedAssets = params.associatedAssets ?: new ArrayList(parentTask.associatedAssets) // Collection.
     137
     138        // Only if supplied, otherwise this would be copying.
     139        if(params.scheduled) p.scheduled = params.scheduled
     140        if(params.approved) p.approved = params.approved
     141
     142        // Supplied by recurring tasks.
    134143        if(params.taskProcedure) p.taskProcedure = params.taskProcedure
    135         if(params.assignedGroups) p.assignedGroups = params.assignedGroups
    136         if(params.assignedPersons) p.assignedPersons = params.assignedPersons
    137 
     144        if(params.assignedGroups) p.assignedGroups = params.assignedGroups // Collection.
     145        if(params.assignedPersons) p.assignedPersons = params.assignedPersons // Collection.
     146
     147        // trash: A new subTask must always have trash=false, which is already the domain class default.
     148
     149        // These would be considered copying, hence not done.
     150        // taskRecurringSchedule, entries, taskModifications, subTasks, inventoryMovements.
     151
     152        // Create the sub task and return the result.
    138153        result = create(p)
    139154
Note: See TracChangeset for help on using the changeset viewer.