diff --git a/src/main/java/hhn/labsw/bugageocaching/Application.java b/src/main/java/hhn/labsw/bugageocaching/Application.java index f835849..9231cda 100644 --- a/src/main/java/hhn/labsw/bugageocaching/Application.java +++ b/src/main/java/hhn/labsw/bugageocaching/Application.java @@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; import springfox.documentation.builders.PathSelectors; @@ -14,6 +15,7 @@ import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication(exclude = { SecurityAutoConfiguration.class }) +@ServletComponentScan @EnableSwagger2 public class Application extends SpringBootServletInitializer{ diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 13d1bb9..a386261 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -7,13 +7,10 @@ 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; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -25,12 +22,11 @@ import java.util.ArrayList; import java.util.LinkedList; 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.CacheConstructionUtil.*; import static hhn.labsw.bugageocaching.util.VerificationUtil.fetchPublicKey; @RestController +@Api(value = "/api", description = "All Backend API Operations for the geocaching Application") public class Controller { @Autowired @@ -67,7 +63,13 @@ public class Controller { fetchPublicKey(); } - @ApiOperation(value = "Retrieves all Caches, including their Stations, from the Database") + @ApiOperation(value = "Retrieves all Caches, including their Stations, from the Database", response = Cache.class, responseContainer = "List in Body of ResponseEntity") + @ApiResponses(value = { + @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), + @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/allCaches", method = RequestMethod.GET, produces = "application/json") @ResponseBody @@ -78,7 +80,7 @@ public class Controller { } - @ApiOperation(value = "Checks if the given Station is the correct next Station in the Cache") + @ApiOperation(value = "Checks if the given Station is the correct next Station in the Cache", responseContainer = "ResponseEntity", response = Bearbeitet.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @@ -88,10 +90,10 @@ public class Controller { @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose @RequestMapping(value = "/api/checkStation", method = RequestMethod.PUT, produces = "application/json") @ResponseBody - public ResponseEntity checkStation(@RequestParam String token, - @RequestParam String cacheID, - @RequestParam String stationID, - @RequestParam String durchgefuehrterCacheID) { + public ResponseEntity checkStation(@ApiParam(value = "JWT Token indentifiying the cser", required = true) @RequestParam String token, + @ApiParam(value = "The CacheID from the scanned QR Code", required = true) @RequestParam String cacheID, + @ApiParam(value = "The StationID from the scanned QR Code", required = true) @RequestParam String stationID, + @ApiParam(value = "The CacheID from the cache the user does at the time scanning the code", required = true)@RequestParam String durchgefuehrterCacheID) { //---------------------- //Verify token ResponseEntity tokenVerification = VerificationUtil.verifyToken(token); @@ -233,45 +235,49 @@ public class Controller { } - @ApiOperation(value = "Creates a new Cache") + @ApiOperation(value = "Creates a new Cache", response = String.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { - @ApiResponse(code = 400, message = "Something wrong with the given Parameters") + @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), + @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/createCache", method = RequestMethod.POST, produces = "application/json") @ResponseBody - public ResponseEntity createCache(@RequestBody Cache cache) { + public ResponseEntity createCache(@ApiParam(value = "The cache to be created and saved in the database", required = true) @RequestBody Cache cache) { logger.warn("API CALL: api/createCache"); logger.debug("/api/allCaches PARAMETERS:\ncache: " + cache.getName()); return createCacheUtil(cache); } - @ApiOperation(value = "Edits a Cache") + @ApiOperation(value = "Edits a Cache", responseContainer = "Body of ResponseEntity", response = String.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @ApiResponse(code = 401, message = "JWT Token expired"), - @ApiResponse(code = 400, message = "Something wrong with the given Parameters") + @ApiResponse(code = 400, message = "Something went wrong at verification") }) @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(@ApiParam(value = "The edited cache", required = true) @RequestBody Cache newCache) { logger.warn("API CALL: /api/editCache"); logger.debug("/api/editCache PARAMETERS:\nnewCache: " + newCache.getName()); return editCacheUtil(newCache); } - @ApiOperation(value = "Checks if the given User has an admin role") + @ApiOperation(value = "Checks if the given User has an admin role", response = Boolean.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/checkAdmin", method = RequestMethod.GET, produces = "application/json") @ResponseBody - public ResponseEntity checkAdmin(@RequestParam String token) { + public ResponseEntity checkAdmin(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token) { ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -299,9 +305,12 @@ public class Controller { return ResponseEntity.status(401).body(false); } - @ApiOperation(value = "Returns all Stations") + @ApiOperation(value = "Returns all Stations", response = Station.class, responseContainer = "List in Body of ResponseEntity") @ApiResponses(value = { - @ApiResponse(code = 404, message = "Database error") + @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), + @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/getAllStations", method = RequestMethod.GET, produces = "application/json") @@ -312,29 +321,33 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll())); } - @ApiOperation(value = "Deletes a Cache") + @ApiOperation(value = "Deletes a Cache", responseContainer = "Body of ResponseEntity", response = Boolean.class) @ApiResponses(value = { - @ApiResponse(code = 404, message = "Database error") + @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), + @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/deleteCache", method = {RequestMethod.DELETE}, produces = "application/json") @ResponseBody - public ResponseEntity deleteCache(@RequestParam String cacheID) { + public ResponseEntity deleteCache(@ApiParam(value = "The cache ID to be deleted", required = true) @RequestParam String cacheID) { logger.warn("API CALL: /api/deleteCache"); logger.debug("/api/deleteCache: PARAMETERS:\ncacheID: " + cacheID); return deleteCacheUtil(cacheID); } - @ApiOperation(value = "Returns all Caches finished/started by a given User") + @ApiOperation(value = "Returns all Caches finished/started by a given User", response = Bearbeitet.class, responseContainer = "List in Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/getMyCaches", method = RequestMethod.GET, produces = "application/json") @ResponseBody - public ResponseEntity getMyCaches(@RequestParam String token) { + public ResponseEntity getMyCaches(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token) { logger.warn("API CALL: /api/getMyCaches"); logger.debug("/api/getMyCaches: PARAMETERS:\ntoken: " + token); @@ -375,14 +388,17 @@ public class Controller { } } - @ApiOperation(value = "Returns the rankinglist") + @ApiOperation(value = "Returns the rankinglist", response = RankingListHelper.class, responseContainer = "List in Body of ResponseEntity") @ApiResponses(value = { - @ApiResponse(code = 404, message = "Database error") + @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), + @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/getRankingList", method = RequestMethod.GET, produces = "application/json") @ResponseBody - public ResponseEntity getRankingList(@RequestParam(value = "token", defaultValue = "null") String token) { + public ResponseEntity getRankingList(@ApiParam(value = "JWT Token indentifiying the User", required = false) @RequestParam(value = "token", defaultValue = "null") String token) { logger.warn("API CALL: /api/getRankingList"); logger.debug("/api/getRankingList: PARAMETERS: -"); @@ -401,7 +417,7 @@ public class Controller { logger.debug("/api/getRankingList Converted Objects to RankingListHelper"); logger.debug("/api/getRankingList RankingList: " + new GsonBuilder().setPrettyPrinting().create().toJson(sendBackUsers)); - if(!token.equals("null")) { + if (!token.equals("null")) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -422,16 +438,16 @@ public class Controller { User user = (User) getUser.getBody(); boolean userAlreadyInRankingList = false; - for (RankingListHelper rankingListHelper: sendBackUsers) { + for (RankingListHelper rankingListHelper : sendBackUsers) { logger.debug("RankingList Helper " + rankingListHelper.getUsername()); logger.debug("User: " + user.getUsername()); - if(rankingListHelper.getUsername().equals(user.getEmail())){ + if (rankingListHelper.getUsername().equals(user.getEmail())) { userAlreadyInRankingList = true; break; } } - if(!userAlreadyInRankingList) { + if (!userAlreadyInRankingList) { ResponseEntity singlePlace = getRankingPlace(user.getEmail()); if (singlePlace.getStatusCodeValue() == 200) { @@ -444,9 +460,12 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers)); } - @ApiOperation(value = "Returns the Team Rankinglist") + @ApiOperation(value = "Returns the Team Rankinglist", response = TeamRankingListHelper.class, responseContainer = "List in Body of ResponseEntity") @ApiResponses(value = { - @ApiResponse(code = 404, message = "Database error") + @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), + @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/getTeamRankingList", method = RequestMethod.GET, produces = "application/json") @@ -472,16 +491,17 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(sendBackTeams)); } - @ApiOperation(value = "Returns a user from a given token") + @ApiOperation(value = "Returns a user from a given token", response = User.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/getUser", method = RequestMethod.GET, produces = "application/json") @ResponseBody - public ResponseEntity getUser(@RequestParam String token) { + public ResponseEntity getUser(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token) { logger.warn("API CALL: /api/getUser"); logger.debug("/api/getUser: PARAMETERS:\ntoken: " + token); @@ -518,17 +538,18 @@ public class Controller { } } - @ApiOperation(value = "Creates a new Team") + @ApiOperation(value = "Creates a new Team", response = Team.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/createTeam", method = RequestMethod.POST, produces = "application/json") @ResponseBody - public ResponseEntity createTeam(@RequestParam String token, - @RequestParam String name) { + public ResponseEntity createTeam(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, + @ApiParam(value = "Name of the team to be created", required = true) @RequestParam String name) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -573,17 +594,18 @@ public class Controller { } //--------- - @ApiOperation(value = "Lets the user join a Team") + @ApiOperation(value = "Lets the user join a Team", response = Team.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/joinTeam", method = RequestMethod.PUT, produces = "application/json") @ResponseBody - public ResponseEntity joinTeam(@RequestParam String token, - @RequestParam String teamID) { + public ResponseEntity joinTeam(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, + @ApiParam(value = "Team id of the team the user wants to join", required = true) @RequestParam String teamID) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -644,16 +666,17 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(team)); } - @ApiOperation(value = "Removes the user from the Team") + @ApiOperation(value = "Removes the user from the Team", responseContainer = "Body of ResponseEntity", response = String.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/leaveTeam", method = {RequestMethod.PUT, RequestMethod.GET}, produces = "application/json") @ResponseBody - public ResponseEntity leaveTeam(@RequestParam String token) { + public ResponseEntity leaveTeam(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -715,17 +738,18 @@ public class Controller { return ResponseEntity.status(200).body("Ok"); } - @ApiOperation(value = "Sends a Team Invite to the invitedUserEmail from the User (token)") + @ApiOperation(value = "Sends a Team Invite to the invitedUserEmail from the User (token)", responseContainer = "Body of ResponseEntity", response = String.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/sendTeamInvite", method = RequestMethod.POST, produces = "application/json") @ResponseBody - public ResponseEntity sendTeamInvite(@RequestParam String token, - @RequestParam String invitedUserEmail) { + public ResponseEntity sendTeamInvite(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, + @ApiParam(value = "The email of the invited User", required = true)@RequestParam String invitedUserEmail) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -787,16 +811,17 @@ public class Controller { return ResponseEntity.status(200).body("OK"); } - @ApiOperation(value = "Returns all User invites for a specific User") + @ApiOperation(value = "Returns all User invites for a specific User", response = TeamInvite.class, responseContainer = "List in Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/getMyTeamInvites", method = RequestMethod.GET, produces = "application/json") @ResponseBody - public ResponseEntity getMyTeamInvites(@RequestParam String token) { + public ResponseEntity getMyTeamInvites(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -833,17 +858,18 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(teamInvitesList)); } - @ApiOperation(value = "Removes a team invite from a user (called if a user declined a team invite)") + @ApiOperation(value = "Removes a team invite from a user (called if a user declined a team invite)", response = String.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/deleteTeamInvite", method = RequestMethod.DELETE, produces = "application/json") @ResponseBody - public ResponseEntity deleteTeamInvite(@RequestParam String token, - @RequestParam String teamInviteID) { + public ResponseEntity deleteTeamInvite(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, + @ApiParam(value = "The id of the TeamInvite to be deletd", required = true) @RequestParam String teamInviteID) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -865,17 +891,18 @@ public class Controller { return ResponseEntity.status(200).body("OK"); } - @ApiOperation(value = "Sets the team status") + @ApiOperation(value = "Sets the team status", responseContainer = "Body of ResponseEntity", response = String.class) @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/setTeamStatus", method = RequestMethod.PUT, produces = "application/json") @ResponseBody - public ResponseEntity setTeamStatus(@RequestParam String token, - @RequestParam String teamStatus) { + public ResponseEntity setTeamStatus(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, + @ApiParam(value = "The new team status", required = true) @RequestParam String teamStatus) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -916,39 +943,46 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(teamStatus)); } - @ApiOperation(value = "Returns a team by a name") + @ApiOperation(value = "Returns a team by a name", response = Team.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), + @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/getTeam", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getTeam(@RequestParam String name) { + public ResponseEntity getTeam(@ApiParam(value = "The name of the team", required = true) @RequestParam String name) { ResponseEntity responseEntity = FinderUtil.findTeamByName(name); return responseEntity; } - @ApiOperation(value = "Returns all teammembers by the team name") + @ApiOperation(value = "Returns all teammembers by the team name", response = User.class, responseContainer = "List in Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), + @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/getTeamMembers", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getTeamMembers(@RequestParam String name) { + public ResponseEntity getTeamMembers(@ApiParam(value = "The name of the team") @RequestParam String name) { return FinderUtil.findTeammemberByTeamName(name); } - @ApiOperation(value = "Returns the station the user is currently at (for a specific cache)") + @ApiOperation(value = "Returns the station the user is currently at (for a specific cache)", response = Station.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/getCurrentStation", method = RequestMethod.GET, produces = "application/json") @ResponseBody - public ResponseEntity getStationFromUserAndCache(@RequestParam String token, - @RequestParam String cacheID) { + public ResponseEntity getStationFromUserAndCache(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, + @ApiParam(value = "The Cache id for the searched station", required = true) @RequestParam String cacheID) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -982,27 +1016,29 @@ public class Controller { 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") + @ApiOperation(value = "Returns the ranking place on the leaderboard for a specific user", response = Integer.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/getRankingPlace", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getRankingPlace(@RequestParam String email) { + public ResponseEntity getRankingPlace(@ApiParam(value = "The email of the user as unique identifier", required = true)@RequestParam String email) { return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(email)); } - @ApiOperation(value = "Returns startstations and all other stations the user already visited as POIS") + @ApiOperation(value = "Returns startstations and all other stations the user already visited as POIS", response = POI.class, responseContainer = "Array in Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/getMyStationPOIS", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getMyStationPOIS(@RequestParam String token) { + public ResponseEntity getMyStationPOIS(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -1060,15 +1096,16 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(pois)); } - @ApiOperation(value = "Returns the Team of a user") + @ApiOperation(value = "Returns the Team of a user", response = Team.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/getTeamOfUser", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity getTeamOfUser(@RequestParam String token) { + public ResponseEntity getTeamOfUser(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token) { // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -1093,15 +1130,17 @@ public class Controller { return ResponseEntity.status(200).body(user_info.getTeam()); } - @ApiOperation(value = "Returns the Team of a user") + @ApiOperation(value = "Returns the Team of a user", response = POI.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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) { + public ResponseEntity getCurrentStationMap(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, + @ApiParam(value = "Cache id of the searched station", required = true) @RequestParam String cacheID) { logger.warn("API CALL: /api/getCurrentStationMap"); @@ -1162,15 +1201,16 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(poi)); } - @ApiOperation(value = "Resets the rankinglist") + @ApiOperation(value = "Resets the rankinglist", response = HttpStatus.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/resetRankingList", method = RequestMethod.GET, produces = "application/json") - public ResponseEntity resetRankingList(@RequestParam String token) { + public ResponseEntity resetRankingList(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token) { logger.warn("API CALL: /api/resetRankingList"); // verify user @@ -1216,15 +1256,17 @@ public class Controller { } } - @ApiOperation(value = "Deletes the bearbeitet entry from a User from a Cache") + @ApiOperation(value = "Deletes the bearbeitet entry from a User from a Cache", response = String.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/deleteCacheForUser", method = RequestMethod.DELETE, produces = "application/json") - public ResponseEntity deleteCacheForUser(@RequestParam String token, @RequestParam String cacheID) { + public ResponseEntity deleteCacheForUser(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, + @ApiParam(value = "The cache id for the cache to be deleted", required = true) @RequestParam String cacheID) { logger.warn("API CALL: /api/deleteCacheForUser"); // verify user @@ -1284,15 +1326,17 @@ public class Controller { } - @ApiOperation(value = "Resets the points of a single User ") + @ApiOperation(value = "Resets the points of a single User", response = HttpStatus.class, responseContainer = "Body of ResponseEntity") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @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/resetSingleUser", method = RequestMethod.PUT, produces = "application/json") - public ResponseEntity resetSingleUser(@RequestParam String token, @RequestParam String username) { + public ResponseEntity resetSingleUser(@ApiParam(value = "JWT Token indentifiying the User (Admin in this case)", required = true) @RequestParam String token, + @ApiParam(value = "The username of the user to be reseted", required = true) @RequestParam String username) { logger.debug("API CALL: /api/resetSingleUser"); // verify user ResponseEntity verifyToken = VerificationUtil.verifyToken(token); @@ -1326,7 +1370,7 @@ public class Controller { User deleteUser = userRepository.findByEmail(username); - if(deleteUser == null) { + if (deleteUser == null) { return ResponseEntity.status(400).body("Es wurde kein User mit dieser Email gefunden."); } @@ -1348,6 +1392,7 @@ public class Controller { @ApiOperation(value = "Test method (Changes its purpose often)") @ApiResponses(value = { @ApiResponse(code = 404, message = "Database error"), + @ApiResponse(code = 400, message = "Given Station is NOT the correct following station"), @ApiResponse(code = 401, message = "JWT Token expired"), @ApiResponse(code = 400, message = "Something went wrong at verification") }) diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/Bearbeitet.java b/src/main/java/hhn/labsw/bugageocaching/entities/Bearbeitet.java index 8b1f3dc..b866f3e 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/Bearbeitet.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/Bearbeitet.java @@ -1,6 +1,8 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.ApiModelProperty; + import javax.persistence.*; import javax.validation.constraints.NotNull; @@ -10,18 +12,23 @@ public class Bearbeitet { @Id @GeneratedValue + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; @OneToOne + @ApiModelProperty(notes = "The User (Foreign Key)") private User user; @OneToOne + @ApiModelProperty(notes = "The Cache (Foreign Key)") private Cache cache; @OneToOne + @ApiModelProperty(notes = "The cacheAccessDefinition (Foreign Key)") private CacheAccesDefinition cacheAccesDefinition; @OneToOne + @ApiModelProperty(notes = "The current Station (Foreign Key)") private Station aktuelleStation; public int getId() { diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/CacheAccesDefinition.java b/src/main/java/hhn/labsw/bugageocaching/entities/CacheAccesDefinition.java index e3dd2dc..9b548ae 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/CacheAccesDefinition.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/CacheAccesDefinition.java @@ -1,6 +1,8 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.ApiModelProperty; + import javax.persistence.*; @Entity @@ -9,8 +11,10 @@ public class CacheAccesDefinition { @Id @GeneratedValue + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; + @ApiModelProperty(notes = "The description for the CacheAcessDefinition") private String description; public int getId() { diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/Reward.java b/src/main/java/hhn/labsw/bugageocaching/entities/Reward.java index c83cc88..6accc98 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/Reward.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/Reward.java @@ -1,6 +1,8 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.ApiModelProperty; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -12,8 +14,10 @@ public class Reward { @Id @GeneratedValue + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; + @ApiModelProperty(notes = "The description for the reward") private String rewardDescription; public Reward() { diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/Role.java b/src/main/java/hhn/labsw/bugageocaching/entities/Role.java index 3e4a9c5..171aee7 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/Role.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/Role.java @@ -1,5 +1,8 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModelProperty; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -9,8 +12,11 @@ public class Role { @Id @GeneratedValue + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; + @ApiModelProperty(notes = "The name of the role") private String name; + @ApiModelProperty(notes = "The domain of the role (e.g. geocaching, flowertours...)") private String domain; public Role() { diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/Station.java b/src/main/java/hhn/labsw/bugageocaching/entities/Station.java index 31bc0eb..eacb1d7 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/Station.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/Station.java @@ -1,6 +1,8 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.ApiModelProperty; + import javax.persistence.*; import javax.validation.constraints.NotNull; @@ -10,22 +12,28 @@ public class Station { @Id @GeneratedValue + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; @NotNull + @ApiModelProperty(notes = "The riddle for the Station") private String description; @NotNull + @ApiModelProperty(notes = "The longitude of the position for the station") private double longitude; @NotNull + @ApiModelProperty(notes = "The latitude of the position for the station") private double lattitude; @Column(unique = true) @NotNull + @ApiModelProperty(notes = "The unique code for a Station (needed for the QR Code)") private int code; @NotNull + @ApiModelProperty(notes = "The solution for the riddle of the station") private String solution; public Station() { diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/Team.java b/src/main/java/hhn/labsw/bugageocaching/entities/Team.java index 55b87d4..e8c5793 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/Team.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/Team.java @@ -1,5 +1,7 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.ApiModelProperty; + import javax.persistence.*; import java.util.ArrayList; import java.util.List; @@ -10,10 +12,13 @@ public class Team { @Id @GeneratedValue + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; + @ApiModelProperty(notes = "The name of the team") private String name; + @ApiModelProperty(notes = "The teamstatus") private String teamStatus; public int getId() { diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/TeamInvite.java b/src/main/java/hhn/labsw/bugageocaching/entities/TeamInvite.java index 22a3e30..e08d8d9 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/TeamInvite.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/TeamInvite.java @@ -1,5 +1,7 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.ApiModelProperty; + import javax.persistence.*; @Entity @@ -8,12 +10,15 @@ public class TeamInvite { @Id @GeneratedValue + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; @OneToOne + @ApiModelProperty(notes = "The user to be invited") private User user; @OneToOne + @ApiModelProperty(notes = "The team the user is invited to join") private Team team; public int getId() { diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/User.java b/src/main/java/hhn/labsw/bugageocaching/entities/User.java index 656a7f3..8974bc2 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/User.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/User.java @@ -1,5 +1,7 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.ApiModelProperty; + import javax.persistence.*; import java.util.Set; @@ -12,18 +14,24 @@ import java.util.List; public class User { @Id + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; + @ApiModelProperty(notes = "The username of the user") private String username; + @ApiModelProperty(notes = "The email of the user") private String email; + @ApiModelProperty(notes = "The password for the user") private String password; @ManyToMany + @ApiModelProperty(notes = "A List of roles for the User (e.g. Cacher, Admin...)") private List roles; @Transient + @ApiModelProperty(notes = "A copy of the password for confirmation (transient)") private String passwordConfirm; public int getId() { diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java b/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java index c74c428..0d82e2e 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java @@ -1,5 +1,6 @@ package hhn.labsw.bugageocaching.entities; +import io.swagger.annotations.ApiModelProperty; import org.hibernate.validator.constraints.UniqueElements; import org.springframework.context.annotation.Primary; @@ -14,15 +15,19 @@ public class User_Info implements Serializable { @Id @OneToOne + @ApiModelProperty(notes = "The User (Foreign Key)") private User user; @Id @GeneratedValue + @ApiModelProperty(notes = "The autogenerated ID (Primary Key)") private int id; + @ApiModelProperty(notes = "The rankingPointsSum for the user") private int rankingPointsSum; @ManyToOne + @ApiModelProperty(notes = "The team of the user (Foreign Key)") private Team team; diff --git a/src/main/java/hhn/labsw/bugageocaching/util/ThreadListener.java b/src/main/java/hhn/labsw/bugageocaching/util/ThreadListener.java new file mode 100644 index 0000000..c9500e6 --- /dev/null +++ b/src/main/java/hhn/labsw/bugageocaching/util/ThreadListener.java @@ -0,0 +1,46 @@ +package hhn.labsw.bugageocaching.util; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Enumeration; +import java.util.Set; + + +/** + * @author Paul Keller + * @version 1.0 + */ +@WebListener +public class ThreadListener implements ServletContextListener { + @Override + public void contextDestroyed(ServletContextEvent arg0) { + //Get all registered drivers + Enumeration drivers = DriverManager.getDrivers(); + Driver d = null; + //as long as there are any registered drivers left - unregister them + while(drivers.hasMoreElements()) { + try { + d = drivers.nextElement(); + DriverManager.deregisterDriver(d); + } catch(SQLException ex) { + //Log any exception while unregistering drivers - shouldn't occure. + } + } + //Get all Threads that are running + Set threadSet = Thread.getAllStackTraces().keySet(); + //convert them to an array + Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); + //for all threads, only stop threads that have the name "Abandoned connection cleanup thread" - a mysql connection thread + for(Thread t: threadArray) { + if(t.getName().contains("Abandoned connection cleanup thread")) { + synchronized (t) { + t.stop(); + } + } + } + } +} diff --git a/swagger.json b/swagger.json index cbb2ccf..32f35ef 100644 --- a/swagger.json +++ b/swagger.json @@ -1235,19 +1235,16 @@ "tags": [ "basic-error-controller" ], - "summary": "error", - "operationId": "errorUsingGET", + "summary": "errorHtml", + "operationId": "errorHtmlUsingGET", "produces": [ - "*/*" + "text/html" ], "responses": { "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "object" - } + "$ref": "#/definitions/ModelAndView" } } }, @@ -1257,22 +1254,19 @@ "tags": [ "basic-error-controller" ], - "summary": "error", - "operationId": "errorUsingHEAD", + "summary": "errorHtml", + "operationId": "errorHtmlUsingHEAD", "consumes": [ "application/json" ], "produces": [ - "*/*" + "text/html" ], "responses": { "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "object" - } + "$ref": "#/definitions/ModelAndView" } } }, @@ -1282,22 +1276,19 @@ "tags": [ "basic-error-controller" ], - "summary": "error", - "operationId": "errorUsingPOST", + "summary": "errorHtml", + "operationId": "errorHtmlUsingPOST", "consumes": [ "application/json" ], "produces": [ - "*/*" + "text/html" ], "responses": { "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "object" - } + "$ref": "#/definitions/ModelAndView" } } }, @@ -1307,22 +1298,19 @@ "tags": [ "basic-error-controller" ], - "summary": "error", - "operationId": "errorUsingPUT", + "summary": "errorHtml", + "operationId": "errorHtmlUsingPUT", "consumes": [ "application/json" ], "produces": [ - "*/*" + "text/html" ], "responses": { "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "object" - } + "$ref": "#/definitions/ModelAndView" } } }, @@ -1332,19 +1320,16 @@ "tags": [ "basic-error-controller" ], - "summary": "error", - "operationId": "errorUsingDELETE", + "summary": "errorHtml", + "operationId": "errorHtmlUsingDELETE", "produces": [ - "*/*" + "text/html" ], "responses": { "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "object" - } + "$ref": "#/definitions/ModelAndView" } } }, @@ -1354,22 +1339,19 @@ "tags": [ "basic-error-controller" ], - "summary": "error", - "operationId": "errorUsingOPTIONS", + "summary": "errorHtml", + "operationId": "errorHtmlUsingOPTIONS", "consumes": [ "application/json" ], "produces": [ - "*/*" + "text/html" ], "responses": { "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "object" - } + "$ref": "#/definitions/ModelAndView" } } }, @@ -1379,22 +1361,19 @@ "tags": [ "basic-error-controller" ], - "summary": "error", - "operationId": "errorUsingPATCH", + "summary": "errorHtml", + "operationId": "errorHtmlUsingPATCH", "consumes": [ "application/json" ], "produces": [ - "*/*" + "text/html" ], "responses": { "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "object" - } + "$ref": "#/definitions/ModelAndView" } } }, @@ -1673,4 +1652,4 @@ "title": "View" } } -} +} \ No newline at end of file