This commit is contained in:
mar committed 2015-01-28 12:44:39 +01:00
1 parent 0ec9584b80
commit a8370ef8c4
3 files changed
+37 -15

No files matched your search

@@ -30,13 +30,15 @@ public class GisController {
@RequestMapping(APIServicePaths.GET_ALL_LAMPS)
@ResponseBody
List<GisPoint> getPoints() {
List<GisPoint> getPoints() throws Exception {
List<GisPoint> points = gisDbApi.getAllLamps();
for (int i = 0; i < points.size(); i++) {
long id = points.get(i).getId();
Location location = objectDbApi.getObject(id);
points.get(i).setDescription(location.getDescription());
List<Location> location = objectDbApi.getObject(id);
if(location.size()==0) throw new Exception("No object for given id found! id:" + id);
points.get(i).setDescription(location.get(0).getDescription());
}
return points;
}
@@ -44,32 +46,46 @@ public class GisController {
@RequestMapping(value = APIServicePaths.GET_LAMP + "/{id}")
@ResponseBody
Location getPoint(@PathVariable("id") Long id) throws Exception {
Location location = objectDbApi.getObject(id);
List<Location> location = objectDbApi.getObject(id);
List<GisPoint> points = gisDbApi.getLamp(id);
if(location.size() == 0) throw new Exception("No object for given id found! id:" + id);
if (points.size() == 0) throw new Exception("No point found id: " + id);
GisPoint p = points.get(0);
location.setY(p.getY());
location.setX(p.getX());
return location;
location.get(0).setY(p.getY());
location.get(0).setX(p.getX());
return location.get(0);
}
@RequestMapping(value = APIServicePaths.GET_POLYGON + "/{id}")
@ResponseBody
List<Point> getPolygon(@PathVariable("id") long id) {
return gisDbApi.getPolygon(id);
Poly getPolygon(@PathVariable("id") long id) throws Exception {
List<Location> location = objectDbApi.getObject(id);
if(location.size()==0) throw new Exception("No object for given id found! id:" + id);
List<Point> list = gisDbApi.getPolygon(id);
Poly pol = new Poly();
pol.setDescription(location.get(0).getDescription());
pol.setPolygon(list);
return pol;
}
@RequestMapping(value = APIServicePaths.GET_POLYGON)
@ResponseBody
List<Polygon> getPolygons() {
return gisDbApi.getPolygons();
List<Polygon> getPolygons() throws Exception {
List<Polygon> list = gisDbApi.getPolygons();
for(int i=0;i<list.size();i++){
List<Location> location = objectDbApi.getObject(list.get(i).getId());
if(location.size()==0) throw new Exception("No object for given id found! id:" + list.get(i).getId());
list.get(i).setDescription(location.get(0).getDescription());
}
return list;
}
@RequestMapping(value = APIServicePaths.PUT_POLYGON, method = RequestMethod.PUT)
@ResponseBody
int putPolygons(@RequestBody Poly polygon) {
long putPolygons(@RequestBody Poly polygon) {
long id = objectDbApi.putObject(polygon.getDescription());
return gisDbApi.putPolygon(id,polygon.getPolygon());
gisDbApi.putPolygon(id,polygon.getPolygon());
return id;
}
@RequestMapping(value = APIServicePaths.PUT_LAMP, method = RequestMethod.PUT)
@@ -83,12 +99,14 @@ public class GisController {
@RequestMapping(value = APIServicePaths.DELETE_LAMP + "/{id}", method = RequestMethod.DELETE)
@ResponseBody
int deletePoint(@PathVariable("id") Long id) {
objectDbApi.deleteObject(id);
return gisDbApi.deleteLamp(id);
}
@RequestMapping(value = APIServicePaths.DELETE_POLYGON + "/{id}", method = RequestMethod.DELETE)
@ResponseBody
int deletePolygon(@PathVariable("id") Long id) {
gisDbApi.deletePolygon(id);
return objectDbApi.deleteObject(id);
}
@@ -29,6 +29,7 @@ public class GisDbApi {
private static final String GET_POLYGON = "SELECT st_transform(way,4326) as polygon FROM gis_polygons WHERE gis_polygons_id = ?";
private static final String PUT_POLYGON = "INSERT INTO public.gis_polygons(gis_polygons_id, way, highway) VALUES (?, (SELECT ST_MakePolygon(ST_AddPoint(foo.open_line, ST_StartPoint(foo.open_line))) FROM (SELECT ST_GeomFromText(?, '4326') AS open_line) AS foo), 'sensor')";
private static final String LINESTRING = "LINESTRING(@)";
private static final String DELETE_POLYGON = "DELETE FROM public.gis_polygons WHERE gis_polygons_id = ?";
JdbcTemplate gisJdbcTemplate;
public GisDbApi() {
@@ -83,6 +84,9 @@ public class GisDbApi {
return gisJdbcTemplate.update(PUT_POLYGON, id,function);
}
public int deletePolygon(long id){
return gisJdbcTemplate.update(DELETE_POLYGON,id);
}
public void setGisJdbcTemplate(JdbcTemplate gisJdbcTemplate) {
this.gisJdbcTemplate = gisJdbcTemplate;
}
@@ -49,8 +49,8 @@ public class ObjectDbApi {
return keyHolder.getKey().longValue();
}
public Location getObject(long id) {
return objectJdbcTemplate.query(GET_LOCATION, new Object[]{id}, new PointRowMapper()).get(0);
public List<Location> getObject(long id) {
return objectJdbcTemplate.query(GET_LOCATION, new Object[]{id}, new PointRowMapper());
}
public int deleteObject(long id){