Guest User

Untitled

a guest
May 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1.  
  2. SearchResults searchAvailableActivities(SearchCriteria criteria) {
  3. log.debug "Search service search with criteria: $criteria"
  4.  
  5. DateTime startTime = criteria.startTime
  6. DateTime endTime = startTime.plusHours(24)
  7. def c = Activity.createCriteria()
  8.  
  9.  
  10.  
  11. log.debug "Search service startTime:$startTime endTime:$endTime"
  12.  
  13. def results = c.list {
  14. and {
  15.  
  16. if (criteria.type) {
  17. log.debug "Adding activity type to search. typeName: ${criteria.type.typeName}"
  18. activityType {
  19. eq("typeName", criteria.type.typeName)
  20. }
  21. }
  22. availabilities {
  23. //To qualify as a valid result the startDate must be less than or equal to the time being searched
  24. // and the endDate must not have already passed
  25. le('startDate', startTime.millis)
  26. ge('endDate', endTime.millis)
  27.  
  28. }
  29.  
  30. }
  31. }
  32.  
  33. List<SearchResult> resultList = new ArrayList<SearchResult>()
  34.  
  35.  
  36. if (results) {
  37. results.each {activity ->
  38. log.debug "Results found"
  39. def availabilities = activity.availabilities
  40. availabilities.each {
  41.  
  42. def retValue = it.isAvailable(startTime, criteria.numberOfParticipants)
  43. if (retValue) {
  44. log.debug "Adding search result for $activity.activityName"
  45. SearchResult aResult = new SearchResult()
  46. resultList.add(aResult)
  47. }
  48. }
  49.  
  50.  
  51. }
  52. }
  53.  
  54. return new SearchResults(results: resultList)
  55.  
  56.  
  57. }
Add Comment
Please, Sign In to add comment