From b8a4cfd95e15c72eaf6a89e129edaadfbf33a1cc Mon Sep 17 00:00:00 2001
From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de>
Date: Tue, 30 Oct 2012 11:09:25 +0100
Subject: [PATCH] Improved code quality

---
 .../LoginAuthenticationFailureHandler.java    |   4 +-
 .../LoginAuthenticationSucessHandler.java     |   6 +-
 .../controller/AbstractController.java        |   8 +-
 .../controller/FeedbackController.java        |  37 +-
 .../arsnova/controller/LoginController.java   |  67 ++--
 .../controller/QuestionController.java        | 135 ++++----
 .../arsnova/controller/SessionController.java |  42 +--
 .../arsnova/controller/WelcomeController.java |   4 +-
 .../java/de/thm/arsnova/dao/CouchDBDao.java   | 318 +++++++++---------
 .../java/de/thm/arsnova/dao/IDatabaseDao.java |  45 ++-
 .../java/de/thm/arsnova/dao/package-info.java |   2 +-
 .../java/de/thm/arsnova/entities/Answer.java  |  52 +--
 .../de/thm/arsnova/entities/Authorize.java    |  10 +-
 .../de/thm/arsnova/entities/Feedback.java     |  12 +-
 14 files changed, 384 insertions(+), 358 deletions(-)

diff --git a/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java b/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java
index 72770e62..eb9e7472 100644
--- a/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java
+++ b/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java
@@ -50,8 +50,8 @@ public class LoginAuthenticationFailureHandler extends
 		redirectStrategy.sendRedirect(request, response, defaultFailureUrl);
 	}
 
-	public final void setDefaultFailureUrl(final String defaultFailureUrl) {
-		this.defaultFailureUrl = defaultFailureUrl;
+	public final void setDefaultFailureUrl(final String failureUrl) {
+		this.defaultFailureUrl = failureUrl;
 	}
 
 }
diff --git a/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java b/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java
index 11ea77fb..1dc072ee 100644
--- a/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java
+++ b/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 THM webMedia
- * 
+ *
  * This file is part of ARSnova.
  *
  * ARSnova is free software: you can redistribute it and/or modify
@@ -42,7 +42,7 @@ public class LoginAuthenticationSucessHandler extends
 		return referer + targetUrl;
 	}
 
-	public final void setTargetUrl(final String targetUrl) {
-		this.targetUrl = targetUrl;
+	public final void setTargetUrl(final String newTargetUrl) {
+		this.targetUrl = newTargetUrl;
 	}
 }
diff --git a/src/main/java/de/thm/arsnova/controller/AbstractController.java b/src/main/java/de/thm/arsnova/controller/AbstractController.java
index b8f04da0..3c379b33 100644
--- a/src/main/java/de/thm/arsnova/controller/AbstractController.java
+++ b/src/main/java/de/thm/arsnova/controller/AbstractController.java
@@ -14,21 +14,21 @@ import de.thm.arsnova.exceptions.UnauthorizedException;
 public class AbstractController {
 	@ResponseStatus(HttpStatus.NOT_FOUND)
 	@ExceptionHandler(NotFoundException.class)
-	public void handleNotFoundException(final Exception e, HttpServletRequest request) {
+	public void handleNotFoundException(final Exception e, final HttpServletRequest request) {
 	}
 
 	@ResponseStatus(HttpStatus.FORBIDDEN)
 	@ExceptionHandler(ForbiddenException.class)
-	public void handleForbiddenException(final Exception e, HttpServletRequest request) {
+	public void handleForbiddenException(final Exception e, final HttpServletRequest request) {
 	}
 
 	@ResponseStatus(HttpStatus.UNAUTHORIZED)
 	@ExceptionHandler(UnauthorizedException.class)
-	public void handleUnauthorizedException(final Exception e, HttpServletRequest request) {
+	public void handleUnauthorizedException(final Exception e, final HttpServletRequest request) {
 	}
 
 	@ResponseStatus(HttpStatus.NO_CONTENT)
 	@ExceptionHandler(NoContentException.class)
-	public void handleNoContentException(final Exception e, HttpServletRequest request) {
+	public void handleNoContentException(final Exception e, final HttpServletRequest request) {
 	}
 }
diff --git a/src/main/java/de/thm/arsnova/controller/FeedbackController.java b/src/main/java/de/thm/arsnova/controller/FeedbackController.java
index f79d4e05..05ad307e 100644
--- a/src/main/java/de/thm/arsnova/controller/FeedbackController.java
+++ b/src/main/java/de/thm/arsnova/controller/FeedbackController.java
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 THM webMedia
- * 
+ *
  * This file is part of ARSnova.
  *
  * ARSnova is free software: you can redistribute it and/or modify
@@ -35,33 +35,30 @@ import de.thm.arsnova.entities.Feedback;
 import de.thm.arsnova.entities.User;
 import de.thm.arsnova.services.IFeedbackService;
 import de.thm.arsnova.services.IUserService;
-import de.thm.arsnova.socket.ARSnovaSocketIOServer;
 
 @Controller
 public class FeedbackController extends AbstractController {
 
-	public static final Logger logger = LoggerFactory.getLogger(FeedbackController.class);
-
-	@Autowired
-	IFeedbackService feedbackService;
+	public static final Logger LOGGER = LoggerFactory.getLogger(FeedbackController.class);
 
 	@Autowired
-	IUserService userService;
+	private IFeedbackService feedbackService;
 
 	@Autowired
-	ARSnovaSocketIOServer server;
+	private IUserService userService;
 
 	@RequestMapping(value = "/session/{sessionkey}/feedback", method = RequestMethod.GET)
 	@ResponseBody
-	public Feedback getFeedback(@PathVariable String sessionkey) {
+	public final Feedback getFeedback(@PathVariable final String sessionkey) {
 		return feedbackService.getFeedback(sessionkey);
 	}
 
 	@RequestMapping(value = "/session/{sessionkey}/myfeedback", method = RequestMethod.GET)
 	@ResponseBody
-	public Integer getMyFeedback(@PathVariable String sessionkey, HttpServletResponse response) {
+	public final Integer getMyFeedback(@PathVariable final String sessionkey, final HttpServletResponse response) {
 		Integer value = feedbackService.getMyFeedback(sessionkey, userService.getCurrentUser());
-		if (value != null && value >= 0 && value <= 3) {
+
+		if (value != null && value >= Feedback.MIN_FEEDBACK_TYPE && value <= Feedback.MAX_FEEDBACK_TYPE) {
 			return value;
 		}
 		response.setStatus(HttpStatus.NOT_FOUND.value());
@@ -70,29 +67,29 @@ public class FeedbackController extends AbstractController {
 
 	@RequestMapping(value = "/session/{sessionkey}/feedbackcount", method = RequestMethod.GET)
 	@ResponseBody
-	public int getFeedbackCount(@PathVariable String sessionkey) {
+	public final int getFeedbackCount(@PathVariable final String sessionkey) {
 		return feedbackService.getFeedbackCount(sessionkey);
 	}
 
 	@RequestMapping(value = "/session/{sessionkey}/roundedaveragefeedback", method = RequestMethod.GET)
 	@ResponseBody
-	public long getAverageFeedbackRounded(
-		@PathVariable String sessionkey
-	) {
+	public final long getAverageFeedbackRounded(@PathVariable final String sessionkey) {
 		return feedbackService.getAverageFeedbackRounded(sessionkey);
 	}
-	
+
 	@RequestMapping(value = "/session/{sessionkey}/averagefeedback", method = RequestMethod.GET)
 	@ResponseBody
-	public double getAverageFeedback(
-		@PathVariable String sessionkey
-	) {
+	public final double getAverageFeedback(@PathVariable final String sessionkey) {
 		return feedbackService.getAverageFeedback(sessionkey);
 	}
 
 	@RequestMapping(value = "/session/{sessionkey}/feedback", method = RequestMethod.POST)
 	@ResponseBody
-	public Feedback postFeedback(@PathVariable String sessionkey, @RequestBody int value, HttpServletResponse response) {
+	public final Feedback postFeedback(
+			@PathVariable final String sessionkey,
+			@RequestBody final int value,
+			final HttpServletResponse response
+	) {
 		User user = userService.getCurrentUser();
 		if (feedbackService.saveFeedback(sessionkey, value, user)) {
 			Feedback feedback = feedbackService.getFeedback(sessionkey);
diff --git a/src/main/java/de/thm/arsnova/controller/LoginController.java b/src/main/java/de/thm/arsnova/controller/LoginController.java
index f1f6f2f4..8c608e01 100644
--- a/src/main/java/de/thm/arsnova/controller/LoginController.java
+++ b/src/main/java/de/thm/arsnova/controller/LoginController.java
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 THM webMedia
- * 
+ *
  * This file is part of ARSnova.
  *
  * ARSnova is free software: you can redistribute it and/or modify
@@ -56,91 +56,80 @@ import de.thm.arsnova.services.IUserService;
 @Controller
 public class LoginController extends AbstractController {
 
+	private static final int MAX_USERNAME_LENGTH = 15;
+	
 	@Autowired
-	TwitterProvider twitterProvider;
+	private TwitterProvider twitterProvider;
 
 	@Autowired
-	Google2Provider googleProvider;
+	private Google2Provider googleProvider;
 
 	@Autowired
-	FacebookProvider facebookProvider;
+	private FacebookProvider facebookProvider;
 
 	@Autowired
-	CasAuthenticationEntryPoint casEntryPoint;
+	private CasAuthenticationEntryPoint casEntryPoint;
 
 	@Autowired
-	IUserService userService;
+	private IUserService userService;
 
-	public static final Logger logger = LoggerFactory
-			.getLogger(LoginController.class);
+	public static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
 
 	@RequestMapping(method = RequestMethod.GET, value = "/doLogin")
-	public View doLogin(@RequestParam("type") String type,
-			@RequestParam(value = "user", required = false) String guestName,
-			HttpServletRequest request, HttpServletResponse response)
-			throws IOException, ServletException {
+	public final View doLogin(
+			@RequestParam("type") final String type,
+			@RequestParam(value = "user", required = false) final String guestName,
+			final HttpServletRequest request,
+			final HttpServletResponse response
+	) throws IOException, ServletException {
 		String referer = request.getHeader("referer");
 		request.getSession().setAttribute("ars-referer", referer);
 		if ("cas".equals(type)) {
 			casEntryPoint.commence(request, response, null);
 		} else if ("twitter".equals(type)) {
-			String authUrl = twitterProvider
-					.getAuthorizationUrl(new HttpUserSession(request));
+			String authUrl = twitterProvider.getAuthorizationUrl(new HttpUserSession(request));
 			return new RedirectView(authUrl);
 		} else if ("facebook".equals(type)) {
-			String authUrl = facebookProvider
-					.getAuthorizationUrl(new HttpUserSession(request));
+			String authUrl = facebookProvider.getAuthorizationUrl(new HttpUserSession(request));
 			return new RedirectView(authUrl);
 		} else if ("google".equals(type)) {
-			String authUrl = googleProvider
-					.getAuthorizationUrl(new HttpUserSession(request));
+			String authUrl = googleProvider.getAuthorizationUrl(new HttpUserSession(request));
 			return new RedirectView(authUrl);
 		} else if ("guest".equals(type)) {
 			List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
 			authorities.add(new SimpleGrantedAuthority("ROLE_GUEST"));
 			String username = "";
-			if (guestName != null && guestName.startsWith("Guest")
-					&& guestName.length() == 15) {
+			if (guestName != null && guestName.startsWith("Guest") && guestName.length() == MAX_USERNAME_LENGTH) {
 				username = guestName;
 			} else {
-				username = "Guest"
-						+ Sha512DigestUtils
-								.shaHex(request.getSession().getId())
-								.substring(0, 10);
+				username = "Guest" + Sha512DigestUtils.shaHex(request.getSession().getId()).substring(0, 10);
 			}
 			org.springframework.security.core.userdetails.User user = new org.springframework.security.core.userdetails.User(
 					username, "", true, true, true, true, authorities);
-			Authentication token = new UsernamePasswordAuthenticationToken(
-					user, null, authorities);
+			Authentication token = new UsernamePasswordAuthenticationToken(user, null, authorities);
 
 			SecurityContextHolder.getContext().setAuthentication(token);
-			request.getSession(true)
-					.setAttribute(
-							HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
-							SecurityContextHolder.getContext());
-			return new RedirectView((referer != null ? referer : "/")
-					+ "#auth/checkLogin");
+			request.getSession(true).setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
+					SecurityContextHolder.getContext());
+			return new RedirectView((referer != null ? referer : "/") + "#auth/checkLogin");
 		}
 		return null;
 	}
 
 	@RequestMapping(method = RequestMethod.GET, value = "/whoami")
 	@ResponseBody
-	public User whoami() {
+	public final User whoami() {
 		return userService.getCurrentUser();
 	}
 
 	@RequestMapping(method = RequestMethod.GET, value = "/logout")
-	public View doLogout(final HttpServletRequest request) {
-		Authentication auth = SecurityContextHolder.getContext()
-				.getAuthentication();
+	public final View doLogout(final HttpServletRequest request) {
+		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
 		request.getSession().invalidate();
 		SecurityContextHolder.clearContext();
 		if (auth instanceof CasAuthenticationToken) {
 			return new RedirectView("/j_spring_cas_security_logout");
 		}
-		return new RedirectView(
-				request.getHeader("referer") != null ? request
-						.getHeader("referer") : "/");
+		return new RedirectView(request.getHeader("referer") != null ? request.getHeader("referer") : "/");
 	}
 }
diff --git a/src/main/java/de/thm/arsnova/controller/QuestionController.java b/src/main/java/de/thm/arsnova/controller/QuestionController.java
index f1a035d1..f2d1baad 100644
--- a/src/main/java/de/thm/arsnova/controller/QuestionController.java
+++ b/src/main/java/de/thm/arsnova/controller/QuestionController.java
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 THM webMedia
- * 
+ *
  * This file is part of ARSnova.
  *
  * ARSnova is free software: you can redistribute it and/or modify
@@ -38,28 +38,22 @@ import de.thm.arsnova.entities.Question;
 import de.thm.arsnova.exceptions.ForbiddenException;
 import de.thm.arsnova.exceptions.NotFoundException;
 import de.thm.arsnova.services.IQuestionService;
-import de.thm.arsnova.services.IUserService;
-import de.thm.arsnova.socket.ARSnovaSocketIOServer;
 
 @Controller
 public class QuestionController extends AbstractController {
 
-	public static final Logger logger = LoggerFactory
-			.getLogger(QuestionController.class);
-
-	@Autowired
-	IQuestionService questionService;
-
-	@Autowired
-	IUserService userService;
+	public static final Logger LOGGER = LoggerFactory.getLogger(QuestionController.class);
 
 	@Autowired
-	ARSnovaSocketIOServer server;
+	private IQuestionService questionService;
 
 	@RequestMapping(value = "/session/{sessionkey}/question/{questionId}", method = RequestMethod.GET)
 	@ResponseBody
-	public Question getQuestion(@PathVariable String sessionkey,
-			@PathVariable String questionId, HttpServletResponse response) {
+	public final Question getQuestion(
+			@PathVariable final String sessionkey,
+			@PathVariable final String questionId,
+			final HttpServletResponse response
+	) {
 		Question question = questionService.getQuestion(questionId, sessionkey);
 		if (question != null) {
 			return question;
@@ -71,8 +65,11 @@ public class QuestionController extends AbstractController {
 
 	@RequestMapping(value = "/session/{sessionkey}/question", method = RequestMethod.POST)
 	@ResponseBody
-	public void postQuestion(@PathVariable String sessionkey,
-			@RequestBody Question question, HttpServletResponse response) {
+	public final void postQuestion(
+			@PathVariable final String sessionkey,
+			@RequestBody final Question question,
+			final HttpServletResponse response
+	) {
 		if (!sessionkey.equals(question.getSession())) {
 			response.setStatus(HttpStatus.PRECONDITION_FAILED.value());
 			return;
@@ -87,78 +84,94 @@ public class QuestionController extends AbstractController {
 		return;
 	}
 
-	@RequestMapping(value = { "/getSkillQuestions/{sessionkey}",
-			"/session/{sessionkey}/skillquestions" }, method = RequestMethod.GET)
+	@RequestMapping(value = { "/getSkillQuestions/{sessionkey}", "/session/{sessionkey}/skillquestions" }, method = RequestMethod.GET)
 	@ResponseBody
-	public List<Question> getSkillQuestions(@PathVariable String sessionkey,
-			HttpServletResponse response) {
-		List<Question> questions = questionService
-				.getSkillQuestions(sessionkey);
+	public final List<Question> getSkillQuestions(
+			@PathVariable final String sessionkey,
+			final HttpServletResponse response
+	) {
+		List<Question> questions = questionService.getSkillQuestions(sessionkey);
 		if (questions == null || questions.isEmpty()) {
 			response.setStatus(HttpStatus.NOT_FOUND.value());
 			return null;
 		}
-		logger.info(questions.toString());
+		LOGGER.info(questions.toString());
 		return questions;
 	}
-	
-	@RequestMapping(value="/session/{sessionKey}/questionids", method=RequestMethod.GET)
+
+	@RequestMapping(value = "/session/{sessionKey}/questionids", method = RequestMethod.GET)
 	@ResponseBody
-	public List<String> getQuestionIds(@PathVariable String sessionKey, HttpServletResponse response) {
+	public final List<String> getQuestionIds(
+			@PathVariable final String sessionKey,
+			final HttpServletResponse response
+	) {
 		List<String> questions = questionService.getQuestionIds(sessionKey);
-		if(questions == null || questions.isEmpty()) {
+		if (questions == null || questions.isEmpty()) {
 			throw new NotFoundException();
 		}
-		logger.info(questions.toString());
-		return questions;		
+		LOGGER.info(questions.toString());
+		return questions;
 	}
-	
-	@RequestMapping(value="/session/{sessionKey}/questions/{questionId}", method=RequestMethod.DELETE)
+
+	@RequestMapping(value = "/session/{sessionKey}/questions/{questionId}", method = RequestMethod.DELETE)
 	@ResponseBody
-	public void deleteAnswersAndQuestion(@PathVariable String sessionKey, @PathVariable String questionId, HttpServletResponse response) {
+	public final void deleteAnswersAndQuestion(
+			@PathVariable final String sessionKey,
+			@PathVariable final String questionId,
+			final HttpServletResponse response
+	) {
 		questionService.deleteQuestion(sessionKey, questionId);
 	}
-	
-	@RequestMapping(value="/session/{sessionKey}/questions/unanswered", method=RequestMethod.GET)
+
+	@RequestMapping(value = "/session/{sessionKey}/questions/unanswered", method = RequestMethod.GET)
 	@ResponseBody
-	public List<String> getUnAnsweredSkillQuestions(@PathVariable String sessionKey, HttpServletResponse response) {
+	public final List<String> getUnAnsweredSkillQuestions(
+			@PathVariable final String sessionKey,
+			final HttpServletResponse response
+	) {
 		List<String> answers = questionService.getUnAnsweredQuestions(sessionKey);
-		if(answers == null || answers.isEmpty()) {
+		if (answers == null || answers.isEmpty()) {
 			throw new NotFoundException();
 		}
-		logger.info(answers.toString());
+		LOGGER.info(answers.toString());
 		return answers;
 	}
-	
+
 	/**
 	 * returns a JSON document which represents the given answer of a question.
+	 *
 	 * @param sessionKey
 	 *            Session Keyword to which the question belongs to
 	 * @param questionId
 	 *            CouchDB Question ID for which the given answer should be
 	 *            retrieved
-	 * @return JSON Document of {@link Answer} or {@link NotFoundException} 
-	 * @throws NotFoundException if
-	 *         wrong session, wrong question or no answer was given by the
-	 *         current user
-	 * @throws ForbiddenException if not logged in
+	 * @return JSON Document of {@link Answer} or {@link NotFoundException}
+	 * @throws NotFoundException
+	 *             if wrong session, wrong question or no answer was given by
+	 *             the current user
+	 * @throws ForbiddenException
+	 *             if not logged in
 	 */
-	@RequestMapping(value="/session/{sessionKey}/question/{questionId}/myanswer", method=RequestMethod.GET)
+	@RequestMapping(value = "/session/{sessionKey}/question/{questionId}/myanswer", method = RequestMethod.GET)
 	@ResponseBody
-	public Answer getMyAnswer(@PathVariable String sessionKey, @PathVariable String questionId, HttpServletResponse response) {
+	public final Answer getMyAnswer(
+			@PathVariable final String sessionKey,
+			@PathVariable final String questionId,
+			final HttpServletResponse response
+	) {
 		Answer answer = questionService.getMyAnswer(sessionKey, questionId);
-		if(answer == null) {
+		if (answer == null) {
 			throw new NotFoundException();
 		}
 		return answer;
 	}
-	
+
 	/**
 	 * returns a list of {@link Answer}s encoded as a JSON document for a given
 	 * question id. In this case only {@link Answer} <tt>questionId</tt>,
 	 * <tt>answerText</tt>, <tt>answerSubject</tt> and <tt>answerCount</tt>
 	 * properties are set
-	 * 
+	 *
 	 * @param sessionKey
 	 *            Session Keyword to which the question belongs to
 	 * @param questionId
@@ -170,33 +183,41 @@ public class QuestionController extends AbstractController {
 	 * @throws ForbiddenException
 	 *             if not logged in
 	 */
-	@RequestMapping(value="/session/{sessionKey}/question/{questionId}/answers", method=RequestMethod.GET)
+	@RequestMapping(value = "/session/{sessionKey}/question/{questionId}/answers", method = RequestMethod.GET)
 	@ResponseBody
-	public List<Answer> getAnswers(@PathVariable String sessionKey, @PathVariable String questionId, HttpServletResponse response) {
+	public final List<Answer> getAnswers(
+			@PathVariable final String sessionKey,
+			@PathVariable final String questionId,
+			final HttpServletResponse response
+	) {
 		List<Answer> answers = questionService.getAnswers(sessionKey, questionId);
-		if(answers == null || answers.isEmpty()) {
+		if (answers == null || answers.isEmpty()) {
 			throw new NotFoundException();
 		}
 		return answers;
 	}
-	
+
 	/**
-	 * 
+	 *
 	 * @param sessionKey
 	 *            Session Keyword to which the question belongs to
 	 * @param questionId
 	 *            CouchDB Question ID for which the given answers should be
 	 *            retrieved
-	 * @return count of answers for given question id 
+	 * @return count of answers for given question id
 	 * @throws NotFoundException
 	 *             if wrong session or wrong question
 	 * @throws ForbiddenException
 	 *             if not logged in
 	 */
-	@RequestMapping(value="/session/{sessionKey}/question/{questionId}/answercount", method=RequestMethod.GET)
+	@RequestMapping(value = "/session/{sessionKey}/question/{questionId}/answercount", method = RequestMethod.GET)
 	@ResponseBody
-	public int getAnswerCount(@PathVariable String sessionKey, @PathVariable String questionId, HttpServletResponse response) {
+	public final int getAnswerCount(
+			@PathVariable final String sessionKey,
+			@PathVariable final String questionId,
+			final HttpServletResponse response
+	) {
 		return questionService.getAnswerCount(sessionKey, questionId);
 	}
-	
+
 }
diff --git a/src/main/java/de/thm/arsnova/controller/SessionController.java b/src/main/java/de/thm/arsnova/controller/SessionController.java
index e8bd7801..5df0665e 100644
--- a/src/main/java/de/thm/arsnova/controller/SessionController.java
+++ b/src/main/java/de/thm/arsnova/controller/SessionController.java
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 THM webMedia
- * 
+ *
  * This file is part of ARSnova.
  *
  * ARSnova is free software: you can redistribute it and/or modify
@@ -36,8 +36,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import de.thm.arsnova.entities.Feedback;
-import de.thm.arsnova.entities.Question;
 import de.thm.arsnova.entities.LoggedIn;
 import de.thm.arsnova.entities.Session;
 import de.thm.arsnova.entities.User;
@@ -48,46 +46,43 @@ import de.thm.arsnova.socket.ARSnovaSocketIOServer;
 @Controller
 public class SessionController extends AbstractController {
 
-	public static final Logger logger = LoggerFactory
-			.getLogger(SessionController.class);
+	public static final Logger LOGGER = LoggerFactory.getLogger(SessionController.class);
 
 	@Autowired
-	ISessionService sessionService;
+	private ISessionService sessionService;
 
 	@Autowired
-	IUserService userService;
+	private IUserService userService;
 
 	@Autowired
-	ARSnovaSocketIOServer server;
+	private ARSnovaSocketIOServer server;
 
 	@RequestMapping(method = RequestMethod.POST, value = "/authorize")
-	public void authorize(@RequestBody Object sessionObject,
-			HttpServletResponse response) {
-		String socketid = (String) JSONObject.fromObject(sessionObject).get(
-				"session");
+	public final void authorize(@RequestBody final Object sessionObject, final HttpServletResponse response) {
+		String socketid = (String) JSONObject.fromObject(sessionObject).get("session");
 		if (socketid == null) {
 			return;
 		}
 		User u = userService.getCurrentUser();
-		logger.info("authorize session: " + socketid + ", user is:  " + u);
-		response.setStatus(u != null ? HttpStatus.CREATED.value()
-				: HttpStatus.UNAUTHORIZED.value());
+		LOGGER.info("authorize session: " + socketid + ", user is:  " + u);
+		response.setStatus(u != null ? HttpStatus.CREATED.value() : HttpStatus.UNAUTHORIZED.value());
 		userService.putUser2SessionID(UUID.fromString(socketid), u);
 	}
 
 	@RequestMapping(value = "/session/{sessionkey}", method = RequestMethod.GET)
 	@ResponseBody
-	public Session joinSession(@PathVariable String sessionkey) {
+	public final Session joinSession(@PathVariable final String sessionkey) {
 		return sessionService.joinSession(sessionkey);
 	}
 
 	@RequestMapping(value = "/session/{sessionkey}/online", method = RequestMethod.POST)
 	@ResponseBody
-	public LoggedIn registerAsOnlineUser(@PathVariable String sessionkey,
-			HttpServletResponse response) {
+	public final LoggedIn registerAsOnlineUser(
+			@PathVariable final String sessionkey,
+			final HttpServletResponse response
+	) {
 		User user = userService.getCurrentUser();
-		LoggedIn loggedIn = sessionService.registerAsOnlineUser(user,
-				sessionkey);
+		LoggedIn loggedIn = sessionService.registerAsOnlineUser(user, sessionkey);
 		if (loggedIn != null) {
 			response.setStatus(HttpStatus.CREATED.value());
 			return loggedIn;
@@ -99,8 +94,7 @@ public class SessionController extends AbstractController {
 
 	@RequestMapping(value = "/session", method = RequestMethod.POST)
 	@ResponseBody
-	public Session postNewSession(@RequestBody Session session,
-			HttpServletResponse response) {
+	public final Session postNewSession(@RequestBody final Session session, final HttpServletResponse response) {
 		Session newSession = sessionService.saveSession(session);
 		if (session != null) {
 			response.setStatus(HttpStatus.CREATED.value());
@@ -113,7 +107,7 @@ public class SessionController extends AbstractController {
 
 	@RequestMapping(value = "/socketurl", method = RequestMethod.GET)
 	@ResponseBody
-	public String getSocketUrl() {
+	public final String getSocketUrl() {
 		StringBuilder url = new StringBuilder();
 
 		url.append(server.isUseSSL() ? "https://" : "http://");
@@ -124,7 +118,7 @@ public class SessionController extends AbstractController {
 
 	@RequestMapping(value = { "/mySessions", "/session/mysessions" }, method = RequestMethod.GET)
 	@ResponseBody
-	public List<Session> getMySession(HttpServletResponse response) {
+	public final List<Session> getMySession(final HttpServletResponse response) {
 		String username = userService.getCurrentUser().getUsername();
 		if (username == null) {
 			response.setStatus(HttpStatus.NOT_FOUND.value());
diff --git a/src/main/java/de/thm/arsnova/controller/WelcomeController.java b/src/main/java/de/thm/arsnova/controller/WelcomeController.java
index 5f900cf9..55796f95 100644
--- a/src/main/java/de/thm/arsnova/controller/WelcomeController.java
+++ b/src/main/java/de/thm/arsnova/controller/WelcomeController.java
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 THM webMedia
- * 
+ *
  * This file is part of ARSnova.
  *
  * ARSnova is free software: you can redistribute it and/or modify
@@ -28,7 +28,7 @@ import org.springframework.web.servlet.ModelAndView;
 @Controller
 public class WelcomeController extends AbstractController {
 	@RequestMapping(method = RequestMethod.GET, value = "/")
-	public ModelAndView home(HttpServletRequest request) {
+	public final ModelAndView home(final HttpServletRequest request) {
 		String referer = request.getHeader("referer");
 		String target = "index.html";
 		if (referer != null && referer.endsWith("dojo-index.html")) {
diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
index ba035705..21a51dd3 100644
--- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 THM webMedia
- * 
+ *
  * This file is part of ARSnova.
  *
  * ARSnova is free software: you can redistribute it and/or modify
@@ -70,47 +70,41 @@ import de.thm.arsnova.services.IUserService;
 @Component
 public class CouchDBDao implements IDatabaseDao {
 	@Autowired
-	IUserService userService;
+	private IUserService userService;
 
 	@Autowired
-	IFeedbackService feedbackService;
+	private IFeedbackService feedbackService;
 
 	@Autowired
-	ISessionService sessionService;
+	private ISessionService sessionService;
 
 	private String databaseHost;
 	private int databasePort;
 	private String databaseName;
-
 	private Database database;
 
-	//
-
-	public static final Logger logger = LoggerFactory.getLogger(CouchDBDao.class);
+	public static final Logger LOGGER = LoggerFactory.getLogger(CouchDBDao.class);
 
 	@Value("${couchdb.host}")
-	public final void setDatabaseHost(String databaseHost) {
-		logger.info(databaseHost);
-		this.databaseHost = databaseHost;
+	public final void setDatabaseHost(final String newDatabaseHost) {
+		this.databaseHost = newDatabaseHost;
 	}
 
 	@Value("${couchdb.port}")
-	public final void setDatabasePort(String databasePort) {
-		logger.info(databasePort);
-		this.databasePort = Integer.parseInt(databasePort);
+	public final void setDatabasePort(final String newDatabasePort) {
+		this.databasePort = Integer.parseInt(newDatabasePort);
 	}
 
 	@Value("${couchdb.name}")
-	public final void setDatabaseName(String databaseName) {
-		logger.info(databaseName);
-		this.databaseName = databaseName;
+	public final void setDatabaseName(final String newDatabaseName) {
+		this.databaseName = newDatabaseName;
 	}
 
 	/**
 	 * This method cleans up old feedback votes at the scheduled interval.
 	 */
 	@Override
-	public void cleanFeedbackVotes(int cleanupFeedbackDelay) {
+	public final void cleanFeedbackVotes(final int cleanupFeedbackDelay) {
 		final long timelimitInMillis = 60000 * (long) cleanupFeedbackDelay;
 		final long maxAllowedTimeInMillis = System.currentTimeMillis() - timelimitInMillis;
 
@@ -136,11 +130,11 @@ public class CouchDBDao implements IDatabaseDao {
 				allAffectedSessions.addAll(affectedArsSessions);
 
 				this.database.deleteDocument(feedback);
-				logger.debug("Cleaning up Feedback document " + d.getId());
+				LOGGER.debug("Cleaning up Feedback document " + d.getId());
 			} catch (IOException e) {
-				logger.error("Could not delete Feedback document " + d.getId());
+				LOGGER.error("Could not delete Feedback document " + d.getId());
 			} catch (JSONException e) {
-				logger.error("Could not delete Feedback document {}, error is: {} ", new Object[] { d.getId(), e });
+				LOGGER.error("Could not delete Feedback document {}, error is: {} ", new Object[] {d.getId(), e});
 			}
 		}
 		if (!results.isEmpty()) {
@@ -157,7 +151,7 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public Session getSession(String keyword) {
+	public final Session getSession(final String keyword) {
 		Session result = this.getSessionFromKeyword(keyword);
 		if (result == null) {
 			throw new NotFoundException();
@@ -170,7 +164,7 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public List<Session> getMySessions(String username) {
+	public final List<Session> getMySessions(final String username) {
 		try {
 			View view = new View("session/by_creator");
 			view.setStartKey("[" + URLEncoder.encode("\"" + username + "\"", "UTF-8") + "]");
@@ -191,11 +185,11 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public List<Question> getSkillQuestions(String sessionKeyword) {
+	public final List<Question> getSkillQuestions(final String sessionKeyword) {
 		Session session = this.getSessionFromKeyword(sessionKeyword);
-		if (session == null)
+		if (session == null) {
 			throw new NotFoundException();
-
+		}
 		try {
 			View view = new View("skill_question/by_session_sorted_by_subject_and_text");
 			view.setStartKey("[" + URLEncoder.encode("\"" + session.get_id() + "\"", "UTF-8") + "]");
@@ -225,7 +219,7 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public int getSkillQuestionCount(String sessionkey) {
+	public final int getSkillQuestionCount(final String sessionkey) {
 		try {
 			View view = new View("skill_question/count_by_session");
 			view.setKey(URLEncoder.encode("\"" + sessionkey + "\"", "UTF-8"));
@@ -243,15 +237,15 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public Session getSessionFromKeyword(String keyword) {
+	public final Session getSessionFromKeyword(final String keyword) {
 		try {
 			View view = new View("session/by_keyword");
 			view.setKey(URLEncoder.encode("\"" + keyword + "\"", "UTF-8"));
 			ViewResults results = this.getDatabase().view(view);
 
-			if (results.getJSONArray("rows").optJSONObject(0) == null)
+			if (results.getJSONArray("rows").optJSONObject(0) == null) {
 				return null;
-
+			}
 			return (Session) JSONObject.toBean(results.getJSONArray("rows").optJSONObject(0).optJSONObject("value"),
 					Session.class);
 		} catch (UnsupportedEncodingException e) {
@@ -260,7 +254,7 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public Session saveSession(Session session) {
+	public final Session saveSession(final Session session) {
 
 		Document sessionDocument = new Document();
 		sessionDocument.put("type", "session");
@@ -279,53 +273,69 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public Feedback getFeedback(String keyword) {
+	public final Feedback getFeedback(final String keyword) {
 		String sessionId = this.getSessionId(keyword);
-		if (sessionId == null)
+		if (sessionId == null) {
 			throw new NotFoundException();
-
+		}
 		View view = new View("understanding/by_session");
 		view.setGroup(true);
 		view.setStartKey(URLEncoder.encode("[\"" + sessionId + "\"]"));
 		view.setEndKey(URLEncoder.encode("[\"" + sessionId + "\",{}]"));
 		ViewResults results = this.getDatabase().view(view);
-		
-		logger.info("Feedback: {}", results.getJSONArray("rows"));
+
+		LOGGER.info("Feedback: {}", results.getJSONArray("rows"));
 
 		return this.createFeedbackObject(results);
 	}
 
-	private Feedback createFeedbackObject(ViewResults results) {
-		int values[] = { 0, 0, 0, 0 };
+	private Feedback createFeedbackObject(final ViewResults results) {
+		int values[] = {0, 0, 0, 0};
 		JSONArray rows = results.getJSONArray("rows");
 
 		try {
-			for (int i = 0; i <= 3; i++) {
+			for (int i = Feedback.MIN_FEEDBACK_TYPE; i <= Feedback.MAX_FEEDBACK_TYPE; i++) {
 				String key = rows.optJSONObject(i).optJSONArray("key").getString(1);
 				JSONObject feedback = rows.optJSONObject(i);
 
-				if (key.equals("Bitte schneller"))
-					values[0] = feedback.getInt("value");
-				if (key.equals("Kann folgen"))
-					values[1] = feedback.getInt("value");
-				if (key.equals("Zu schnell"))
-					values[2] = feedback.getInt("value");
-				if (key.equals("Nicht mehr dabei"))
-					values[3] = feedback.getInt("value");
+				if (key.equals("Bitte schneller")) {
+					values[Feedback.FEEDBACK_FASTER] = feedback.getInt("value");
+				}
+				if (key.equals("Kann folgen")) {
+					values[Feedback.FEEDBACK_OK] = feedback.getInt("value");
+				}
+				if (key.equals("Zu schnell")) {
+					values[Feedback.FEEDBACK_SLOWER] = feedback.getInt("value");
+				}
+				if (key.equals("Nicht mehr dabei")) {
+					values[Feedback.FEEDBACK_AWAY] = feedback.getInt("value");
+				}
 			}
 		} catch (Exception e) {
-			return new Feedback(values[0], values[1], values[2], values[3]);
+			return new Feedback(
+					values[Feedback.FEEDBACK_FASTER],
+					values[Feedback.FEEDBACK_OK],
+					values[Feedback.FEEDBACK_SLOWER],
+					values[Feedback.FEEDBACK_AWAY]
+			);
 		}
-		return new Feedback(values[0], values[1], values[2], values[3]);
+		return new Feedback(
+				values[Feedback.FEEDBACK_FASTER],
+				values[Feedback.FEEDBACK_OK],
+				values[Feedback.FEEDBACK_SLOWER],
+				values[Feedback.FEEDBACK_AWAY]
+		);
 	}
 
 	@Override
-	public boolean saveFeedback(String keyword, int value, de.thm.arsnova.entities.User user) {
+	public final boolean saveFeedback(final String keyword, final int value, final de.thm.arsnova.entities.User user) {
 		String sessionId = this.getSessionId(keyword);
-		if (sessionId == null)
+		if (sessionId == null) {
 			return false;
-		if (!(value >= 0 && value <= 3))
+		}
+		if (!(value >= Feedback.MIN_FEEDBACK_TYPE && value <= Feedback.MAX_FEEDBACK_TYPE)) {
 			return false;
+		}
 
 		Document feedback = new Document();
 		List<Document> postedFeedback = findPreviousFeedback(sessionId, user);
@@ -361,7 +371,7 @@ public class CouchDBDao implements IDatabaseDao {
 		return true;
 	}
 
-	private List<Document> findPreviousFeedback(String sessionId, de.thm.arsnova.entities.User user) {
+	private List<Document> findPreviousFeedback(final String sessionId, final de.thm.arsnova.entities.User user) {
 		View view = new View("understanding/by_user");
 		try {
 			view.setKey(URLEncoder.encode("[\"" + sessionId + "\", \"" + user.getUsername() + "\"]", "UTF-8"));
@@ -372,54 +382,57 @@ public class CouchDBDao implements IDatabaseDao {
 		return results.getResults();
 	}
 
-	private String feedbackValueToString(int value) {
+	private String feedbackValueToString(final int value) {
 		switch (value) {
-		case 0:
+		case Feedback.FEEDBACK_FASTER:
 			return "Bitte schneller";
-		case 1:
+		case Feedback.FEEDBACK_OK:
 			return "Kann folgen";
-		case 2:
+		case Feedback.FEEDBACK_SLOWER:
 			return "Zu schnell";
-		case 3:
+		case Feedback.FEEDBACK_AWAY:
 			return "Nicht mehr dabei";
 		default:
 			return null;
 		}
 	}
 
-	private int feedbackValueFromString(String value) {
-		if (value.equals("Bitte schneller"))
-			return 0;
-		if (value.equals("Kann folgen"))
-			return 1;
-		if (value.equals("Zu schnell"))
-			return 2;
-		if (value.equals("Nicht mehr dabei"))
-			return 3;
+	private int feedbackValueFromString(final String value) {
+		if (value.equals("Bitte schneller")) {
+			return Feedback.FEEDBACK_FASTER;
+		}
+		if (value.equals("Kann folgen")) {
+			return Feedback.FEEDBACK_OK;
+		}
+		if (value.equals("Zu schnell")) {
+			return Feedback.FEEDBACK_AWAY;
+		}
+		if (value.equals("Nicht mehr dabei")) {
+			return Feedback.FEEDBACK_AWAY;
+		}
 		return Integer.MIN_VALUE;
 	}
 
 	@Override
 	@Transactional(isolation = Isolation.READ_COMMITTED)
-	public boolean sessionKeyAvailable(String keyword) {
+	public final boolean sessionKeyAvailable(final String keyword) {
 		View view = new View("session/by_keyword");
 		ViewResults results = this.getDatabase().view(view);
 
 		return !results.containsKey(keyword);
 	}
 
-	private String getSessionId(String keyword) {
+	private String getSessionId(final String keyword) {
 		View view = new View("session/by_keyword");
 		view.setKey(URLEncoder.encode("\"" + keyword + "\""));
 		ViewResults results = this.getDatabase().view(view);
-
-		if (results.getJSONArray("rows").optJSONObject(0) == null)
+		if (results.getJSONArray("rows").optJSONObject(0) == null) {
 			return null;
-
+		}
 		return results.getJSONArray("rows").optJSONObject(0).optJSONObject("value").getString("_id");
 	}
 
-	private String getSessionKeyword(String internalSessionId) {
+	private String getSessionKeyword(final String internalSessionId) {
 		try {
 			View view = new View("session/by_id");
 			view.setKey(URLEncoder.encode("\"" + internalSessionId + "\"", "UTF-8"));
@@ -438,8 +451,9 @@ public class CouchDBDao implements IDatabaseDao {
 
 	private String actualUserName() {
 		User user = userService.getCurrentUser();
-		if (user == null)
+		if (user == null) {
 			return null;
+		}
 		return user.getUsername();
 	}
 
@@ -449,7 +463,7 @@ public class CouchDBDao implements IDatabaseDao {
 				com.fourspaces.couchdb.Session session = new com.fourspaces.couchdb.Session(databaseHost, databasePort);
 				database = session.getDatabase(databaseName);
 			} catch (Exception e) {
-				logger.error("Cannot connect to CouchDB database '" + databaseName + "' on host '" + databaseHost
+				LOGGER.error("Cannot connect to CouchDB database '" + databaseName + "' on host '" + databaseHost
 						+ "' using port " + databasePort);
 			}
 		}
@@ -458,7 +472,7 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public boolean saveQuestion(Session session, Question question) {
+	public final boolean saveQuestion(final Session session, final Question question) {
 		Document q = new Document();
 		q.put("type", "skill_question");
 		q.put("questionType", question.getQuestionType());
@@ -474,15 +488,15 @@ public class CouchDBDao implements IDatabaseDao {
 		try {
 			database.saveDocument(q);
 		} catch (IOException e) {
-			logger.error("Could not save question {}", question);
+			LOGGER.error("Could not save question {}", question);
 		}
 		return false;
 	}
 
 	@Override
-	public Question getQuestion(String id, String sessionKey) {
+	public final Question getQuestion(final String id, final String sessionKey) {
 		Session s = this.getSessionFromKeyword(sessionKey);
-		if(s == null) {
+		if (s == null) {
 			throw new NotFoundException();
 		}
 		try {
@@ -493,28 +507,30 @@ public class CouchDBDao implements IDatabaseDao {
 			if (results.getJSONArray("rows").optJSONObject(0) == null) {
 				return null;
 			}
-			
-			Question q = (Question) JSONObject.toBean(results.getJSONArray("rows").optJSONObject(0).optJSONObject("value"), Question.class);
-			JSONArray possibleAnswers = results.getJSONArray("rows").optJSONObject(0).optJSONObject("value").getJSONArray("possibleAnswers");
+
+			Question q = (Question) JSONObject.toBean(
+					results.getJSONArray("rows").optJSONObject(0).optJSONObject("value"), Question.class);
+			JSONArray possibleAnswers = results.getJSONArray("rows").optJSONObject(0).optJSONObject("value")
+					.getJSONArray("possibleAnswers");
 			Collection<PossibleAnswer> answers = JSONArray.toCollection(possibleAnswers, PossibleAnswer.class);
 			q.setPossibleAnswers(new ArrayList<PossibleAnswer>(answers));
-			
-			if(s.get_id().equals(q.getSessionId())) {
+
+			if (s.get_id().equals(q.getSessionId())) {
 				return q;
 			} else {
 				throw new UnauthorizedException();
 			}
 		} catch (IOException e) {
-			logger.error("Could not get question with id {}", id);
+			LOGGER.error("Could not get question with id {}", id);
 		}
 		return null;
 	}
 
 	@Override
-	public LoggedIn registerAsOnlineUser(User u, Session s) {
+	public final LoggedIn registerAsOnlineUser(final User user, final Session session) {
 		try {
 			View view = new View("logged_in/all");
-			view.setKey(URLEncoder.encode("\"" + u.getUsername() + "\"", "UTF-8"));
+			view.setKey(URLEncoder.encode("\"" + user.getUsername() + "\"", "UTF-8"));
 			ViewResults results = this.getDatabase().view(view);
 
 			LoggedIn loggedIn = new LoggedIn();
@@ -526,9 +542,9 @@ public class CouchDBDao implements IDatabaseDao {
 				loggedIn.setVisitedSessions(new ArrayList<VisitedSession>(visitedSessions));
 			}
 
-			loggedIn.setUser(u.getUsername());
-			loggedIn.setSessionId(s.get_id());
-			loggedIn.addVisitedSession(s);
+			loggedIn.setUser(user.getUsername());
+			loggedIn.setSessionId(session.get_id());
+			loggedIn.addVisitedSession(session);
 			loggedIn.updateTimestamp();
 
 			JSONObject json = JSONObject.fromObject(loggedIn);
@@ -557,23 +573,24 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public void updateSessionOwnerActivity(Session session) {
+	public final void updateSessionOwnerActivity(final Session session) {
 		try {
 			session.setLastOwnerActivity(System.currentTimeMillis());
 			JSONObject json = JSONObject.fromObject(session);
 			this.getDatabase().saveDocument(new Document(json));
 		} catch (IOException e) {
-			logger.error("Failed to update lastOwnerActivity for Session {}", session);
+			LOGGER.error("Failed to update lastOwnerActivity for Session {}", session);
 			return;
 		}
 	}
 
 	@Override
-	public Integer getMyFeedback(String keyword, User user) {
+	public final Integer getMyFeedback(final String keyword, final User user) {
 		try {
 			String sessionId = this.getSessionId(keyword);
-			if (sessionId == null)
+			if (sessionId == null) {
 				throw new NotFoundException();
+			}
 
 			View view = new View("understanding/by_user");
 			view.setKey(URLEncoder.encode("[\"" + sessionId + "\", \"" + user.getUsername() + "\"]", "UTF-8"));
@@ -592,86 +609,85 @@ public class CouchDBDao implements IDatabaseDao {
 	}
 
 	@Override
-	public List<String> getQuestionIds(String sessionKey) {
+	public final List<String> getQuestionIds(final String sessionKey) {
 		User u = userService.getCurrentUser();
 		View view;
-		if(u.getType().equals("thm")) {
+		if (u.getType().equals("thm")) {
 			view = new View("skill_question/by_session_only_id_for_thm");
 		} else {
 			view = new View("skill_question/by_session_only_id_for_all");
 		}
-		
+
 		String sessionId = getSessionId(sessionKey);
-		if(sessionId == null) {
+		if (sessionId == null) {
 			throw new NotFoundException();
 		}
-		
+
 		try {
 			view.setKey(URLEncoder.encode("\"" + sessionId + "\"", "UTF-8"));
 			ViewResults results = this.getDatabase().view(view);
 			if (results.getJSONArray("rows").optJSONObject(0) == null) {
 				return null;
 			}
-			
+
 			List<String> ids = new ArrayList<String>();
-			for(Document d : results.getResults()) {
+			for (Document d : results.getResults()) {
 				ids.add(d.getId());
 			}
 			return ids;
-			
+
 		} catch (IOException e) {
-			logger.error("Could not get list of question ids of session {}", sessionKey);
+			LOGGER.error("Could not get list of question ids of session {}", sessionKey);
 		}
 		return null;
 	}
 
 	@Override
-	public void deleteQuestion(String sessionKey, String questionId) {
+	public final void deleteQuestion(final String sessionKey, final String questionId) {
 		Session s = this.getSessionFromKeyword(sessionKey);
 		try {
 			Document question = this.getDatabase().getDocument(questionId);
-			if(!question.getString("sessionId").equals(s.get_id())) {
+			if (!question.getString("sessionId").equals(s.get_id())) {
 				throw new UnauthorizedException();
 			}
 		} catch (IOException e) {
-			logger.error("could not find question {}", questionId);
+			LOGGER.error("could not find question {}", questionId);
 		}
-		
+
 		try {
 			View view = new View("answer/cleanup");
 			view.setKey(URLEncoder.encode("\"" + questionId + "\"", "UTF-8"));
-			ViewResults results = this.getDatabase().view(view);	
-			
-			for(Document d : results.getResults()) {
+			ViewResults results = this.getDatabase().view(view);
+
+			for (Document d : results.getResults()) {
 				Document answer = this.getDatabase().getDocument(d.getId());
 				this.getDatabase().deleteDocument(answer);
 			}
 			Document question = this.getDatabase().getDocument(questionId);
 			this.getDatabase().deleteDocument(question);
-			
-		} catch(IOException e) {
-			logger.error(
-				"IOException: Could not delete question and its answers with id {}. Connection to CouchDB available?",
-				questionId
-			);
-		} 
+
+		} catch (IOException e) {
+			LOGGER.error(
+					"IOException: Could not delete question and its answers with id {}. Connection to CouchDB available?",
+					questionId);
+		}
 	}
 
 	@Override
-	public List<String> getUnAnsweredQuestions(String sessionKey) {
+	public final List<String> getUnAnsweredQuestions(final String sessionKey) {
 		User user = userService.getCurrentUser();
-		if(user == null) {
+		if (user == null) {
 			throw new UnauthorizedException();
 		}
-		
+
 		Session s = this.getSessionFromKeyword(sessionKey);
-		if(s == null) {
+		if (s == null) {
 			throw new NotFoundException();
 		}
-		
+
 		try {
 			View view = new View("answer/by_user");
-			view.setKey("[" + URLEncoder.encode("\"" + user.getUsername() + "\",\"" + s.get_id()+ "\"", "UTF-8") + "]");
+			view.setKey("[" + URLEncoder.encode("\"" + user.getUsername() + "\",\"" + s.get_id() + "\"", "UTF-8") + "]");
 			ViewResults anseweredQuestions = this.getDatabase().view(view);
 
 			List<String> answered = new ArrayList<String>();
@@ -681,66 +697,68 @@ public class CouchDBDao implements IDatabaseDao {
 
 			List<String> questions = this.getQuestionIds(sessionKey);
 			List<String> unanswered = new ArrayList<String>();
-			for(String questionId : questions) {
-				if(!answered.contains(questionId)) {
+			for (String questionId : questions) {
+				if (!answered.contains(questionId)) {
 					unanswered.add(questionId);
 				}
 			}
 			return unanswered;
 		} catch (UnsupportedEncodingException e) {
-			logger.error("Error while retrieving unansweredquestions", e);
+			LOGGER.error("Error while retrieving unansweredquestions", e);
 		}
-		
-		
+
 		return null;
 	}
 
 	@Override
-	public Answer getMyAnswer(String sessionKey, String questionId) {		
+	public final Answer getMyAnswer(final String sessionKey, final String questionId) {
 		User user = userService.getCurrentUser();
-		if(user == null) {
+		if (user == null) {
 			throw new UnauthorizedException();
 		}
-		
+
 		Session s = this.getSessionFromKeyword(sessionKey);
-		if(s == null) {
+		if (s == null) {
 			throw new NotFoundException();
 		}
-		
+
 		try {
 			View view = new View("answer/by_question_and_user");
 			view.setKey("[" + URLEncoder.encode("\"" + questionId + "\",\"" + user.getUsername() + "\"", "UTF-8") + "]");
 			ViewResults results = this.getDatabase().view(view);
-			if(results.getResults().isEmpty()) {
+			if (results.getResults().isEmpty()) {
 				throw new NotFoundException();
 			}
 			return (Answer) JSONObject.toBean(results.getJSONArray("rows").optJSONObject(0).optJSONObject("value"),
 					Answer.class);
 		} catch (UnsupportedEncodingException e) {
-			logger.error("Error while retrieving answer for user {} and question {}, {}", new Object[]{user, questionId, e});
+			LOGGER.error(
+					"Error while retrieving answer for user {} and question {}, {}",
+					new Object[] {user,	questionId, e }
+			);
 		}
-		
+
 		return null;
 	}
-	
+
 	@Override
-	public List<Answer> getAnswers(String sessionKey, String questionId) {
+	public final List<Answer> getAnswers(final String sessionKey, final String questionId) {
 		Session s = this.getSessionFromKeyword(sessionKey);
-		if(s == null) {
+		if (s == null) {
 			throw new NotFoundException();
 		}
-		
+
 		try {
 			View view = new View("skill_question/count_answers");
 			view.setStartKey("[" + URLEncoder.encode("\"" + questionId + "\"", "UTF-8") + "]");
 			view.setEndKey("[" + URLEncoder.encode("\"" + questionId + "\",{}", "UTF-8") + "]");
 			view.setGroup(true);
 			ViewResults results = this.getDatabase().view(view);
-			if(results.getResults().isEmpty()) {
+			if (results.getResults().isEmpty()) {
 				throw new NotFoundException();
 			}
 			List<Answer> answers = new ArrayList<Answer>();
-			for(Document d : results.getResults()) {
+			for (Document d : results.getResults()) {
 				Answer a = new Answer();
 				a.setAnswerCount(d.getInt("value"));
 				a.setQuestionId(d.getJSONObject().getJSONArray("key").getString(0));
@@ -750,19 +768,19 @@ public class CouchDBDao implements IDatabaseDao {
 			}
 			return answers;
 		} catch (UnsupportedEncodingException e) {
-			logger.error("Error while retrieving answers", e);
+			LOGGER.error("Error while retrieving answers", e);
 		}
-		
+
 		return null;
 	}
-	
+
 	@Override
-	public int getAnswerCount(String sessionKey, String questionId) {
+	public final int getAnswerCount(final String sessionKey, final String questionId) {
 		Session s = this.getSessionFromKeyword(sessionKey);
-		if(s == null) {
+		if (s == null) {
 			throw new NotFoundException();
 		}
-		
+
 		try {
 			View view = new View("skill_question/count_answers_by_question");
 			view.setKey(URLEncoder.encode("\"" + questionId + "\"", "UTF-8"));
@@ -770,8 +788,8 @@ public class CouchDBDao implements IDatabaseDao {
 			ViewResults results = this.getDatabase().view(view);
 			return results.getJSONArray("rows").optJSONObject(0).optInt("value");
 		} catch (UnsupportedEncodingException e) {
-			logger.error("Error while retrieving answer count", e);
-		}		
+			LOGGER.error("Error while retrieving answer count", e);
+		}
 		return 0;
 	}
 }
diff --git a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
index 9049bf8a..524a8d98 100644
--- a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
+++ b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2012 THM webMedia
- * 
+ *
  * This file is part of ARSnova.
  *
  * ARSnova is free software: you can redistribute it and/or modify
@@ -29,46 +29,45 @@ import de.thm.arsnova.entities.Session;
 import de.thm.arsnova.entities.User;
 
 public interface IDatabaseDao {
-	public void cleanFeedbackVotes(int cleanupFeedbackDelay);
+	void cleanFeedbackVotes(int cleanupFeedbackDelay);
 
-	public Session getSessionFromKeyword(String keyword);
+	Session getSessionFromKeyword(String keyword);
 
-	public Session getSession(String keyword);
+	Session getSession(String keyword);
 
-	public List<Session> getMySessions(String username);
+	List<Session> getMySessions(String username);
 
-	public Session saveSession(Session session);
+	Session saveSession(Session session);
 
-	public Feedback getFeedback(String keyword);
+	Feedback getFeedback(String keyword);
 
-	public boolean saveFeedback(String keyword, int value, User user);
+	boolean saveFeedback(String keyword, int value, User user);
 
-	public boolean sessionKeyAvailable(String keyword);
+	boolean sessionKeyAvailable(String keyword);
 
-	public boolean saveQuestion(Session session, Question question);
+	boolean saveQuestion(Session session, Question question);
 
-	public Question getQuestion(String id, String sessionKey);
+	Question getQuestion(String id, String sessionKey);
 
 	List<Question> getSkillQuestions(String session);
 
-	public int getSkillQuestionCount(String sessionkey);
-
-	public LoggedIn registerAsOnlineUser(User u, Session s);
+	int getSkillQuestionCount(String sessionkey);
 
-	public void updateSessionOwnerActivity(Session session);
+	LoggedIn registerAsOnlineUser(User u, Session s);
 
-	public Integer getMyFeedback(String keyword, User user);
+	void updateSessionOwnerActivity(Session session);
 
-	public List<String> getQuestionIds(String sessionKey);
+	Integer getMyFeedback(String keyword, User user);
 
-	public void deleteQuestion(String sessionKey, String questionId);
+	List<String> getQuestionIds(String sessionKey);
 
-	public List<String> getUnAnsweredQuestions(String sessionKey);
+	void deleteQuestion(String sessionKey, String questionId);
 
-	public Answer getMyAnswer(String sessionKey, String questionId);
+	List<String> getUnAnsweredQuestions(String sessionKey);
 
-	public List<Answer> getAnswers(String sessionKey, String questionId);
+	Answer getMyAnswer(String sessionKey, String questionId);
 
-	public int getAnswerCount(String sessionKey, String questionId);
+	List<Answer> getAnswers(String sessionKey, String questionId);
 
-}
\ No newline at end of file
+	int getAnswerCount(String sessionKey, String questionId);
+}
diff --git a/src/main/java/de/thm/arsnova/dao/package-info.java b/src/main/java/de/thm/arsnova/dao/package-info.java
index 2dcb75c6..1178f009 100644
--- a/src/main/java/de/thm/arsnova/dao/package-info.java
+++ b/src/main/java/de/thm/arsnova/dao/package-info.java
@@ -1 +1 @@
-package de.thm.arsnova.dao;
\ No newline at end of file
+package de.thm.arsnova.dao;
diff --git a/src/main/java/de/thm/arsnova/entities/Answer.java b/src/main/java/de/thm/arsnova/entities/Answer.java
index 6b81e231..3a3ef5d4 100644
--- a/src/main/java/de/thm/arsnova/entities/Answer.java
+++ b/src/main/java/de/thm/arsnova/entities/Answer.java
@@ -17,87 +17,87 @@ public class Answer {
 		this.type = "skill_question_answer";
 	}
 	
-	public String get_id() {
+	public final String get_id() {
 		return _id;
 	}
 
-	public void set_id(String _id) {
+	public final void set_id(String _id) {
 		this._id = _id;
 	}
 
-	public String get_rev() {
+	public final String get_rev() {
 		return _rev;
 	}
 
-	public void set_rev(String _rev) {
+	public final void set_rev(final String _rev) {
 		this._rev = _rev;
 	}
 
-	public String getType() {
+	public final String getType() {
 		return type;
 	}
 
-	public void setType(String type) {
+	public final void setType(final String type) {
 		this.type = type;
 	}
 
-	public String getSessionId() {
+	public final String getSessionId() {
 		return sessionId;
 	}
 
-	public void setSessionId(String sessionId) {
+	public final void setSessionId(final String sessionId) {
 		this.sessionId = sessionId;
 	}
 
-	public String getQuestionId() {
+	public final String getQuestionId() {
 		return questionId;
 	}
 
-	public void setQuestionId(String questionId) {
+	public final void setQuestionId(final String questionId) {
 		this.questionId = questionId;
 	}
 
-	public String getAnswerText() {
+	public final String getAnswerText() {
 		return answerText;
 	}
 
-	public void setAnswerText(String answerText) {
+	public final void setAnswerText(final String answerText) {
 		this.answerText = answerText;
 	}
 
-	public String getAnswerSubject() {
+	public final String getAnswerSubject() {
 		return answerSubject;
 	}
 
-	public void setAnswerSubject(String answerSubject) {
+	public final void setAnswerSubject(final String answerSubject) {
 		this.answerSubject = answerSubject;
 	}
 
-	public String getUser() {
+	public final String getUser() {
 		return user;
 	}
 
-	public void setUser(String user) {
+	public final void setUser(final String user) {
 		this.user = user;
 	}
 
-	public int getAnswerCount() {
+	public final int getAnswerCount() {
 		return answerCount;
 	}
 
-	public void setAnswerCount(int answerCount) {
+	public final void setAnswerCount(final int answerCount) {
 		this.answerCount = answerCount;
 	}
 
 	@Override
-	public String toString() {
-		return "Answer type:'" + type + "'" +
-				", session: " + sessionId + 
-				", question: " + questionId +
-				", subject: " + answerSubject +
-				", answerCount: " + answerCount +
-				", answer: " + answerText + 
-				", user: " + user;
+	public final String toString() {
+		return "Answer type:'" + type + "'"
+				+ ", session: " + sessionId 
+				+ ", question: " + questionId
+				+ ", subject: " + answerSubject
+				+ ", answerCount: " + answerCount
+				+ ", answer: " + answerText
+				+ ", user: " + user;
 	}
 
 }
diff --git a/src/main/java/de/thm/arsnova/entities/Authorize.java b/src/main/java/de/thm/arsnova/entities/Authorize.java
index a19d5bb0..4dab20f0 100644
--- a/src/main/java/de/thm/arsnova/entities/Authorize.java
+++ b/src/main/java/de/thm/arsnova/entities/Authorize.java
@@ -4,24 +4,24 @@ public class Authorize {
 	private String user;
 	private String socketid;
 
-	public String getUser() {
+	public final String getUser() {
 		return user;
 	}
 
-	public void setUser(String user) {
+	public final void setUser(final String user) {
 		this.user = user;
 	}
 
-	public String getSocketid() {
+	public final String getSocketid() {
 		return socketid;
 	}
 
-	public void setSocketid(String socketid) {
+	public final void setSocketid(final String socketid) {
 		this.socketid = socketid;
 	}
 
 	@Override
-	public String toString() {
+	public final String toString() {
 		return "user: " + user + ", socketid: " + socketid;
 
 	}
diff --git a/src/main/java/de/thm/arsnova/entities/Feedback.java b/src/main/java/de/thm/arsnova/entities/Feedback.java
index 32a75632..4b5e51f4 100644
--- a/src/main/java/de/thm/arsnova/entities/Feedback.java
+++ b/src/main/java/de/thm/arsnova/entities/Feedback.java
@@ -4,9 +4,17 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class Feedback {
+	public static final int MIN_FEEDBACK_TYPE = 0;
+	public static final int MAX_FEEDBACK_TYPE = 3;
+
+	public static final int FEEDBACK_FASTER = 0;
+	public static final int FEEDBACK_OK = 1;
+	public static final int FEEDBACK_SLOWER = 2;
+	public static final int FEEDBACK_AWAY = 3;
+
 	private List<Integer> values;
 
-	public Feedback(int a, int b, int c, int d) {
+	public Feedback(final int a, final int b, final int c, final int d) {
 		values = new ArrayList<Integer>();
 		values.add(a);
 		values.add(b);
@@ -14,7 +22,7 @@ public class Feedback {
 		values.add(d);
 	}
 
-	public List<Integer> getValues() {
+	public final List<Integer> getValues() {
 		return values;
 	}
 }
-- 
GitLab