Ignore:
Timestamp:
Sep 1, 2009, 10:10:43 PM (15 years ago)
Author:
gav
Message:

Update to grails-1.1.1 release.
Fix WorkDone? and Fault entries not showing after update, now using criteria.
Work on TaskRecurringSchedule, add DateUtilService class, regenerate views to suite.
Finally have correct rollback behaviour on TaskRecurringSchedule? domain object updates by using transactions.
Added name to copyright since the license has no meaning without it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/TaskRecurringScheduleDetailedController.groovy

    r136 r137  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
    22import org.codehaus.groovy.runtime.TimeCategory
     3import java.text.SimpleDateFormat
    34
    45class TaskRecurringScheduleDetailedController extends BaseController {
    56   
     7        def dateUtilService
     8       
    69    def index = { redirect(action:list,params:params) }
    710
     
    5154        }
    5255        else {
    53             return [ taskRecurringScheduleInstance : taskRecurringScheduleInstance ]
     56            return [ taskRecurringScheduleInstance : taskRecurringScheduleInstance]
    5457        }
    5558    }
    5659
    5760    def update = {
    58         def taskRecurringScheduleInstance = TaskRecurringSchedule.get( params.id )
    59         if(taskRecurringScheduleInstance) {
    60             if(params.version) {
    61                 def version = params.version.toLong()
    62                 if(taskRecurringScheduleInstance.version > version) {
     61                TaskRecurringSchedule.withTransaction { status ->
     62       
     63                def taskRecurringScheduleInstance = TaskRecurringSchedule.get( params.id )
     64                        if(taskRecurringScheduleInstance) {
     65                               
     66                                if(params.version) {
     67                                        def version = params.version.toLong()
     68                                        if(taskRecurringScheduleInstance.version > version) {
     69                                                taskRecurringScheduleInstance.errors.rejectValue("version", "taskRecurringSchedule.optimistic.locking.failure", "Another user has updated this TaskRecurringSchedule while you were editing.")
     70                                                render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
     71                                                return
     72                                        }
     73                                }
     74                                       
     75                                Date originalDate = taskRecurringScheduleInstance.startDate
     76                                taskRecurringScheduleInstance.properties = params  // Domain object is now 'dirty'.
     77                                Date newDate = taskRecurringScheduleInstance.startDate
     78       
     79                                // If user changes startDate then ensure it is in the future, otherwise it's ok to keep the original date.
     80                                if(originalDate.getTime() != newDate.getTime())
     81                                {
     82                                        if(newDate < dateUtilService.getToday())
     83                                        {
     84                                                status.setRollbackOnly()  // Only allow the transaction to Rollback, preventing flush due to 'dirty'.
     85                                                taskRecurringScheduleInstance.errors.rejectValue("startDate", "taskRecurring.startDate.NotInTheFuture")
     86                                                render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
     87                                                return
     88                                        }
     89                                }
     90                                       
     91                                taskRecurringScheduleInstance.nextTargetStartDate = taskRecurringScheduleInstance.startDate
     92                                taskRecurringScheduleInstance.setNextGenerationDate()
     93                                taskRecurringScheduleInstance.setNextTargetCompletionDate()
    6394                   
    64                     taskRecurringScheduleInstance.errors.rejectValue("version", "taskRecurringSchedule.optimistic.locking.failure", "Another user has updated this TaskRecurringSchedule while you were editing.")
    65                     render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
    66                     return
    67                 }
    68             }
    69 //             taskRecurringScheduleInstance.properties = params
    70             setUpdateProperties()
    71                    
    72             if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save()) {
    73                 flash.message = "TaskRecurringSchedule ${params.id} updated"
    74                 redirect(action:show,id:taskRecurringScheduleInstance.id)
    75             }
    76             else {
    77                 render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
    78             }
    79         }
    80         else {
    81             flash.message = "TaskRecurringSchedule not found with id ${params.id}"
    82             redirect(action:edit,id:params.id)
    83         }
    84     }
     95                                if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save())
     96                                {
     97                                        flash.message = "TaskRecurringSchedule ${params.id} updated"
     98                                        redirect(action:show,id:taskRecurringScheduleInstance.id)
     99                                }
     100                                else
     101                                {
     102                                        render(view:'edit',model:[taskRecurringScheduleInstance:taskRecurringScheduleInstance])
     103                                }
     104                        }
     105                        else
     106                        {
     107                                flash.message = "TaskRecurringSchedule not found with id ${params.id}"
     108                                redirect(action:edit,id:params.id)
     109                        }
     110                       
     111                } // end withTransaction                       
     112        } // end update()
    85113       
    86114    def create = {
     
    95123            redirect(controller:"taskDetailed", action:"list")
    96124        }
    97     }
     125    } // end create()
    98126
    99127    def save = {
     
    106134                }
    107135                else {
     136                       
     137                        if(taskRecurringScheduleInstance.startDate < dateUtilService.getToday()) {
     138                                taskRecurringScheduleInstance.errors.rejectValue("startDate", "taskRecurring.startDate.NotInTheFuture")
     139                        }
    108140                       
    109141                        if(!taskRecurringScheduleInstance.hasErrors() && taskRecurringScheduleInstance.save()) {
     
    125157                }
    126158
    127     }
    128                
    129     private setUpdateProperties() {
    130         def originalStartDate = taskRecurringScheduleInstance.startDate
    131        
    132         if(taskRecurringScheduleInstance.startDate == params.startDate) {
    133             taskRecurringScheduleInstance.properties = params
    134         }
    135         else {
    136             taskRecurringScheduleInstance.properties = params
    137             taskRecurringScheduleInstance.nextTargetStartDate = params.startDate
    138         }
    139        
    140     }
     159    } // end save()
    141160
    142 /*   
    143     private Date calculateNextDueDate(recurEvery, period, startDate) {
    144         def nextDue = new Date()
    145        
    146         switch (period) {
    147             case "Day(s)":
    148                 use(TimeCategory) {
    149                     nextDue = startDate + recurEvery.days
    150                 }
    151                 return nextDue
    152             case "Week(s)":
    153                 use(TimeCategory) {
    154                     nextDue = startDate + recurEvery.weeks
    155                 }
    156                 return nextDue
    157             case "Month(s)":
    158                 use(TimeCategory) {
    159                     nextDue = startDate + recurEvery.months
    160                 }
    161                 return nextDue
    162             case "Year(s)":
    163                 use(TimeCategory) {
    164                     nextDue = startDate + recurEvery.years
    165                 }
    166                 return nextDue
    167             default:
    168                 return nextDue
    169         }
    170        
    171     }*/
    172161}
Note: See TracChangeset for help on using the changeset viewer.