Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SearchResults searchAvailableActivities(SearchCriteria criteria) {
- log.debug "Search service search with criteria: $criteria"
- DateTime startTime = criteria.startTime
- DateTime endTime = startTime.plusHours(24)
- def c = Activity.createCriteria()
- log.debug "Search service startTime:$startTime endTime:$endTime"
- def results = c.list {
- and {
- if (criteria.type) {
- log.debug "Adding activity type to search. typeName: ${criteria.type.typeName}"
- activityType {
- eq("typeName", criteria.type.typeName)
- }
- }
- availabilities {
- //To qualify as a valid result the startDate must be less than or equal to the time being searched
- // and the endDate must not have already passed
- le('startDate', startTime.millis)
- ge('endDate', endTime.millis)
- }
- }
- }
- List<SearchResult> resultList = new ArrayList<SearchResult>()
- if (results) {
- results.each {activity ->
- log.debug "Results found"
- def availabilities = activity.availabilities
- availabilities.each {
- def retValue = it.isAvailable(startTime, criteria.numberOfParticipants)
- if (retValue) {
- log.debug "Adding search result for $activity.activityName"
- SearchResult aResult = new SearchResult()
- resultList.add(aResult)
- }
- }
- }
- }
- return new SearchResults(results: resultList)
- }
Add Comment
Please, Sign In to add comment