poprawki
This commit is contained in:
1 parent
166b795b7c
commit
9eb8f56961
8 files changed
+107
-18
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package hello;
|
||||
|
||||
import hello.agh.edu.bazy.interceptor.RequestInterceptor;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -34,9 +35,9 @@ public class Application extends WebMvcConfigurerAdapter implements CommandLineR
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
//TODO INTERCEPTORS DO NOT FIRE ON PATHS
|
||||
// TODO only /** works
|
||||
// registry.addInterceptor(new RequestInterceptor("GIS_CRUD")).addPathPatterns("/gis/*/*", "/gis/*");
|
||||
registry.addInterceptor(new RequestInterceptor("GIS_CRUD")).addPathPatterns("/gis/*/*", "/gis/*");
|
||||
// registry.addInterceptor(new RequestInterceptor("OBJECTS_CRUD")).addPathPatterns("/objects**");
|
||||
// registry.addInterceptor(new RequestInterceptor("SENSORS_CRUD")).addPathPatterns("/sensors*/*", "/sensors/*");
|
||||
registry.addInterceptor(new RequestInterceptor("SENSORS_CRUD")).addPathPatterns("/sensors/*/*", "/sensors/*");
|
||||
// registry.addInterceptor(new RequestInterceptor("REQUIREMENTS_CRUD")).addPathPatterns("/requirements**");
|
||||
// registry.addInterceptor(new RequestInterceptor("RULES_CRUD")).addPathPatterns("/rules**");
|
||||
// registry.addInterceptor(new RequestInterceptor("PROFILES_CRUD")).addPathPatterns("/profiles**");
|
||||
|
||||
@@ -4,6 +4,7 @@ import hello.agh.edu.bazy.path.APIServicePaths;
|
||||
import hello.agh.edu.bazy.dbApi.gis.GisdbApi;
|
||||
import hello.agh.edu.bazy.model.Location;
|
||||
import hello.agh.edu.bazy.row.gis.GisLamp;
|
||||
import hello.agh.edu.bazy.row.gis.GisPoint;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -29,9 +30,8 @@ public class GisController {
|
||||
|
||||
@RequestMapping(value = APIServicePaths.GET_LAMP + "/{id}")
|
||||
@ResponseBody
|
||||
List<?> getLamp(@PathVariable("id") Long id) {
|
||||
return gisdbApi.getLampCoordinates(id) != null ?
|
||||
gisdbApi.getLampCoordinates(id) : Collections.emptyList();
|
||||
List<GisPoint> getLamp(@PathVariable("id") Long id) {
|
||||
return gisdbApi.getLamp(id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = APIServicePaths.PUT_LAMP + "/{id}", method = RequestMethod.PUT)
|
||||
@@ -39,4 +39,11 @@ public class GisController {
|
||||
int putLamp(@RequestBody Location location, @PathVariable("id") Long id) {
|
||||
return gisdbApi.putLamp(id, location.getX(), location.getY());
|
||||
}
|
||||
|
||||
@RequestMapping(value = APIServicePaths.DELETE_LAMP + "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
int deleteLamp(@PathVariable("id") Long id) {
|
||||
return gisdbApi.deleteLamp(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package hello.agh.edu.bazy.dbApi.gis;
|
||||
import hello.agh.edu.bazy.postgresql.gis.GisDataSource;
|
||||
import hello.agh.edu.bazy.row.gis.GisLamp;
|
||||
import hello.agh.edu.bazy.row.gis.GisPoint;
|
||||
import hello.agh.edu.bazy.row.mappers.gis.GisRowMapperForLamps;
|
||||
import hello.agh.edu.bazy.row.mappers.GisRowMapperForLamps;
|
||||
import hello.agh.edu.bazy.row.mappers.gis.PointRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -16,9 +16,10 @@ import java.util.List;
|
||||
@Component
|
||||
public class GisdbApi {
|
||||
|
||||
private static final String GET_ALL_LAMPS_COORDINATES = "SELECT osm_id,st_transform(way,4326) FROM planet_osm_point WHERE highway='street_lamp'";
|
||||
private static final String GET_LAMP = "SELECT osm_id,tags,st_transform(way,4326) FROM planet_osm_point WHERE highway='street_lamp'";
|
||||
private static String PUT_LAMP = "INSERT INTO public.gis_points(gis_points_id, way, highway) VALUES (@, st_geomfromtext('POINT(@ @)',4326), 'street_lamp');";
|
||||
private static final String GET_POINT_COORDINATES = "SELECT st_transform(way,900913) FROM gis_points WHERE gis_points_id = ?;";
|
||||
private static final String GET_LAMPS = "SELECT st_transform(way,900913) FROM gis_points WHERE gis_points_id = ?;";
|
||||
private static final String DELETE_LAMP = "DELETE FROM public.gis_points WHERE gis_points_id = ?";
|
||||
|
||||
JdbcTemplate gisJdbcTemplate;
|
||||
|
||||
@@ -33,12 +34,16 @@ public class GisdbApi {
|
||||
gisJdbcTemplate = template;
|
||||
}
|
||||
|
||||
public List<GisLamp> getAllLamps() {
|
||||
return gisJdbcTemplate.query(GET_ALL_LAMPS_COORDINATES, new GisRowMapperForLamps());
|
||||
public int deleteLamp(long id) {
|
||||
return gisJdbcTemplate.update(DELETE_LAMP, id);
|
||||
}
|
||||
|
||||
public List<GisPoint> getLampCoordinates(long id) {
|
||||
return gisJdbcTemplate.query(GET_POINT_COORDINATES, new Object[]{id}, new PointRowMapper());
|
||||
public List<GisLamp> getAllLamps() {
|
||||
return gisJdbcTemplate.query(GET_LAMP, new GisRowMapperForLamps());
|
||||
}
|
||||
|
||||
public List<GisPoint> getLamp(long id) {
|
||||
return gisJdbcTemplate.query(GET_LAMPS, new Object[]{id}, new PointRowMapper());
|
||||
}
|
||||
|
||||
public int putLamp(long id, double x, double y) {
|
||||
|
||||
@@ -20,9 +20,10 @@ public final class APIServicePaths {
|
||||
|
||||
//GIS
|
||||
public static final String GIS_CONTROLLER = "/gis";
|
||||
public static final String GET_ALL_LAMPS = "/getLamps";
|
||||
public static final String PUT_LAMP = "/putLamp";
|
||||
public static final String GET_LAMP = "/getLamp";
|
||||
public static final String GET_ALL_LAMPS = "/lamp";
|
||||
public static final String PUT_LAMP = "/lamp";
|
||||
public static final String DELETE_LAMP = "/lamp";
|
||||
public static final String GET_LAMP = "/lamp";
|
||||
|
||||
//SENSORS
|
||||
public static final String SENSORS_CONTROLLER = "/sensors";
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package hello.agh.edu.bazy.row;
|
||||
|
||||
import org.postgis.Point;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
||||
/**
|
||||
* Created by mar on 24.01.15.
|
||||
*/
|
||||
@XmlRootElement
|
||||
public class GisLamp {
|
||||
private final long id;
|
||||
private final Point location;
|
||||
private String tag;
|
||||
|
||||
public GisLamp(long id, Point location) {
|
||||
this.id = id;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Point getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public class GisLamp {
|
||||
private final long id;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private String tag;
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
@@ -22,8 +23,18 @@ public class GisLamp {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public GisLamp(long id, double x, double y, String tag) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package hello.agh.edu.bazy.row.mappers;
|
||||
|
||||
import hello.agh.edu.bazy.row.GisLamp;
|
||||
import org.postgis.PGgeometry;
|
||||
import org.postgis.Point;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by mar on 24.01.15.
|
||||
*/
|
||||
public class GisRowMapperForLamp implements RowMapper<GisLamp> {
|
||||
|
||||
private static final String COORDINATE_COLUM_NNAME = "st_transform";
|
||||
private static final String OSM_ID = "osm_id";
|
||||
private static final String TAG ="tag" ;
|
||||
|
||||
@Override
|
||||
public GisLamp mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
PGgeometry geometry = (PGgeometry)rs.getObject(COORDINATE_COLUM_NNAME);
|
||||
GisLamp lamp = new GisLamp(rs.getLong(OSM_ID),(Point) geometry.getGeometry());
|
||||
lamp.setTag(rs.getString(TAG));
|
||||
return lamp;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package hello.agh.edu.bazy.row.mappers.gis;
|
||||
package hello.agh.edu.bazy.row.mappers;
|
||||
|
||||
import hello.agh.edu.bazy.row.gis.GisLamp;
|
||||
import org.postgis.PGgeometry;
|
||||
@@ -14,13 +14,13 @@ public class GisRowMapperForLamps implements RowMapper<GisLamp> {
|
||||
|
||||
private static final String COORDINATE_COLUM_NNAME = "st_transform";
|
||||
private static final String OSM_ID = "osm_id";
|
||||
|
||||
private static final String TAG = "tags";
|
||||
@Override
|
||||
public GisLamp mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
PGgeometry geometry = (PGgeometry)rs.getObject(COORDINATE_COLUM_NNAME);
|
||||
|
||||
return new GisLamp(rs.getLong(OSM_ID),
|
||||
((Point) geometry.getGeometry()).getX(),
|
||||
((Point) geometry.getGeometry()).getY());
|
||||
((Point) geometry.getGeometry()).getY(),rs.getString(TAG));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user