From f598516ed01651ca26f27c8544bcd6006b6c8c92 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Fri, 10 May 2019 18:16:03 +0200 Subject: [PATCH 01/25] bugfix in overview --- frontend/src/pages/Overview.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 4daba55..5b3c05e 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -123,8 +123,8 @@ async created() { console.log("created(): " + this.caches); - // this.$store.commit('auth/SET_AUTHENTICATED'); - // this.$store.commit('auth/SET_USER'); + this.$store.commit('auth/SET_AUTHENTICATED'); + this.$store.commit('auth/SET_USER'); await this.fetchAllCaches(); this.render = await this.fetchMyCaches(); }, From 8c1bff3a205737cc6f486123a8fc1af054dc48a2 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Fri, 10 May 2019 18:49:51 +0200 Subject: [PATCH 02/25] auth evaluation bugfix --- frontend/src/pages/Login.vue | 2 +- frontend/src/pages/MyCaches.vue | 6 +++--- frontend/src/pages/Overview.vue | 9 ++------- frontend/src/pages/Profile.vue | 4 ++-- frontend/src/pages/Register.vue | 4 ++-- frontend/src/router/index.js | 29 +++++++++++++++++------------ 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 96418a7..ec2a41d 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -138,7 +138,7 @@ }, evalAuthentication: function () { this.$store.commit('auth/SET_AUTHENTICATED'); - // this.$store.commit('auth/SET_USER'); + this.$store.commit('auth/SET_USER'); }, logout: function () { console.log("logout()"); diff --git a/frontend/src/pages/MyCaches.vue b/frontend/src/pages/MyCaches.vue index d541885..d7e463e 100644 --- a/frontend/src/pages/MyCaches.vue +++ b/frontend/src/pages/MyCaches.vue @@ -11,8 +11,8 @@ indicator-color="cyan-14" switch-indicator > - - + + @@ -115,7 +115,7 @@ }, }, created: function () { - this.$store.commit('auth/SET_AUTHENTICATED'); + // this.$store.commit('auth/SET_AUTHENTICATED'); this.fetchUserCaches(); }, methods: { diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 5b3c05e..9ea23cf 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -60,7 +60,7 @@ label="Belohnung" size="xs"/> - @@ -118,13 +118,8 @@ return this.$store.getters['auth/GET_ADMINSTATE']; } }, - beforeMount() { - }, - async created() { console.log("created(): " + this.caches); - this.$store.commit('auth/SET_AUTHENTICATED'); - this.$store.commit('auth/SET_USER'); await this.fetchAllCaches(); this.render = await this.fetchMyCaches(); }, @@ -236,7 +231,7 @@ addCache() { this.$router.push({path: `/cache`}) }, - editCache() { + editCache(cacheID) { }, initMap() { console.log("Signalwort: " + this.pois); diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index c711f26..ac4b1c6 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -296,8 +296,8 @@ } }, created: function () { - this.$store.commit('auth/SET_AUTHENTICATED'); - this.$store.commit('auth/SET_USER'); + // this.$store.commit('auth/SET_AUTHENTICATED'); + // this.$store.commit('auth/SET_USER'); this.userName = JSON.parse(localStorage.getItem('userToken')).name; this.data[0].userData = this.userName; this.email = JSON.parse(localStorage.getItem('userMail')); diff --git a/frontend/src/pages/Register.vue b/frontend/src/pages/Register.vue index ccd2b3f..2a9d9ae 100644 --- a/frontend/src/pages/Register.vue +++ b/frontend/src/pages/Register.vue @@ -185,8 +185,8 @@ .then((response) => { localStorage.setItem('userToken', JSON.stringify(response.data)); localStorage.setItem('userMail', JSON.stringify(data.email)); - this.$store.commit('auth/SET_AUTHENTICATED'); - this.$store.commit('auth/SET_USER'); + // this.$store.commit('auth/SET_AUTHENTICATED'); + // this.$store.commit('auth/SET_USER'); this.$router.push({path: `/overview`}); }) .catch((error) => { diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index e56463b..944f157 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -3,18 +3,17 @@ import VueRouter from "vue-router"; import routes from "./routes"; import {axiosInstance} from "../boot/axios"; -Vue.use(VueRouter); -import store from "../store/index"; +Vue.use(VueRouter); /* * If not building with SSR mode, you can * directly export the Router instantiation */ -export default function({ store }/* { store, ssrContext } */) { +export default function ({store}/* { store, ssrContext } */) { const Router = new VueRouter({ - scrollBehavior: () => ({ x: 0, y: 0 }), + scrollBehavior: () => ({x: 0, y: 0}), routes, store, // Leave these as is and change from quasar.conf.js instead! @@ -36,20 +35,23 @@ export default function({ store }/* { store, ssrContext } */) { console.log(loggedIn); const isAdmin = loggedIn ? loggedIn.roles.find(x => x.role === "ADMIN" && x.domain === "geocaching.de") : false; //const isAdmin = true; - if (!isPublic && !loggedIn) { return next({ - path:'/login', + path: '/login', query: {redirect: to.fullPath} // Store the full path to redirect the user to after login }); } + console.log("!isPublic && !loggedIn") if ((loggedIn && onlyWhenLoggedOut) || (loggedIn && onlyAdmin && !isAdmin)) { return next('/') } - if (isPublic) { + console.log("(loggedIn && onlyWhenLoggedOut) || (loggedIn && onlyAdmin && !isAdmin)") + if (isPublic && !loggedIn) { return next() } - if (!isPublic && loggedIn) { + console.log("isPublic") + if (!onlyWhenLoggedOut && loggedIn) { + console.log("fetch data...") axiosInstance.get('/api/getUser', { params: { token: loggedIn.token @@ -57,7 +59,6 @@ export default function({ store }/* { store, ssrContext } */) { }) .then((response) => { console.log("Token valid!"); - store.commit('auth/SET_AUTHENTICATED'); return next(); }) .catch((error) => { @@ -71,16 +72,20 @@ export default function({ store }/* { store, ssrContext } */) { store.commit('dialog/NEW_MESSAGE_DIALOG', { message: "Ihr Token ist nicht mehr gültig. Bitte loggen Sie sich erneut ein.", title: "Bitte erneut anmelden.", - color: "blue", }); + color: "blue", + }); localStorage.removeItem('userToken'); - store.commit('auth/SET_AUTHENTICATED'); return next('/Login'); } else { console.log("unexpected behaviour"); console.log(error); return next(); } - }); + }).finally(() => { + console.log("finally..."); + store.commit('auth/SET_AUTHENTICATED'); + store.commit('auth/SET_USER'); + }); } console.log(`isPublic: ${isPublic} \nonlyWhenLoggedOut: ${onlyWhenLoggedOut} \nonlyAdmin: ${onlyAdmin}`); //return next(); From 30954310e115f3990d70e8687a6a9d382bc8c9f7 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Fri, 10 May 2019 19:00:51 +0200 Subject: [PATCH 03/25] improvements --- frontend/src/layouts/MyLayout.vue | 2 +- frontend/src/router/index.js | 1 - frontend/src/store/auth/mutations.js | 8 ++------ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/frontend/src/layouts/MyLayout.vue b/frontend/src/layouts/MyLayout.vue index 7d4edf9..a689d69 100644 --- a/frontend/src/layouts/MyLayout.vue +++ b/frontend/src/layouts/MyLayout.vue @@ -235,7 +235,7 @@ } }, created() { - this.evalAuthentication(); + //this.evalAuthentication(); }, methods: { //openURL diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index 944f157..c9ba718 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -82,7 +82,6 @@ export default function ({store}/* { store, ssrContext } */) { return next(); } }).finally(() => { - console.log("finally..."); store.commit('auth/SET_AUTHENTICATED'); store.commit('auth/SET_USER'); }); diff --git a/frontend/src/store/auth/mutations.js b/frontend/src/store/auth/mutations.js index e096bee..9e7fb77 100644 --- a/frontend/src/store/auth/mutations.js +++ b/frontend/src/store/auth/mutations.js @@ -14,7 +14,6 @@ export const SET_LOGOUT = (state) => { localStorage.removeItem('userToken'); state.userAuthenticated = null; state.isAuthenticated = false; - console.log(localStorage.getItem('userToken')); }; export const SET_USER = (state) => { console.log("SET_USER()"); @@ -26,16 +25,13 @@ export const SET_USER = (state) => { } }) .then((response) => { - console.log("GET/POST /api/getUser - response: "); - console.log(response.data); + console.log("GET /api/getUser"); state.userAuthenticated = response.data; state.isAuthenticated = true; if (state.userAuthenticated.hasOwnProperty('password')) delete state.userAuthenticated.password; - console.log(state.userAuthenticated); }) .catch((error) => { - console.log("Catch Block: ") - console.log(error) + console.log("error") }); } else { state.isAuthenticated = false; From fce24179a61682578b845c1678065bf15c8bb79c Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Mon, 13 May 2019 11:14:22 +0200 Subject: [PATCH 04/25] Fixed Leave team --- .../java/hhn/labsw/bugageocaching/controller/Controller.java | 2 +- 1 file changed, 1 insertion(+), 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 a9643d9..c72d267 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -632,7 +632,7 @@ public class Controller { @ApiResponse(code = 400, message = "Something went wrong at verification") }) @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose - @RequestMapping(value = "/api/leaveTeam", method = RequestMethod.PUT, produces = "application/json") + @RequestMapping(value = "/api/leaveTeam", method = {RequestMethod.PUT, RequestMethod.GET}, produces = "application/json") @ResponseBody public ResponseEntity leaveTeam(@RequestParam String token) { From fd0328557322ce9cede00fd5a6c0a51981ca608e Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 13 May 2019 12:30:42 +0200 Subject: [PATCH 05/25] typo in warning --- frontend/quasar.conf.js | 3 ++- frontend/src/router/index.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index 3765fb7..d4ff378 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -72,7 +72,8 @@ module.exports = function (ctx) { 'QPopupEdit', 'QSlideTransition', 'QToggle', - 'QLinearProgress' + 'QLinearProgress', + 'QBtnGroup' ], directives: [ diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index c9ba718..98ea71b 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -70,7 +70,7 @@ export default function ({store}/* { store, ssrContext } */) { console.log(error.response.headers); //store.commit('auth/SET_LOGOUT'); store.commit('dialog/NEW_MESSAGE_DIALOG', { - message: "Ihr Token ist nicht mehr gültig. Bitte loggen Sie sich erneut ein.", + message: "Ihre Session ist abgelaufen. Bitte loggen Sie sich erneut ein.", title: "Bitte erneut anmelden.", color: "blue", }); From d0976ab92139c7c74c06b8bcef29504099bd99df Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 May 2019 12:49:57 +0200 Subject: [PATCH 06/25] 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 07/25] 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 c1dcba7c0499c0d08a1784ac2a0d18c0f072a989 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 May 2019 15:34:34 +0200 Subject: [PATCH 08/25] first implementation of editCache --- .../bugageocaching/controller/Controller.java | 48 +++++----- .../util/CacheConstructionUtil.java | 92 +++++++++++++++++++ 2 files changed, 118 insertions(+), 22 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 2385965..72027ea 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -6,6 +6,7 @@ import hhn.labsw.bugageocaching.helper.POI; import hhn.labsw.bugageocaching.helper.RankingListHelper; import hhn.labsw.bugageocaching.helper.TeamRankingListHelper; import hhn.labsw.bugageocaching.repositories.*; +import hhn.labsw.bugageocaching.util.CacheConstructionUtil; import hhn.labsw.bugageocaching.util.FinderUtil; import hhn.labsw.bugageocaching.util.VerificationUtil; import io.jsonwebtoken.Claims; @@ -24,6 +25,7 @@ import java.util.List; import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.createCacheUtil; import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.deleteCacheUtil; +import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.editCacheUtil; import static hhn.labsw.bugageocaching.util.VerificationUtil.fetchPublicKey; @RestController @@ -57,7 +59,7 @@ public class Controller { TeamInviteRepository teamInviteRepository; @PostConstruct - public void init(){ + public void init() { fetchPublicKey(); } @@ -333,28 +335,30 @@ 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 - ResponseEntity getCache = FinderUtil.findCacheById(newCache.getId() + ""); +// //---------------------- +// //Get Cache +// ResponseEntity getCache = FinderUtil.findCacheById(newCache.getId() + ""); +// +// if (getCache.getStatusCodeValue() != 200) { +// return getCache; +// } +// +// Cache oldCache = (Cache) getCache.getBody(); +// //---------------------- +// +// oldCache.setDescription(newCache.getDescription()); +// oldCache.setName(newCache.getName()); +// oldCache.setRankingPoints(newCache.getRankingPoints()); +// oldCache.setReward(newCache.getReward()); +// oldCache.setStationen(newCache.getStationen()); +// +// cacheRepository.save(oldCache); +// +// return ResponseEntity.status(200).body("Cache edited"); - if (getCache.getStatusCodeValue() != 200) { - return getCache; - } - - Cache oldCache = (Cache) getCache.getBody(); - //---------------------- - - oldCache.setDescription(newCache.getDescription()); - oldCache.setName(newCache.getName()); - oldCache.setRankingPoints(newCache.getRankingPoints()); - oldCache.setReward(newCache.getReward()); - oldCache.setStationen(newCache.getStationen()); - - cacheRepository.save(oldCache); - - return ResponseEntity.status(200).body("Cache edited"); + return editCacheUtil(newCache); } @ApiOperation(value = "Checks if the given User has an admin role") @@ -823,7 +827,7 @@ public class Controller { List teamInvitesList = teamInviteRepository.findByUser(user); - for (TeamInvite tmp : teamInvitesList){ + for (TeamInvite tmp : teamInvitesList) { tmp.setUser(null); } diff --git a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java index 5deb9c5..959c2f5 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; import javax.persistence.RollbackException; import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.Random; @@ -120,6 +121,87 @@ public class CacheConstructionUtil { return ResponseEntity.status(200).body(new Gson().toJson(station)); } + public static ResponseEntity editCacheUtil(Cache cache) { + Optional oldCacheOptional = cacheRepository.findById(cache.getId()); + Cache oldCache; + if (oldCacheOptional.isPresent()) { + oldCache = oldCacheOptional.get(); + } else { + return ResponseEntity.status(404).body("There isnt a cache with the id " + cache.getId()); + } + + ResponseEntity response; + List newCreatedStationList = new ArrayList(); + for (Station station : cache.getStationen()) { + // wenn Station schon vorher vorhanden war, wird nur nach validen Daten geprüft + if (oldCache.getStationen().contains(station)) { + response = checkStationUtil(station); + } + // wenn Station neu hinzugefügt wurde, wird die Station zusätzlich in die Datenbank gespeichert + else { + response = createStationUtil(station); + if (response.getStatusCodeValue() == 200) { + newCreatedStationList.add(station); + } + } + if (response.getStatusCodeValue() == 400) { + // neu erzeugte Stationen werden gelöscht, falls es einen Fehler gibt + deleteNewCreatedStationsUtil(newCreatedStationList); + return response; + } + } + + for (Station station : oldCache.getStationen()) { + // wenn Station entfernt wurde, wird diese auch aus der Datenbank gelöscht + if (!cache.getStationen().contains(station)) { + stationRepository.delete(station); + } + } + + // überprüft den Cache nach validen Daten + if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("cache fields can´t be empty"); + } + + if (cache.getStationen().size() < 2) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("a cache needs atleast 2 stations"); + } + + for (Cache cache1 : cacheRepository.findAll()) { + if (cache1.getName().equals(cache.getName())) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("name is already taken"); + } + } + + if (cache.getRankingPoints() < 0) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("Ranking points has to be a positive number"); + } + + cacheRepository.save(cache); + + return ResponseEntity.status(200).body(new Gson().toJson(cache)); + } + + public static ResponseEntity checkStationUtil(Station station) { + if (station.getDescription().length() == 0 || station.getLattitude() == 0.0 || station.getLongitude() == 0.0 /*|| station.getSolution().length() == 0*/) { + return ResponseEntity.status(400).body("station fields can´t be empty"); + } + + if (station.getLattitude() < 9 || station.getLattitude() > 10) { + return ResponseEntity.status(400).body("Lattitude has to be between 9 and 10 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"); + } + + return ResponseEntity.status(200).body(new Gson().toJson(station)); + } + public static void deleteStationenUtil(Cache cache) { for (Station station : cache.getStationen()) { try { @@ -130,6 +212,16 @@ public class CacheConstructionUtil { } } + public static void deleteNewCreatedStationsUtil(List newCreatedStationList) { + for (Station station : newCreatedStationList) { + try { + stationRepository.delete(station); + } catch (IllegalArgumentException e) { // station is null + // do nothing + } + } + } + public static ResponseEntity deleteCacheUtil(String cacheID) { Optional optionalCache = cacheRepository.findById(Integer.valueOf(cacheID)); if (!optionalCache.isPresent()) { From 30cb1d15796d57964b801e9e160c1bd97dad8352 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 May 2019 15:41:13 +0200 Subject: [PATCH 09/25] a fix in editCache --- .../labsw/bugageocaching/util/CacheConstructionUtil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java index 959c2f5..7dc78ac 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java @@ -171,8 +171,10 @@ public class CacheConstructionUtil { for (Cache cache1 : cacheRepository.findAll()) { if (cache1.getName().equals(cache.getName())) { - deleteNewCreatedStationsUtil(newCreatedStationList); - return ResponseEntity.status(400).body("name is already taken"); + if (cache1 != oldCache) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("name is already taken"); + } } } From 9608f082ae80825bf44f433e94902f6b4f0a4519 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Mon, 13 May 2019 15:50:19 +0200 Subject: [PATCH 10/25] 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 11/25] 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 From 074a18a831190fb55c46856769235336eacce0b7 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Tue, 14 May 2019 09:09:59 +0200 Subject: [PATCH 12/25] More Logger --- .../bugageocaching/controller/Controller.java | 25 +++++++++++++++---- .../bugageocaching/util/VerificationUtil.java | 14 +++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 6098d36..93182f4 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -68,6 +68,7 @@ public class Controller { @RequestMapping(value = "/api/allCaches", method = RequestMethod.GET, produces = "application/json") @ResponseBody public ResponseEntity getAllCaches() { + logger.warn("API CALL: /api/allCaches"); return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll())); } @@ -405,6 +406,7 @@ public class Controller { @RequestMapping(value = "/api/getAllStations", method = RequestMethod.GET, produces = "application/json") @ResponseBody public ResponseEntity getAllStations() { + logger.warn("API CALL: /api/getAllStations"); return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll())); } @@ -416,6 +418,7 @@ public class Controller { @RequestMapping(value = "/api/deleteCache", method = {RequestMethod.DELETE, RequestMethod.GET}, produces = "application/json") @ResponseBody public ResponseEntity deleteCache(@RequestParam String cacheID) { + logger.warn("API CALL: /api/deleteCache"); return deleteCacheUtil(cacheID); } @@ -430,6 +433,7 @@ public class Controller { @ResponseBody public ResponseEntity getMyCaches(@RequestParam String token) { + logger.warn("API CALL: /api/getMyCaches"); ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -439,6 +443,8 @@ public class Controller { Claims claims = (Claims) verifyToken.getBody(); + logger.debug("/api/getMyCaches Token verified"); + ResponseEntity getUser = FinderUtil.findUserFromClaim(claims); if (getUser.getStatusCodeValue() != 200) { @@ -447,14 +453,18 @@ public class Controller { User user = (User) getUser.getBody(); - if (user != null) { - ArrayList bearbeitetList = new ArrayList<>(); + logger.debug("/api/getMyCaches Got User: " + user.getEmail()); - for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) { + if (user != null) { + //ArrayList bearbeitetList = new ArrayList<>(); + + /*for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) { if (bearbeitet.getUser().getId() == user.getId()) { bearbeitetList.add(bearbeitet); } - } + }*/ + List bearbeitetList = bearbeitetRepository.findByUser(user); + logger.debug("/api/getMyCaches Got all bearbeitet entreis of user: " +user.getEmail()); return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList)); } else { return ResponseEntity.status(404).body("User was not found in the database"); @@ -470,13 +480,18 @@ public class Controller { @ResponseBody public ResponseEntity getRankingList() { + logger.warn("API CALL: /api/getRankingList"); + List sendBackUsers = new LinkedList<>(); + + logger.debug("/api/getRankingList create sendBackUsers"); List rankingUsers = userRepository.getRankingList(); + logger.debug("/api/getRankingList got Object[] from DB"); for (Object[] obj : rankingUsers) { RankingListHelper tmp = new RankingListHelper((String) obj[1], (Integer) obj[2]); - System.out.println(tmp); sendBackUsers.add(tmp); } + logger.debug("/api/getRankingList Converted Objects to RankingListHelper"); return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers)); } diff --git a/src/main/java/hhn/labsw/bugageocaching/util/VerificationUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/VerificationUtil.java index 1ad5b5f..fb047af 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/VerificationUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/VerificationUtil.java @@ -1,5 +1,6 @@ package hhn.labsw.bugageocaching.util; +import hhn.labsw.bugageocaching.controller.Controller; import hhn.labsw.bugageocaching.fetchObjects.PublicKey; import io.jsonwebtoken.Claims; import io.jsonwebtoken.ExpiredJwtException; @@ -16,16 +17,23 @@ public class VerificationUtil { public static Key publicKey; + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(VerificationUtil.class); + public static void fetchPublicKey(){ RestTemplate restTemplate = new RestTemplate(); try { + logger.warn("POST CONSCTRUCT: FETCH PUBLIC KEY"); PublicKey response = restTemplate.getForObject("http://seserver.se.hs-heilbronn.de:9080/buga19usermanagement/token/publickey", PublicKey.class); + logger.debug("FETCH PUBLIC KEY: Got response from http://seserver.se.hs-heilbronn.de:9080/buga19usermanagement/token/publickey"); + byte[] decodedKey = Base64.getDecoder().decode(response.getMessage()); KeyFactory factory = KeyFactory.getInstance("RSA"); X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(decodedKey); Key key = factory.generatePublic(publicKeySpec); publicKey = key; + + logger.debug("FETCH PUBLIC KEY: Decoded Key: " + publicKey.toString()); } catch (Exception e) { e.printStackTrace(); } @@ -36,14 +44,20 @@ public class VerificationUtil { public static ResponseEntity verifyToken(String token){ try{ + + logger.warn("VERIFY TOKEN: token: " + token); Claims claims = Jwts.parser() //Parse JWT .setSigningKey(VerificationUtil.publicKey) .parseClaimsJws(token).getBody(); + logger.debug("VERIFY TOKEN: Got Claims: " + claims); + return ResponseEntity.status(200).body(claims); } catch (ExpiredJwtException e){ + logger.debug("VERIFY TOKEN: JWT Token expired"); return ResponseEntity.status(401).body("JWT Token expired"); } catch (Exception e){ + logger.debug("VERIFY TOKEN: Something went wrong verificating"); return ResponseEntity.status(400).body("Something went wrong"); } } From 0d2ac9af37fc4ec611a6dc3c9c4162a0aa7af09a Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 May 2019 09:53:48 +0200 Subject: [PATCH 13/25] refactored code --- .../util/CacheConstructionUtil.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java index 7dc78ac..0f618b6 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java @@ -86,12 +86,12 @@ public class CacheConstructionUtil { return ResponseEntity.status(400).body("station fields can´t be empty"); } - if (station.getLattitude() < 9 || station.getLattitude() > 10) { + if (station.getLongitude() < 9 || station.getLongitude() > 10) { return ResponseEntity.status(400).body("Lattitude has to be between 9 and 10 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"); + if (station.getLattitude() < 49 || station.getLattitude() > 50) { + return ResponseEntity.status(400).body("Lattitude has to be in the range of 49 to 50 degrees"); } Random r = new Random(); @@ -151,13 +151,6 @@ public class CacheConstructionUtil { } } - for (Station station : oldCache.getStationen()) { - // wenn Station entfernt wurde, wird diese auch aus der Datenbank gelöscht - if (!cache.getStationen().contains(station)) { - stationRepository.delete(station); - } - } - // überprüft den Cache nach validen Daten if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) { deleteNewCreatedStationsUtil(newCreatedStationList); @@ -185,6 +178,13 @@ public class CacheConstructionUtil { cacheRepository.save(cache); + for (Station station : oldCache.getStationen()) { + // wenn Station entfernt wurde, wird diese auch aus der Datenbank gelöscht + if (!cache.getStationen().contains(station)) { + stationRepository.delete(station); + } + } + return ResponseEntity.status(200).body(new Gson().toJson(cache)); } From 16381ac8c2eaff04875a1c4fa0e28115d25cb86b Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Tue, 14 May 2019 10:17:06 +0200 Subject: [PATCH 14/25] implemented edit Cache, bugfixes --- frontend/src/pages/Cache.vue | 97 ++++++++----------- frontend/src/pages/Overview.vue | 13 ++- .../src/store/cacheCollector/mutations.js | 4 +- frontend/src/store/cacheCollector/state.js | 4 +- 4 files changed, 51 insertions(+), 67 deletions(-) diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue index 42c9e40..d61d98d 100644 --- a/frontend/src/pages/Cache.vue +++ b/frontend/src/pages/Cache.vue @@ -1,7 +1,5 @@