import java.text.SimpleDateFormat import org.hibernate.criterion.Restrictions /** * Created by IntelliJ IDEA. * User: sbortman * Date: Jun 25, 2008 * Time: 11:13:19 AM * To change this template use File | Settings | File Templates. */ class VideoDataSetQuery { def aoiMaxLat def aoiMinLon def aoiMinLat def aoiMaxLon Date startDate Date endDate def viewMaxLat def viewMinLon def viewMinLat def viewMaxLon private def createIntersection() { def intersects = null if ( aoiMaxLat && aoiMinLon && aoiMinLat && aoiMaxLon ) { def srs = "4326" def wkt = Geometry.createPolygon( aoiMinLon, aoiMinLat, aoiMaxLon, aoiMaxLat ) def bounds = Geometry.fromString("SRID=${srs};${wkt}") intersects = new IntersectsExpression("groundGeom", bounds) } return intersects } private def createDateRange() { def range = null // Change the time portion of the end date // to be the end of the day. 23:59:59.999 if ( endDate ) { def cal = Calendar.instance cal.time = endDate cal.set(Calendar.HOUR, 23) cal.set(Calendar.MINUTE, 59) cal.set(Calendar.SECOND, 59) cal.set(Calendar.MILLISECOND, 999) endDate = cal.time } if ( startDate && endDate ) { range = Restrictions.or( Restrictions.between("startDate", startDate, endDate), Restrictions.between("endDate", startDate, endDate) ) } else { if ( startDate ) { range = Restrictions.ge("endDate", startDate) } else if ( endDate ) { range = Restrictions.le("startDate", endDate) } } return range } public def createClause() { def intersects = createIntersection() def range = createDateRange() def clause = null if ( intersects && range ) { clause = Restrictions.and(intersects, range) } else { if ( intersects ) { clause = intersects } else if ( range ) { clause = range } } return clause } def toMap() { SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); String startDateText = (startDate) ? formatter.format(startDate) : ""; String endDateText = (endDate) ? formatter.format(endDate) : ""; [ aoiMaxLat: aoiMaxLat, aoiMinLon: aoiMinLon, aoiMinLat: aoiMinLat, aoiMaxLon: aoiMaxLon, startDate: startDateText, endDate: endDateText, viewMaxLat: viewMaxLat, viewMinLon: viewMinLon, viewMinLat: viewMinLat, viewMaxLon: viewMaxLon ] } }