/** * Created by IntelliJ IDEA. * User: sbortman * Date: Jun 12, 2008 * Time: 1:48:33 PM * To change this template use File | Settings | File Templates. */ import java.text.SimpleDateFormat; import org.hibernate.criterion.Restrictions import org.hibernate.criterion.Criterion class RasterEntryQuery { def aoiMaxLat def aoiMinLon def aoiMinLat def aoiMaxLon Date startDate Date endDate def viewMaxLat def viewMinLon def viewMinLat def viewMaxLon SearchTag searchTag def searchTagValue def createClause() { IntersectsExpression intersects = createIntersection() Criterion 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 } private Criterion 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.between("acquisitionDate", startDate, endDate) } else if ( startDate ) { range = Restrictions.ge("acquisitionDate", startDate) } else if ( endDate ) { range = Restrictions.le("acquisitionDate", endDate) } return range } private IntersectsExpression 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 } 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, "searchTag.id":searchTag.id, searchTagValue:searchTagValue ] } }