import org.hibernate.criterion.Restrictions import org.springframework.beans.factory.InitializingBean import grails.converters.* class VideoDataSetController implements InitializingBean { def ext = ( System.properties["os.name"] == "Windows XP" ) ? ".exe" : "" def serverAddress = "localhost" def mapFile = "/data/bmng.map" def baseWMS def dataWMS def index = { redirect(action: list, params: params) } // the delete, save and update actions only accept POST requests def allowedMethods = [delete: 'POST', save: 'POST', update: 'POST'] def list = { if ( !params.max ) params.max = 10 def videoDataSetList = null if ( params.repositoryId ) { def repository = Repository.get(params.repositoryId) videoDataSetList = VideoDataSet.createCriteria().list(params) { eq("repository", repository) } } else { videoDataSetList = VideoDataSet.createCriteria().list(params) {} } [ videoDataSetList: videoDataSetList ] /* withFormat { html { [ videoDataSetList: videoDataSetList ] } xml { render videoDataSetList as XML } json { render videoDataSetList as JSON } } */ } def show = { def videoDataSet = VideoDataSet.get(params.id) if ( !videoDataSet ) { flash.message = "VideoDataSet not found with id ${params.id}" redirect(action: list) } else { return [videoDataSet: videoDataSet] } } def delete = { def videoDataSet = VideoDataSet.get(params.id) if ( videoDataSet ) { videoDataSet.delete() flash.message = "VideoDataSet ${params.id} deleted" redirect(action: list) } else { flash.message = "VideoDataSet not found with id ${params.id}" redirect(action: list) } } def edit = { def videoDataSet = VideoDataSet.get(params.id) if ( !videoDataSet ) { flash.message = "VideoDataSet not found with id ${params.id}" redirect(action: list) } else { return [videoDataSet: videoDataSet] } } def update = { def videoDataSet = VideoDataSet.get(params.id) if ( videoDataSet ) { videoDataSet.properties = params if ( !videoDataSet.hasErrors() && videoDataSet.save() ) { flash.message = "VideoDataSet ${params.id} updated" redirect(action: show, id: videoDataSet.id) } else { render(view: 'edit', model: [videoDataSet: videoDataSet]) } } else { flash.message = "VideoDataSet not found with id ${params.id}" redirect(action: edit, id: params.id) } } def create = { def videoDataSet = new VideoDataSet() videoDataSet.properties = params return ['videoDataSet': videoDataSet] } def save = { def videoDataSet = new VideoDataSet(params) if ( !videoDataSet.hasErrors() && videoDataSet.save() ) { flash.message = "VideoDataSet ${videoDataSet.id} created" redirect(action: show, id: videoDataSet.id) } else { render(view: 'create', model: [videoDataSet: videoDataSet]) } } def search = { def queryParams = new VideoDataSetQuery() println params bindData(queryParams, params) if ( request.method == 'POST' ) { if ( !params.max ) params.max = 10 def videoDataSets = runQuery(queryParams, params) chain(action: results, model: [videoDataSets: videoDataSets], params: params) } else return [queryParams: queryParams, baseWMS: baseWMS, dataWMS: dataWMS, sidebar:"videoSearch"] } def results = { if ( !params.max ) params.max = 10 def videoDataSets = null def queryParams = new VideoDataSetQuery() bindData(queryParams, params) if ( chainModel ) { videoDataSets = chainModel.videoDataSets } else { videoDataSets = runQuery(queryParams, params) } render(view: 'results', model: [videoDataSets: videoDataSets, queryParams: queryParams]) } def runQuery(def queryParams, def params) { def intersects = null if ( queryParams.aoiMaxLat && queryParams.aoiMinLon && queryParams.aoiMinLat && queryParams.aoiMaxLon ) { def srs = "4326" def wkt = Geometry.createPolygon( queryParams.aoiMinLon, queryParams.aoiMinLat, queryParams.aoiMaxLon, queryParams.aoiMaxLat ) def bounds = Geometry.fromString("SRID=${srs};${wkt}") intersects = new IntersectsExpression("groundGeom", bounds) } def range = null // Change the time portion of the end date // to be the end of the day. 23:59:59.999 if ( queryParams.endDate ) { def cal = Calendar.instance cal.time = queryParams.endDate cal.set(Calendar.HOUR, 23) cal.set(Calendar.MINUTE, 59) cal.set(Calendar.SECOND, 59) cal.set(Calendar.MILLISECOND, 999) queryParams.endDate = cal.time } if ( queryParams.startDate && queryParams.endDate ) { range = Restrictions.or( Restrictions.between("startDate", queryParams.startDate, queryParams.endDate), Restrictions.between("endDate", queryParams.startDate, queryParams.endDate) ) } else if ( queryParams.startDate ) { range = Restrictions.ge("endDate", queryParams.startDate) } else if ( queryParams.endDate ) { range = Restrictions.le("startDate", queryParams.endDate) } def clause = null if ( intersects && range ) { clause = Restrictions.and(intersects, range) } else if ( intersects ) { clause = intersects } else if ( range ) { clause = range } def videos = VideoDataSet.createCriteria().list(params) { if ( clause ) addToCriteria(clause) } return videos } public void afterPropertiesSet() { baseWMS = grailsApplication.config.wms.base dataWMS = grailsApplication.config.wms.data.video } }