From 3cc9fd5597ba55168e39f1f0b8db8abb8c4fbebf Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 3 May 2019 18:43:09 +0200 Subject: [PATCH 1/6] added StationPOI helper class --- .../bugageocaching/helper/StationPOI.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/hhn/labsw/bugageocaching/helper/StationPOI.java diff --git a/src/main/java/hhn/labsw/bugageocaching/helper/StationPOI.java b/src/main/java/hhn/labsw/bugageocaching/helper/StationPOI.java new file mode 100644 index 0000000..6b2566b --- /dev/null +++ b/src/main/java/hhn/labsw/bugageocaching/helper/StationPOI.java @@ -0,0 +1,41 @@ +package hhn.labsw.bugageocaching.helper; + +public class StationPOI { + + private String Name; + private float Latitude; + private float Longitude; + private int CategoryID; // 0 = grünes icon(startstation) // 1 = orangenes icon(folgestationen) // 2 = rotes icon(endstation) + + public String getName() { + return Name; + } + + public void setName(String name) { + Name = name; + } + + public float getLatitude() { + return Latitude; + } + + public void setLatitude(float latitude) { + Latitude = latitude; + } + + public float getLongitude() { + return Longitude; + } + + public void setLongitude(float longitude) { + Longitude = longitude; + } + + public int getCategoryID() { + return CategoryID; + } + + public void setCategoryID(int categoryID) { + CategoryID = categoryID; + } +} From c86ce22d27538a81b96182c8378d556cd39415cb Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 3 May 2019 18:48:02 +0200 Subject: [PATCH 2/6] renamed the helper class --- .../hhn/labsw/bugageocaching/controller/Controller.java | 6 ++++++ .../bugageocaching/helper/{StationPOI.java => POI.java} | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) rename src/main/java/hhn/labsw/bugageocaching/helper/{StationPOI.java => POI.java} (96%) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 612c5e7..45cfefd 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -971,6 +971,12 @@ public class Controller { return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(user.getUsername())); } + @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose +// @RequestMapping(value = "/api/getRankingPlace", method = RequestMethod.GET, produces = "application/json") + public ResponseEntity getMyMap() { + + } + @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/StationPOI.java b/src/main/java/hhn/labsw/bugageocaching/helper/POI.java similarity index 96% rename from src/main/java/hhn/labsw/bugageocaching/helper/StationPOI.java rename to src/main/java/hhn/labsw/bugageocaching/helper/POI.java index 6b2566b..1c1b908 100644 --- a/src/main/java/hhn/labsw/bugageocaching/helper/StationPOI.java +++ b/src/main/java/hhn/labsw/bugageocaching/helper/POI.java @@ -1,6 +1,6 @@ package hhn.labsw.bugageocaching.helper; -public class StationPOI { +public class POI { private String Name; private float Latitude; From 6ca87f84fc0bbbd7aa5b0c431863cf9672b0e6a6 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 3 May 2019 19:10:03 +0200 Subject: [PATCH 3/6] implemented getStationPOIS --- .../bugageocaching/controller/Controller.java | 73 +++++++++++++++++-- .../hhn/labsw/bugageocaching/helper/POI.java | 7 ++ 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 45cfefd..c1e0bd2 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -2,6 +2,7 @@ package hhn.labsw.bugageocaching.controller; import com.google.gson.Gson; import hhn.labsw.bugageocaching.entities.*; +import hhn.labsw.bugageocaching.helper.POI; import hhn.labsw.bugageocaching.helper.RankingListHelper; import hhn.labsw.bugageocaching.helper.TeamRankingListHelper; import hhn.labsw.bugageocaching.repositories.*; @@ -724,7 +725,7 @@ public class Controller { //Get User_Info - User_Info user_info = user_infoRepository.findUser_InfoByUser(user); + User_Info user_info = user_infoRepository.findUser_InfoByUser(user); //---------------------- if (user_info.getTeam() == null) { return ResponseEntity.status(400).body("You aren´t in any team"); @@ -853,7 +854,7 @@ public class Controller { User user = (User) getUser.getBody(); //Get User_Info - User_Info user_info = user_infoRepository.findUser_InfoByUser(user); + User_Info user_info = user_infoRepository.findUser_InfoByUser(user); //---------------------- if (user_info.getTeam() == null) { return ResponseEntity.status(400).body("You aren´t in any team"); @@ -880,7 +881,7 @@ public class Controller { }) @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping(value = "/api/getTeam", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getTeam(@RequestParam String name){ + public ResponseEntity getTeam(@RequestParam String name) { ResponseEntity responseEntity = FinderUtil.findTeamByName(name); return responseEntity; @@ -892,7 +893,7 @@ public class Controller { }) @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping(value = "/api/getTeamMembers", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getTeamMembers(@RequestParam String name){ + public ResponseEntity getTeamMembers(@RequestParam String name) { return FinderUtil.findTeammemberByTeamName(name); } @@ -906,7 +907,7 @@ public class Controller { @RequestMapping(value = "/api/getCurrentStation", method = RequestMethod.GET, produces = "application/json") @ResponseBody public ResponseEntity getStationFromUserAndCache(@RequestParam String token, - @RequestParam String cacheID){ + @RequestParam String cacheID) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -948,7 +949,7 @@ public class Controller { }) @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping(value = "/api/getRankingPlace", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getRankingPlace(@RequestParam String token){ + public ResponseEntity getRankingPlace(@RequestParam String token) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -971,10 +972,66 @@ public class Controller { return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(user.getUsername())); } + @ApiOperation(value = "Returns startstations and all other stations he user already visited as POIS") + @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 = "http://localhost:8081") // only for dev purpose -// @RequestMapping(value = "/api/getRankingPlace", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getMyMap() { + @RequestMapping(value = "/api/getStationPOIS", method = RequestMethod.GET, produces = "application/json") + public ResponseEntity getStationPOIS(@RequestParam String token) { + // 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(); + // + + ArrayList poisList = new ArrayList<>(); + for (Cache cache : cacheRepository.findAll()) { + Station station = cache.getStationen().get(0); + POI poi = new POI(cache.getName() + "_Station1", (float) station.getLattitude(), (float) station.getLongitude(), 0); + poisList.add(poi); + } + + for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) { + if (bearbeitet.getUser() == user) { + Cache cache = bearbeitet.getCache(); + Station aktuelleStation = bearbeitet.getAktuelleStation(); + int index = cache.getStationen().indexOf(aktuelleStation); + for (int i = 1; i <= index; i++) { + Station station = cache.getStationen().get(i); + int categoryID; + if (i < cache.getStationen().size() - 1) { // isnt endstation + categoryID = 1; + } else { // is endstation + categoryID = 2; + } + POI poi = new POI(cache.getName() + "_Station" + (i + 1), (float) station.getLattitude(), (float) station.getLongitude(), categoryID); + poisList.add(poi); + } + } + } + + POI[] pois = new POI[poisList.size()]; + for (int i = 0; i < poisList.size(); i++) { + pois[i] = poisList.get(i); + } + + return ResponseEntity.status(200).body(new Gson().toJson(pois)); } @ApiOperation(value = "Test method (Changes its purpose often)") diff --git a/src/main/java/hhn/labsw/bugageocaching/helper/POI.java b/src/main/java/hhn/labsw/bugageocaching/helper/POI.java index 1c1b908..2bb91c7 100644 --- a/src/main/java/hhn/labsw/bugageocaching/helper/POI.java +++ b/src/main/java/hhn/labsw/bugageocaching/helper/POI.java @@ -7,6 +7,13 @@ public class POI { private float Longitude; private int CategoryID; // 0 = grünes icon(startstation) // 1 = orangenes icon(folgestationen) // 2 = rotes icon(endstation) + public POI(String name, float latitude, float longitude, int categoryID) { + Name = name; + Latitude = latitude; + Longitude = longitude; + CategoryID = categoryID; + } + public String getName() { return Name; } From ed3fb3ff0edc8959e04e14f82d293af398818dad Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 3 May 2019 19:13:21 +0200 Subject: [PATCH 4/6] renamed to getMyStationPOIS --- .../java/hhn/labsw/bugageocaching/controller/Controller.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index c1e0bd2..de86d5d 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -979,8 +979,8 @@ public class Controller { @ApiResponse(code = 400, message = "Something went wrong at verification") }) @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose - @RequestMapping(value = "/api/getStationPOIS", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getStationPOIS(@RequestParam String token) { + @RequestMapping(value = "/api/getMyStationPOIS", method = RequestMethod.GET, produces = "application/json") + public ResponseEntity getMyStationPOIS(@RequestParam String token) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); From 68098b1fffdd7c10c5fc88923747df1758fa55c4 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 3 May 2019 19:18:47 +0200 Subject: [PATCH 5/6] fixed a spelling mistake --- .../java/hhn/labsw/bugageocaching/controller/Controller.java | 4 +++- src/main/java/hhn/labsw/bugageocaching/helper/POI.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index de86d5d..fe2525c 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -972,7 +972,7 @@ public class Controller { return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(user.getUsername())); } - @ApiOperation(value = "Returns startstations and all other stations he user already visited as POIS") + @ApiOperation(value = "Returns startstations and all other stations the user already visited as POIS") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), @ApiResponse(code = 401, message = "JWT Token expired"), @@ -1003,6 +1003,7 @@ public class Controller { ArrayList poisList = new ArrayList<>(); for (Cache cache : cacheRepository.findAll()) { Station station = cache.getStationen().get(0); + // ICONS müssen noch erstellt werden und die categoryID entsprechend angepasst POI poi = new POI(cache.getName() + "_Station1", (float) station.getLattitude(), (float) station.getLongitude(), 0); poisList.add(poi); } @@ -1014,6 +1015,7 @@ public class Controller { int index = cache.getStationen().indexOf(aktuelleStation); for (int i = 1; i <= index; i++) { Station station = cache.getStationen().get(i); + // ICONS müssen noch erstellt werden und die categoryID entsprechend angepasst int categoryID; if (i < cache.getStationen().size() - 1) { // isnt endstation categoryID = 1; diff --git a/src/main/java/hhn/labsw/bugageocaching/helper/POI.java b/src/main/java/hhn/labsw/bugageocaching/helper/POI.java index 2bb91c7..d6a4051 100644 --- a/src/main/java/hhn/labsw/bugageocaching/helper/POI.java +++ b/src/main/java/hhn/labsw/bugageocaching/helper/POI.java @@ -5,6 +5,7 @@ public class POI { private String Name; private float Latitude; private float Longitude; + // ICONS müssen noch erstellt werden und die categoryID entsprechend angepasst private int CategoryID; // 0 = grünes icon(startstation) // 1 = orangenes icon(folgestationen) // 2 = rotes icon(endstation) public POI(String name, float latitude, float longitude, int categoryID) { From ef819e5e54cc0e6e59cb0abb7a0a33dc03a11042 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Mon, 6 May 2019 13:53:42 +0200 Subject: [PATCH 6/6] Usermanagement fixed --- .../java/hhn/labsw/bugageocaching/util/VerificationUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/util/VerificationUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/VerificationUtil.java index 4fac803..b29ae41 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/VerificationUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/VerificationUtil.java @@ -20,7 +20,7 @@ public class VerificationUtil { public static void fetchPublicKey() { RestTemplate restTemplate = new RestTemplate(); try { - PublicKey response = restTemplate.getForObject("http://seserver.se.hs-heilbronn.de:9080/buga19usermanagement/token/publickey", PublicKey.class); + PublicKey response = restTemplate.getForObject("http://seserver.se.hs-heilbronn.de:8090/buga19usermanagement/token/publickey", PublicKey.class); byte[] decodedKey = Base64.getDecoder().decode(response.getMessage()); KeyFactory factory = KeyFactory.getInstance("RSA"); X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(decodedKey);