From d0976ab92139c7c74c06b8bcef29504099bd99df Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 May 2019 12:49:57 +0200 Subject: [PATCH 1/4] fixed valid lonitude, lattitude values --- .../labsw/bugageocaching/util/CacheConstructionUtil.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java index 6d7d887..5deb9c5 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java @@ -85,12 +85,12 @@ public class CacheConstructionUtil { return ResponseEntity.status(400).body("station fields can“t be empty"); } - if (station.getLattitude() < -90 || station.getLattitude() > 90) { - return ResponseEntity.status(400).body("Lattitude has to be between -90 and 90 Degree"); + if (station.getLattitude() < 9 || station.getLattitude() > 10) { + return ResponseEntity.status(400).body("Lattitude has to be between 9 and 10 degrees"); } - if (station.getLongitude() < -180 || station.getLongitude() > 180) { - return ResponseEntity.status(400).body("Longitude has to be in the range of -180 to 180 degrees"); + if (station.getLongitude() < 49 || station.getLongitude() > 50) { + return ResponseEntity.status(400).body("Longitude has to be in the range of 49 to 50 degrees"); } Random r = new Random(); From 8ba109427caf53c65ca8f699ffda6fcaa35d4a5b Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Mon, 13 May 2019 15:32:53 +0200 Subject: [PATCH 2/4] Added map api call for the last station you visited from a cache --- build.gradle | 7 ++ .../bugageocaching/controller/Controller.java | 80 ++++++++++++++++++- .../hhn/labsw/bugageocaching/helper/POI.java | 5 ++ 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 733231a..43d4fd1 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,13 @@ dependencies { // https://mvnrepository.com/artifact/com.mashape.unirest/unirest-java compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.3.1' + compile group: 'commons-collections', name: 'commons-collections', version: '3.2' + compile group: 'org.slf4j', name:'slf4j-api', version: '1.7.2' + compile group: 'ch.qos.logback', name:'logback-classic', version: '1.0.9' + compile group: 'ch.qos.logback', name:'logback-core', version: '1.0.9' + + testCompile group: 'junit', name: 'junit', version: '4.+' + } node { diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 2385965..d470edc 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -12,7 +12,10 @@ import io.jsonwebtoken.Claims; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -56,6 +59,8 @@ public class Controller { @Autowired TeamInviteRepository teamInviteRepository; + private static final Logger logger = LoggerFactory.getLogger(Controller.class); + @PostConstruct public void init(){ fetchPublicKey(); @@ -985,7 +990,7 @@ public class Controller { Cache cache = (Cache) getCache.getBody(); //---------------------- - return ResponseEntity.status(200).body(bearbeitetRepository.findByUserAndCache(user, cache)); + return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetRepository.findByUserAndCache(user, cache))); } @ApiOperation(value = "Returns the ranking place on the leaderboard for a specific user") @@ -1006,7 +1011,7 @@ public class Controller { @ApiResponse(code = 401, message = "JWT Token expired"), @ApiResponse(code = 400, message = "Something went wrong at verification") }) - @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose + @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose @RequestMapping(value = "/api/getMyStationPOIS", method = RequestMethod.GET, produces = "application/json") public ResponseEntity getMyStationPOIS(@RequestParam String token) { // verify user @@ -1072,7 +1077,7 @@ public class Controller { @ApiResponse(code = 401, message = "JWT Token expired"), @ApiResponse(code = 400, message = "Something went wrong at verification") }) - @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose + @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose @RequestMapping(value = "/api/getTeamOfUser", method = RequestMethod.GET, produces = "application/json") public ResponseEntity getTeamOfUser(@RequestParam String token) { @@ -1099,6 +1104,75 @@ public class Controller { return ResponseEntity.status(200).body(user_info.getTeam()); } + @ApiOperation(value = "Returns the Team of a user") + @ApiResponses(value = { + @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 401, message = "JWT Token expired"), + @ApiResponse(code = 400, message = "Something went wrong at verification") + }) + @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose + @RequestMapping(value = "/api/getCurrentStationMap", method = RequestMethod.GET, produces = "application/json") + public ResponseEntity getCurrentStationMap(@RequestParam String token, @RequestParam String cacheID){ + + logger.warn("API CALL: /api/getCurrentStationMap"); + + // verify user + ResponseEntity verifyToken = VerificationUtil.verifyToken(token); + + if (verifyToken.getStatusCodeValue() != 200) { + return verifyToken; + } + + //get User + Claims claims = (Claims) verifyToken.getBody(); + + ResponseEntity getUser = FinderUtil.findUserFromClaim(claims); + + if (getUser.getStatusCodeValue() != 200) { + return getUser; + } + + User user = (User) getUser.getBody(); + + logger.debug("User verificated: " + user.getEmail()); + + //---------------------- + //Get Cache + ResponseEntity getCache = FinderUtil.findCacheById(cacheID); + + if (getCache.getStatusCodeValue() != 200) { + return getCache; + } + + Cache cache = (Cache) getCache.getBody(); + + logger.debug("Cache: " + cache.getName()); + //---------------------- + + ResponseEntity responseBearbeitet = FinderUtil.findBearbeitetByUserAndCache(user, cache); + + if (responseBearbeitet.getStatusCodeValue() != 200){ + return responseBearbeitet; + } + + Bearbeitet bearbeitet = (Bearbeitet) responseBearbeitet.getBody(); + logger.debug("Got Bearbeitet:\n User: " + bearbeitet.getUser().getEmail() + "\nCache: " + bearbeitet.getCache().getName()); + + Station nextStation = bearbeitet.getAktuelleStation(); + logger.debug("Got Station from bearbeitet: " + nextStation.getDescription()); + + int index = cache.getStationen().indexOf(nextStation); + logger.debug("Index of Station " + nextStation.getDescription() + " in Cache " + cache.getName() + " : " + index); + + Station lastStation = cache.getStationen().get(index - 1); + logger.debug("Station before: " + lastStation.getDescription()); + + POI poi = new POI(cache.getName() + "_Station" + (index - 1.0), (float) lastStation.getLattitude(), (float) lastStation.getLongitude(), 201); + logger.debug("Created POI: " + poi.toString()); + + return ResponseEntity.status(200).body(new Gson().toJson(poi)); + } + @ApiOperation(value = "Test method (Changes its purpose often)") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), diff --git a/src/main/java/hhn/labsw/bugageocaching/helper/POI.java b/src/main/java/hhn/labsw/bugageocaching/helper/POI.java index 84631ac..8202997 100644 --- a/src/main/java/hhn/labsw/bugageocaching/helper/POI.java +++ b/src/main/java/hhn/labsw/bugageocaching/helper/POI.java @@ -45,4 +45,9 @@ public class POI { public void setCategoryID(int categoryID) { CategoryID = categoryID; } + + @Override + public String toString() { + return "Name: " + getName() + "; Latitude " + getLatitude() + "; Longitude " + getLongitude() + "; categoryID " + getLongitude(); + } } From 9608f082ae80825bf44f433e94902f6b4f0a4519 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Mon, 13 May 2019 15:50:19 +0200 Subject: [PATCH 3/4] Configured Logging for Backend --- build.gradle | 2 ++ .../hhn/labsw/bugageocaching/controller/Controller.java | 2 +- src/main/resources/application.properties | 8 +++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 43d4fd1..acc1301 100644 --- a/build.gradle +++ b/build.gradle @@ -68,6 +68,8 @@ dependencies { compile group: 'ch.qos.logback', name:'logback-core', version: '1.0.9' testCompile group: 'junit', name: 'junit', version: '4.+' + + } diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index d470edc..65a36e8 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -59,7 +59,7 @@ public class Controller { @Autowired TeamInviteRepository teamInviteRepository; - private static final Logger logger = LoggerFactory.getLogger(Controller.class); + private org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Controller.class); @PostConstruct public void init(){ diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6dee0a4..e6ddaf2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,4 +6,10 @@ spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.jooq.sql-dialect=org.hibernate.dialect.MariaDBDialect spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true -debug=true \ No newline at end of file +debug=true + + +# logging level +logging.level.hhn.labsw.bugageocaching=DEBUG +logging.level.root=WARN + From c75eb3f5e2226304fb556fec22035ac4ae162c9c Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Mon, 13 May 2019 19:08:02 +0200 Subject: [PATCH 4/4] Small changes in Logging --- .../bugageocaching/controller/Controller.java | 27 +++++++++---------- src/main/resources/application.properties | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 65a36e8..6098d36 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -12,10 +12,7 @@ import io.jsonwebtoken.Claims; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -62,7 +59,7 @@ public class Controller { private org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Controller.class); @PostConstruct - public void init(){ + public void init() { fetchPublicKey(); } @@ -338,7 +335,7 @@ public class Controller { @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose @RequestMapping(value = "/api/editCache", method = RequestMethod.PUT, produces = "application/json") @ResponseBody - public ResponseEntity editCache(@RequestBody Cache newCache){ + public ResponseEntity editCache(@RequestBody Cache newCache) { //---------------------- //Get Cache @@ -828,7 +825,7 @@ public class Controller { List teamInvitesList = teamInviteRepository.findByUser(user); - for (TeamInvite tmp : teamInvitesList){ + for (TeamInvite tmp : teamInvitesList) { tmp.setUser(null); } @@ -1112,7 +1109,7 @@ public class Controller { }) @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose @RequestMapping(value = "/api/getCurrentStationMap", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getCurrentStationMap(@RequestParam String token, @RequestParam String cacheID){ + public ResponseEntity getCurrentStationMap(@RequestParam String token, @RequestParam String cacheID) { logger.warn("API CALL: /api/getCurrentStationMap"); @@ -1134,7 +1131,7 @@ public class Controller { User user = (User) getUser.getBody(); - logger.debug("User verificated: " + user.getEmail()); + logger.debug("/api/getCurrentStationMap " + "User verificated: " + user.getEmail()); //---------------------- //Get Cache @@ -1146,29 +1143,29 @@ public class Controller { Cache cache = (Cache) getCache.getBody(); - logger.debug("Cache: " + cache.getName()); + logger.debug("/api/getCurrentStationMap " + "Cache: " + cache.getName()); //---------------------- ResponseEntity responseBearbeitet = FinderUtil.findBearbeitetByUserAndCache(user, cache); - if (responseBearbeitet.getStatusCodeValue() != 200){ + if (responseBearbeitet.getStatusCodeValue() != 200) { return responseBearbeitet; } Bearbeitet bearbeitet = (Bearbeitet) responseBearbeitet.getBody(); - logger.debug("Got Bearbeitet:\n User: " + bearbeitet.getUser().getEmail() + "\nCache: " + bearbeitet.getCache().getName()); + logger.debug("/api/getCurrentStationMap " + "Got Bearbeitet: User: " + bearbeitet.getUser().getEmail() + " Cache: " + bearbeitet.getCache().getName()); Station nextStation = bearbeitet.getAktuelleStation(); - logger.debug("Got Station from bearbeitet: " + nextStation.getDescription()); + logger.debug("/api/getCurrentStationMap " + "Got Station from bearbeitet: " + nextStation.getDescription()); int index = cache.getStationen().indexOf(nextStation); - logger.debug("Index of Station " + nextStation.getDescription() + " in Cache " + cache.getName() + " : " + index); + logger.debug("/api/getCurrentStationMap " + "Index of Station " + nextStation.getDescription() + " in Cache " + cache.getName() + " : " + index); Station lastStation = cache.getStationen().get(index - 1); - logger.debug("Station before: " + lastStation.getDescription()); + logger.debug("/api/getCurrentStationMap " + "Station before: " + lastStation.getDescription()); POI poi = new POI(cache.getName() + "_Station" + (index - 1.0), (float) lastStation.getLattitude(), (float) lastStation.getLongitude(), 201); - logger.debug("Created POI: " + poi.toString()); + logger.debug("/api/getCurrentStationMap " + "Created POI: " + poi.toString()); return ResponseEntity.status(200).body(new Gson().toJson(poi)); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e6ddaf2..61d17f8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,7 +5,7 @@ spring.jmx.default-domain=buga19geocaching spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.jooq.sql-dialect=org.hibernate.dialect.MariaDBDialect spring.jpa.hibernate.ddl-auto=update -spring.jpa.show-sql=true +# spring.jpa.show-sql=true debug=true