Changeset 445 for trunk/grails-app/services
- Timestamp:
 - Mar 16, 2010, 5:18:20 PM (16 years ago)
 - File:
 - 
          
- 1 edited
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
        
trunk/grails-app/services/TaskRecurringScheduleService.groovy
r434 r445 15 15 def generateAll() { 16 16 17 def taskRecurringScheduleList = TaskRecurringSchedule.findAllByEnabled(true)18 19 17 // Prevent errors if base data has not yet been created. 20 18 if(!appConfigService.exists("baseDataCreated")) { … … 26 24 } 27 25 28 taskRecurringScheduleList.each() { 26 def p = [:] 27 def targetCompletionDate 28 def nextTargetCompletionDate 29 def tomorrow = dateUtilService.tomorrow 30 31 def taskRecurringScheduleList = TaskRecurringSchedule.findAllByEnabled(true) 32 33 // Stop generation if max reached. 34 def maxSubTasksReached = { 35 if( (it.maxSubTasks > 0) && (it.subTasksGenerated >= it.maxSubTasks) ) { 36 it.enabled = false 37 return true 38 } 39 return false 40 } 41 42 // Stop generation by targetCompletionDate. 43 def targetCompletionDateReached = { 44 if( it.useTargetCompletionDate) { 45 targetCompletionDate = dateUtilService.getMidnight(it.task.targetCompletionDate) 46 nextTargetCompletionDate = dateUtilService.getMidnight(it.nextTargetCompletionDate) 47 if(nextTargetCompletionDate > targetCompletionDate) { 48 it.enabled = false 49 return true 50 } 51 } 52 return false 53 } 54 55 // Main loop. 56 for(it in taskRecurringScheduleList) { 57 58 if(maxSubTasksReached(it)) 59 continue 60 61 if(targetCompletionDateReached(it)) 62 continue 29 63 30 64 if (dateUtilService.tomorrow > it.nextGenerationDate) { 31 defp = [:]65 p = [:] 32 66 33 // Build the requiredparams.34 p.targetStartDate = it.nextTargetStartDate35 p.targetCompletionDate = it.nextTargetCompletionDate36 if(it.task.taskProcedure) p.taskProcedure = it.task.taskProcedure37 if(it.task.assignedGroups) p.assignedGroups = new ArrayList(it.task.assignedGroups)38 if(it.task.assignedPersons) p.assignedPersons = new ArrayList(it.task.assignedPersons)67 // Build the subTask params. 68 p.targetStartDate = it.nextTargetStartDate 69 p.targetCompletionDate = it.nextTargetCompletionDate 70 if(it.task.taskProcedure) p.taskProcedure = it.task.taskProcedure 71 if(it.task.assignedGroups) p.assignedGroups = new ArrayList(it.task.assignedGroups) 72 if(it.task.assignedPersons) p.assignedPersons = new ArrayList(it.task.assignedPersons) 39 73 40 def result = taskService.createSubTask(it.task, p)41 if( !result.error ) {42 it.lastGeneratedSubTask = result.taskInstance43 it.subTasksGenerated++44 it.setNextTargetStartDate()45 it.setNextGenerationDate()46 it.setNextTargetCompletionDate()47 }48 else {49 log.error "Sub task generation for recurring schedule ${it.id} failed."50 log.error result.taskInstance.errors51 }74 def result = taskService.createSubTask(it.task, p) 75 if( !result.error ) { 76 it.lastGeneratedSubTask = result.taskInstance 77 it.subTasksGenerated++ 78 it.setNextTargetStartDate() 79 it.setNextGenerationDate() 80 it.setNextTargetCompletionDate() 81 } 82 else { 83 log.error "Sub task generation for recurring schedule ${it.id} failed." 84 log.error result.taskInstance.errors 85 } 52 86 } 53 87 54 } 55 } 88 // Run the completion reached checks for a second time so 89 // that this recurring schedule does not run again if 90 // there are no more subTasks to be generated. 91 if(maxSubTasksReached(it)) 92 continue 93 94 if(targetCompletionDateReached(it)) 95 continue 96 97 } // for() 98 } // generateAll() 56 99 57 100 /**  
Note: See TracChangeset
          for help on using the changeset viewer.
      