Wednesday, October 16, 2013

Getting Started with OpenShift Spatial (part 4)

Our last steps involve coding up a domain and controller class and then deploying the resulting war to OpenShift.
grails create-domain-class GeoEvent
import com.vividsolutions.jts.geom.Geometry
import com.vividsolutions.jts.geom.GeometryFactory
import com.vividsolutions.jts.geom.Coordinate

class GeoEvent {

  String name
  String status 
  String type
  double lat
  double lon

  Geometry shape
  
  static constraints = {
    shape nullable: true
  }

  def beforeInsert( ) {
    if ( lat!=null && lon!=null ) {
      shape = ( new GeometryFactory( ) ).createPoint( new Coordinate( lon.value, lat.value ) )
    }
  }

}
We'll use a simple scaffold based controller...
class GeoEventController {

    static scaffold = true

}
Finally compile test and deploy to OpenShift.
grails>compile
grails>run-app
grails>prod war
In our OpenShift managed repo copy the war generated above into webapps/ROOT.war
git commit -a -m 'latest update!'
git push

No comments: