- Timestamp:
- Apr 28, 2010, 11:14:56 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/TaskSearchService.groovy
r511 r512 157 157 */ 158 158 def getTasks(params, startDate=null, endDate=null) { 159 params.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 160 params.offset = params?.offset?.toInteger() ?: 0 161 params.sort = params?.sort ?: "attentionFlag" 162 params.order = params?.order ?: "desc" 163 164 startDate = startDate ?: dateUtilService.today 165 endDate = endDate ?: dateUtilService.tomorrow 166 167 def taskInstanceList = Task.createCriteria().list( 168 max: params.max, 169 offset: params.offset, 170 sort: params.sort, 171 order: params.order) { 172 lt("targetStartDate", endDate) 173 ge("targetCompletionDate", startDate) 174 eq("trash", false) 175 } // createCriteria 176 } // getTasks() 159 def paginateParams = [:] 160 paginateParams.max = Math.min(params?.max?.toInteger() ?: 10, paramsMax) 161 paginateParams.offset = params?.offset?.toInteger() ?: 0 162 163 def sort = "task." + (params?.sort ?: "attentionFlag") 164 def order = params?.order == "asc" ? "asc" : "desc" 165 def orderBy = " order by " + sort + ' ' + order 166 167 def namedParams = [:] 168 namedParams.startDate = startDate ?: dateUtilService.today 169 namedParams.endDate = endDate ?: dateUtilService.tomorrow 170 171 def baseQuery = "from Task as task \ 172 where (task.trash = false \ 173 and task.targetStartDate < :endDate \ 174 and task.targetCompletionDate >= :startDate \ 175 )" 176 177 def searchQuery = "select distinct task " + baseQuery + orderBy 178 def list = Task.executeQuery(searchQuery, namedParams, paginateParams) 179 180 def countQuery = "select count(distinct task) as taskCount " + baseQuery 181 def totalCount = Task.executeQuery(countQuery, namedParams)[0].toInteger() 182 183 def taskInstanceList = new PagedResultList(list, totalCount) 184 return taskInstanceList 185 } // getPTasks() 177 186 178 187 /** -
trunk/test/integration/TaskSearchServiceTests.groovy
r511 r512 70 70 71 71 // Tasks in the trash should not be returned. 72 task s[0].trash = true73 task s[0].save(flush:true)72 taskA.trash = true 73 taskA.save(flush:true) 74 74 assert taskSearchService.getTasks([:]).totalCount == taskCount - 1 75 task s[1].trash = true76 task s[1].save(flush:true)75 taskB.trash = true 76 taskB.save(flush:true) 77 77 assert taskSearchService.getTasks([:]).totalCount == taskCount - 2 78 78 79 79 // Restored tasks should be returned. 80 task s[0].trash = false81 task s[0].save(flush:true)80 taskA.trash = false 81 taskA.save(flush:true) 82 82 assert taskSearchService.getTasks([:]).totalCount == taskCount - 1 83 task s[1].trash = false84 task s[1].save(flush:true)83 taskB.trash = false 84 taskB.save(flush:true) 85 85 assert taskSearchService.getTasks([:]).totalCount == taskCount 86 86 87 87 // Tomorrows tasks should not be returned. 88 task s[0].targetStartDate = dateUtilService.tomorrow89 task s[0].targetCompletionDate = dateUtilService.tomorrow90 task s[0].save(flush:true)88 taskA.targetStartDate = dateUtilService.tomorrow 89 taskA.targetCompletionDate = dateUtilService.tomorrow 90 taskA.save(flush:true) 91 91 assert taskSearchService.getTasks([:]).totalCount == taskCount - 1 92 92 93 // Tomorrows tasks should be returned, if we ask for them. 94 assert taskSearchService.getTasks([:], dateUtilService.today, dateUtilService.tomorrow+1).totalCount == taskCount 95 93 96 // Yesterdays tasks should not be returned. 94 task s[0].targetStartDate = dateUtilService.yesterday95 task s[0].targetCompletionDate = dateUtilService.yesterday96 task s[0].save(flush:true)97 taskA.targetStartDate = dateUtilService.yesterday 98 taskA.targetCompletionDate = dateUtilService.yesterday 99 taskA.save(flush:true) 97 100 assert taskSearchService.getTasks([:]).totalCount == taskCount - 1 98 101 102 // Yesterdays tasks should be returned, if we ask for them. 103 assert taskSearchService.getTasks([:], dateUtilService.yesterday, dateUtilService.tomorrow).totalCount == taskCount 104 99 105 // Tasks that span today should be returned. 100 task s[0].targetStartDate = dateUtilService.yesterday101 task s[0].targetCompletionDate = dateUtilService.tomorrow102 task s[0].save(flush:true)106 taskA.targetStartDate = dateUtilService.yesterday 107 taskA.targetCompletionDate = dateUtilService.tomorrow 108 taskA.save(flush:true) 103 109 assert taskSearchService.getTasks([:]).totalCount == taskCount 104 110 } // testGetTasks()
Note: See TracChangeset
for help on using the changeset viewer.