Started Logging Backend

This commit is contained in:
Maximilian Leopold 2019-06-24 20:51:54 +02:00
parent 1b2cdd3605
commit 9580cbac88
2 changed files with 51 additions and 1 deletions

View File

@ -94,78 +94,104 @@ public class Controller {
@ApiParam(value = "The CacheID from the scanned QR Code", required = true) @RequestParam String cacheID, @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 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) { @ApiParam(value = "The CacheID from the cache the user does at the time scanning the code", required = true)@RequestParam String durchgefuehrterCacheID) {
logger.warn("API CALL: /api/checkStation");
logger.debug("/api/checkStation PARAMETERS:\ntoken: " + token);
logger.debug("cacheID: " + cacheID);
logger.debug("stationID: " + stationID);
logger.debug("durchgefuehrterCacheID: " + durchgefuehrterCacheID);
//---------------------- //----------------------
//Verify token //Verify token
ResponseEntity tokenVerification = VerificationUtil.verifyToken(token); ResponseEntity tokenVerification = VerificationUtil.verifyToken(token);
logger.debug("/api/checkStation trying to verificate token " + token);
//Error in token verification //Error in token verification
if (tokenVerification.getStatusCodeValue() != 200) { if (tokenVerification.getStatusCodeValue() != 200) {
logger.debug("/api/checkStation Couldnt verificate token: " + token);
return tokenVerification; return tokenVerification;
} }
Claims claims = (Claims) tokenVerification.getBody(); Claims claims = (Claims) tokenVerification.getBody();
logger.debug("/api/checkStation token " + token + " verified");
logger.debug("/api/checkStation trying to get user from token");
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims); ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) { if (getUser.getStatusCodeValue() != 200) {
logger.debug("/api/checkStation Couldnt find user entity from claim: " + getUser);
return getUser; return getUser;
} }
User user = (User) getUser.getBody(); User user = (User) getUser.getBody();
logger.debug("/api/checkStation Got User " + user.getEmail());
//---------------------- //----------------------
//---------------------- //----------------------
//Get Cache //Get Cache
logger.debug("/api/checkStation trying to find cache from id " + cacheID);
ResponseEntity getCache = FinderUtil.findCacheById(cacheID); ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
if (getCache.getStatusCodeValue() != 200) { if (getCache.getStatusCodeValue() != 200) {
logger.debug("/api/checkStation couldnt find cache by id: " + cacheID);
return getCache; return getCache;
} }
Cache cache = (Cache) getCache.getBody(); Cache cache = (Cache) getCache.getBody();
logger.debug("/api/checkStation Got cache: " + cache.getName());
//---------------------- //----------------------
//---------------------- //----------------------
//Get durchgeführter Cache //Get durchgeführter Cache
logger.debug("/api/checkStation trying to get durchgeführterCache by cache id: " + durchgefuehrterCacheID);
ResponseEntity getDurchgefuehrterCache = FinderUtil.findCacheById(durchgefuehrterCacheID); ResponseEntity getDurchgefuehrterCache = FinderUtil.findCacheById(durchgefuehrterCacheID);
if (getDurchgefuehrterCache.getStatusCodeValue() != 200) { if (getDurchgefuehrterCache.getStatusCodeValue() != 200) {
logger.debug("/api/checkStation couldnt find cache by id: " + durchgefuehrterCacheID);
return getDurchgefuehrterCache; return getDurchgefuehrterCache;
} }
Cache durchgefuehrterCache = (Cache) getDurchgefuehrterCache.getBody(); Cache durchgefuehrterCache = (Cache) getDurchgefuehrterCache.getBody();
logger.debug("/api/checkStation found durchgeführterCache from id: " + durchgefuehrterCacheID + " name: " +durchgefuehrterCache.getName()ß);
//---------------------- //----------------------
//---------------------- //----------------------
//Get Station //Get Station
logger.debug("/api/checkStation Trying to find station by id: " + stationID);
ResponseEntity getStation = FinderUtil.findStationById(stationID); ResponseEntity getStation = FinderUtil.findStationById(stationID);
if (getStation.getStatusCodeValue() != 200) { if (getStation.getStatusCodeValue() != 200) {
logger.debug("/api/checkStation Error trying to find station by id: " + stationID);
return getStation; return getStation;
} }
Station station = (Station) getStation.getBody(); Station station = (Station) getStation.getBody();
logger.debug("/api/checkStation Found station by id: " + stationID + " des.: " + station.getDescription());
//---------------------- //----------------------
System.out.println(cache.getName()); System.out.println(cache.getName());
System.out.println(durchgefuehrterCache.getName()); System.out.println(durchgefuehrterCache.getName());
if (!cacheID.equals(durchgefuehrterCacheID)) { if (!cacheID.equals(durchgefuehrterCacheID)) {
logger.debug("/api/checkStations cacheID != durchgeführterCacheID -> Error");
return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station"); return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station");
} }
if (!cache.getStationen().contains(station)) { if (!cache.getStationen().contains(station)) {
logger.debug("/api/checkStation cache " + cacheID + " doesnt contain station " + stationID + " -> Error");
return ResponseEntity.status(400).body("Die gescannte Station gehört nicht zu dem gerade bearbeiteten Cache"); return ResponseEntity.status(400).body("Die gescannte Station gehört nicht zu dem gerade bearbeiteten Cache");
} }
//---------------------- //----------------------
//Get Bearbeitet entry //Get Bearbeitet entry
logger.debug("/api/checkStation trying to get bearbeitet entry for user " + user.getEmail() + " and cache " + cache.getId());
ResponseEntity getBearbeitet = FinderUtil.findBearbeitetByUserAndCache(user, cache); ResponseEntity getBearbeitet = FinderUtil.findBearbeitetByUserAndCache(user, cache);
if (getBearbeitet.getStatusCodeValue() != 200) { if (getBearbeitet.getStatusCodeValue() != 200) {
logger.debug("/api/checkStation got bearbeitet entry for user " + user.getEmail() + " and cache " + cache.getId());
if (cache.getStationen().get(0).equals(station)) { if (cache.getStationen().get(0).equals(station)) {
// start Cache // start Cache
logger.debug("/api/checkStation Start the cache " + cacheID + " for user " + user.getEmail());
System.out.println("Startstation"); System.out.println("Startstation");
Bearbeitet bearbeitet = new Bearbeitet(); Bearbeitet bearbeitet = new Bearbeitet();
bearbeitet.setUser(user); bearbeitet.setUser(user);
@ -176,6 +202,7 @@ public class Controller {
ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0"); ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0");
if (getCacheAccesDefinition.getStatusCodeValue() != 200) { if (getCacheAccesDefinition.getStatusCodeValue() != 200) {
logger.debug("/api/checkStation Couldnt receive cacheAccessDefinition 0 from Server");
return getCacheAccesDefinition; return getCacheAccesDefinition;
} }
@ -183,41 +210,51 @@ public class Controller {
//---------------------- //----------------------
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
logger.debug("/api/checkStation Save new bearbeitet entry, cache " + bearbeitet.getCache().getId() + ", user " + bearbeitet.getUser().getEmail());
bearbeitetRepository.save(bearbeitet); bearbeitetRepository.save(bearbeitet);
return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet)); return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet));
} else { } else {
logger.debug("/api/checkStation Couldnt receive bearbeitet");
return getBearbeitet; return getBearbeitet;
} }
} }
Bearbeitet bearbeitet = (Bearbeitet) getBearbeitet.getBody(); Bearbeitet bearbeitet = (Bearbeitet) getBearbeitet.getBody();
logger.debug("/api/checkStation Got bearbeitet entry, cache " + bearbeitet.getCache().getId() + ", user " + bearbeitet.getUser().getEmail());
//---------------------- //----------------------
Station aktuelleStation = bearbeitet.getAktuelleStation(); Station aktuelleStation = bearbeitet.getAktuelleStation();
if (aktuelleStation == null) { if (aktuelleStation == null) {
logger.debug("/api/checkStation Couldnt receive station from bearbeitet entry, cache " + bearbeitet.getCache().getId() + ", user " + bearbeitet.getUser().getEmail());
return ResponseEntity.status(400).body("Es gab einen Fehler. Bitte versuche es erneut oder kontaktiere einen Admin"); return ResponseEntity.status(400).body("Es gab einen Fehler. Bitte versuche es erneut oder kontaktiere einen Admin");
} }
logger.debug("/api/checkStation Got station "+ aktuelleStation.getDescription());
int i = cache.getStationen().indexOf(station); int i = cache.getStationen().indexOf(station);
if (i == 0) { if (i == 0) {
logger.debug("/api/checkStation The scanned station isnt the correct following station i=0");
return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station"); return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station");
} }
if (cache.getStationen().get(i - 1).equals(aktuelleStation)) { if (cache.getStationen().get(i - 1).equals(aktuelleStation)) {
bearbeitet.setAktuelleStation(station); bearbeitet.setAktuelleStation(station);
logger.debug("/api/checkStation Set station " + station.getId() + " as actual station");
if (i == cache.getStationen().size() - 1) { // letze Station erreicht if (i == cache.getStationen().size() - 1) { // letze Station erreicht
//---------------------- //----------------------
//Get CacheAccesDefinition //Get CacheAccesDefinition
ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("1"); ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("1");
if (getCacheAccesDefinition.getStatusCodeValue() != 200) { if (getCacheAccesDefinition.getStatusCodeValue() != 200) {
logger.debug("/api/checkStation Couldnt receive cacheAccessDefinition 1 from Server");
return getCacheAccesDefinition; return getCacheAccesDefinition;
} }
CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody(); CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody();
logger.debug("/api/checkStation Got cache Access Definition 1");
//---------------------- //----------------------
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
//Get User_Info //Get User_Info
@ -226,10 +263,13 @@ public class Controller {
//---------------------- //----------------------
user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints()); user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints());
user_infoRepository.save(user_info); user_infoRepository.save(user_info);
logger.debug("/api/checkStation Saved new rankingpoints (" + user_info.getRankingPointsSum() + ") for user " + user.getEmail());
} }
bearbeitetRepository.save(bearbeitet); bearbeitetRepository.save(bearbeitet);
logger.debug("/api/checkStation Saved bearbeitet entry, cache " + bearbeitet.getCache().getId() + ", user " + user.getEmail());
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet)); return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet));
} else { } else {
logger.debug("/api/checkStation Scanned station " + stationID + " isnt correct following station to station " + aktuelleStation);
return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station"); return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station");
} }
@ -384,6 +424,7 @@ public class Controller {
logger.debug("/api/getMyCaches Got all bearbeitet entreis of user: " + user.getEmail()); logger.debug("/api/getMyCaches Got all bearbeitet entreis of user: " + user.getEmail());
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList)); return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList));
} else { } else {
logger.warn("/api/getMyCaches Internal Server Error Line 427 Controller");
return ResponseEntity.status(404).body("Es gab einen Fehler. Bitte versuche es erneut oder kontaktiere einen Admin!"); return ResponseEntity.status(404).body("Es gab einen Fehler. Bitte versuche es erneut oder kontaktiere einen Admin!");
} }
} }
@ -550,6 +591,8 @@ public class Controller {
@ResponseBody @ResponseBody
public ResponseEntity createTeam(@ApiParam(value = "JWT Token indentifiying the User", required = true) @RequestParam String token, 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) { @ApiParam(value = "Name of the team to be created", required = true) @RequestParam String name) {
logger.warn("API CALL: /api/createTeam");
// verify user // verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token); ResponseEntity verifyToken = VerificationUtil.verifyToken(token);

View File

@ -12,4 +12,11 @@ debug=true
# logging level # logging level
logging.level.hhn.labsw.bugageocaching=DEBUG logging.level.hhn.labsw.bugageocaching=DEBUG
logging.level.root=WARN logging.level.root=WARN
logging.level.org.apache.tomcat=DEBUG
logging.level.org.apache.catalina=DEBUG
logging.level.org.apache=DEBUG
server.tomcat.accesslog.suffix=.log
server.tomcat.accesslog.prefix=buga19geocachinglog
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd
server.tomcat.accesslog.pattern=common