Commit 9c79407d authored by Daniel Gerhardt's avatar Daniel Gerhardt

Merge branch 'code-cleanup' into 'master'

Code cleanup

See merge request !48
parents 84116434 685695a6
......@@ -295,6 +295,11 @@
<artifactId>metrics-annotation</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>2.1.9</version>
</dependency>
</dependencies>
<build>
......
......@@ -34,7 +34,7 @@ import java.io.IOException;
*/
public class CASLogoutSuccessHandler implements LogoutSuccessHandler {
public static final Logger LOGGER = LoggerFactory.getLogger(CASLogoutSuccessHandler.class);
private static final Logger logger = LoggerFactory.getLogger(CASLogoutSuccessHandler.class);
private String casUrl;
private String defaultTarget;
......@@ -50,7 +50,7 @@ public class CASLogoutSuccessHandler implements LogoutSuccessHandler {
/* Typo in "referer" intended. It is in the spec. */
String referrer = request.getHeader("referer");
if (response.isCommitted()) {
LOGGER.info("Response has already been committed. Unable to redirect to target");
logger.info("Response has already been committed. Unable to redirect to target");
return;
}
redirectStrategy.sendRedirect(
......
......@@ -56,7 +56,7 @@ public class ImageUtils {
/* default value is 200 pixel in height, set the value in the configuration file */
static final int THUMB_HEIGHT_DEFAULT = 200;
public static final Logger LOGGER = LoggerFactory.getLogger(ImageUtils.class);
private static final Logger logger = LoggerFactory.getLogger(ImageUtils.class);
@Value("${imageupload.thumbnail.width}")
private int thumbWidth = THUMB_WIDTH_DEFAULT;
......@@ -200,7 +200,7 @@ public class ImageUtils {
return result.toString();
} catch (IOException e) {
LOGGER.error(e.getLocalizedMessage());
logger.error(e.getLocalizedMessage());
return null;
}
}
......@@ -248,7 +248,7 @@ public class ImageUtils {
return baos.toByteArray();
} catch (IOException e) {
LOGGER.error(e.getLocalizedMessage());
logger.error(e.getLocalizedMessage());
}
return null;
......
......@@ -17,8 +17,6 @@
*/
package de.thm.arsnova;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.RedirectStrategy;
......@@ -40,8 +38,6 @@ public class LoginAuthenticationFailureHandler extends
private final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
private String failureUrl;
public static final Logger LOGGER = LoggerFactory.getLogger(LoginAuthenticationFailureHandler.class);
@Override
public void onAuthenticationFailure(
final HttpServletRequest request,
......
......@@ -17,8 +17,6 @@
*/
package de.thm.arsnova;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import javax.servlet.http.HttpServletRequest;
......@@ -33,8 +31,6 @@ public class LoginAuthenticationSucessHandler extends
private String targetUrl;
public static final Logger LOGGER = LoggerFactory.getLogger(LoginAuthenticationSucessHandler.class);
@Override
protected String determineTargetUrl(
final HttpServletRequest request,
......
......@@ -87,7 +87,7 @@ import java.util.List;
@EnableWebSecurity
@Profile("!test")
public class SecurityConfig extends WebSecurityConfigurerAdapter implements ServletContextAware {
private final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
private ServletContext servletContext;
......
......@@ -28,8 +28,6 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -50,8 +48,6 @@ import java.util.List;
@Api(value = "/audiencequestion", description = "the Audience Question API")
public class AudienceQuestionController extends PaginationController {
public static final Logger LOGGER = LoggerFactory.getLogger(AudienceQuestionController.class);
@Autowired
private IQuestionService questionService;
......
......@@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* The ConfigurationController provides frontend clients with information necessary to correctly interact with the
......@@ -36,7 +37,7 @@ import java.util.HashMap;
@Controller
@RequestMapping({"/configuration", "/arsnova-config"})
public class ConfigurationController extends AbstractController {
public static final Logger LOGGER = LoggerFactory
private static final Logger logger = LoggerFactory
.getLogger(ConfigurationController.class);
@Value("${api.path:}")
......@@ -161,11 +162,11 @@ public class ConfigurationController extends AbstractController {
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public HashMap<String, Object> getConfiguration(HttpServletRequest request) {
HashMap<String, Object> config = new HashMap<>();
HashMap<String, Boolean> features = new HashMap<>();
HashMap<String, String> publicPool = new HashMap<>();
HashMap<String, Object> splashscreen = new HashMap<>();
public Map<String, Object> getConfiguration(HttpServletRequest request) {
Map<String, Object> config = new HashMap<>();
Map<String, Boolean> features = new HashMap<>();
Map<String, String> publicPool = new HashMap<>();
Map<String, Object> splashscreen = new HashMap<>();
/* The API path could be unknown to the client in case the request was forwarded */
if ("".equals(apiPath)) {
......@@ -268,7 +269,7 @@ public class ConfigurationController extends AbstractController {
}
if (!"".equals(trackingTrackerUrl)) {
HashMap<String, String> tracking = new HashMap<>();
Map<String, String> tracking = new HashMap<>();
config.put("tracking", tracking);
tracking.put("provider", trackingProvider);
......
......@@ -45,7 +45,7 @@ import java.util.List;
@RestController
public class CourseController extends AbstractController {
public static final Logger LOGGER = LoggerFactory.getLogger(CourseController.class);
private static final Logger logger = LoggerFactory.getLogger(CourseController.class);
@Autowired(required = false)
private ConnectorClient connectorClient;
......
......@@ -43,7 +43,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class FeedbackController extends AbstractController {
public static final Logger LOGGER = LoggerFactory.getLogger(FeedbackController.class);
private static final Logger logger = LoggerFactory.getLogger(FeedbackController.class);
@Autowired
private IFeedbackService feedbackService;
......
......@@ -56,7 +56,7 @@ import java.util.List;
@Api(value = "/lecturerquestion", description = "Operations for Lecture Questions")
public class LecturerQuestionController extends PaginationController {
public static final Logger LOGGER = LoggerFactory.getLogger(LecturerQuestionController.class);
private static final Logger logger = LoggerFactory.getLogger(LecturerQuestionController.class);
@Autowired
private IQuestionService questionService;
......
......@@ -19,8 +19,6 @@ package de.thm.arsnova.controller;
import de.thm.arsnova.services.IQuestionService;
import de.thm.arsnova.web.DeprecatedApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -34,8 +32,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class LegacyController extends AbstractController {
public static final Logger LOGGER = LoggerFactory.getLogger(LegacyController.class);
@Autowired
private IQuestionService questionService;
......
......@@ -141,7 +141,7 @@ public class LoginController extends AbstractController {
@Autowired
private UserSessionService userSessionService;
public static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);
private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
@RequestMapping(value = { "/auth/login", "/doLogin" }, method = { RequestMethod.POST, RequestMethod.GET })
public void doLogin(
......@@ -174,7 +174,7 @@ public class LoginController extends AbstractController {
return;
}
} catch (AuthenticationException e) {
LOGGER.info("Authentication failed: {}", e.getMessage());
logger.info("Authentication failed: {}", e.getMessage());
}
userService.increaseFailedLoginCount(addr);
......@@ -197,9 +197,9 @@ public class LoginController extends AbstractController {
return;
}
LOGGER.info("LDAPLOGIN: {}", auth.isAuthenticated());
logger.info("LDAPLOGIN: {}", auth.isAuthenticated());
} catch (AuthenticationException e) {
LOGGER.info("No LDAP login: {}", e);
logger.info("No LDAP login: {}", e);
}
userService.increaseFailedLoginCount(addr);
......
......@@ -25,8 +25,6 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -49,8 +47,6 @@ import java.util.List;
@Api(value = "/motd", description = "the Motd Controller API")
public class MotdController extends AbstractController {
private static final Logger LOGGER = LoggerFactory.getLogger(MotdController.class);
@Autowired
private IMotdService motdService;
......@@ -72,7 +68,7 @@ public class MotdController extends AbstractController {
client.setTime(Long.parseLong(clientdate));
}
if (adminview) {
if (sessionkey.equals("null")) {
if ("null".equals(sessionkey)) {
motds = motdService.getAdminMotds();
} else {
motds = motdService.getAllSessionMotds(sessionkey);
......@@ -96,7 +92,7 @@ public class MotdController extends AbstractController {
) {
if (motd != null) {
Motd newMotd;
if (motd.getAudience().equals("session") && motd.getSessionkey() != null) {
if ("session".equals(motd.getAudience()) && motd.getSessionkey() != null) {
newMotd = motdService.saveSessionMotd(motd.getSessionkey(), motd);
} else {
newMotd = motdService.saveMotd(motd);
......@@ -118,7 +114,7 @@ public class MotdController extends AbstractController {
@ApiParam(value = "motdkey from current motd", required = true) @PathVariable final String motdkey,
@ApiParam(value = "current motd", required = true) @RequestBody final Motd motd
) {
if (motd.getAudience().equals("session") && motd.getSessionkey() != null) {
if ("session".equals(motd.getAudience()) && motd.getSessionkey() != null) {
return motdService.updateSessionMotd(motd.getSessionkey(), motd);
} else {
return motdService.updateMotd(motd);
......@@ -129,7 +125,7 @@ public class MotdController extends AbstractController {
@RequestMapping(value = "/{motdkey}", method = RequestMethod.DELETE)
public void deleteMotd(@ApiParam(value = "Motd-key from the message that shall be deleted", required = true) @PathVariable final String motdkey) {
Motd motd = motdService.getMotd(motdkey);
if (motd.getAudience().equals("session")) {
if ("session".equals(motd.getAudience())) {
motdService.deleteSessionMotd(motd.getSessionkey(), motd);
} else {
motdService.deleteMotd(motd);
......
......@@ -62,16 +62,19 @@ public class SecurityExceptionControllerAdvice {
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
public void handleNotFoundException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ExceptionHandler(UnauthorizedException.class)
public void handleUnauthorizedException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ExceptionHandler(AuthenticationCredentialsNotFoundException.class)
public void handleAuthenticationCredentialsNotFoundException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
@ExceptionHandler(AccessDeniedException.class)
......@@ -95,30 +98,36 @@ public class SecurityExceptionControllerAdvice {
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(ForbiddenException.class)
public void handleForbiddenException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
@ResponseStatus(HttpStatus.NO_CONTENT)
@ExceptionHandler(NoContentException.class)
public void handleNoContentException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BadRequestException.class)
public void handleBadRequestException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
@ResponseStatus(HttpStatus.PRECONDITION_FAILED)
@ExceptionHandler(PreconditionFailedException.class)
public void handlePreconditionFailedException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
@ResponseStatus(HttpStatus.NOT_IMPLEMENTED)
@ExceptionHandler(NotImplementedException.class)
public void handleNotImplementedException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
@ResponseStatus(HttpStatus.PAYLOAD_TOO_LARGE)
@ExceptionHandler(PayloadTooLargeException.class)
public void handlePayloadTooLargeException(final Exception e, final HttpServletRequest request) {
/* No implementation - handled solely by annotations */
}
}
......@@ -63,7 +63,7 @@ import java.util.List;
@Api(value = "/session", description = "the Session Controller API")
public class SessionController extends PaginationController {
public static final Logger LOGGER = LoggerFactory.getLogger(SessionController.class);
private static final Logger logger = LoggerFactory.getLogger(SessionController.class);
@Autowired
private ISessionService sessionService;
......@@ -172,7 +172,7 @@ public class SessionController extends PaginationController {
) {
List<Session> sessions;
if (!username.equals("")) {
if (!"".equals(username)) {
try {
if (ownedOnly && !visitedOnly) {
sessions = sessionService.getUserSessions(username);
......@@ -206,7 +206,7 @@ public class SessionController extends PaginationController {
return null;
}
if (sortby != null && sortby.equals("shortname")) {
if ("shortname".equals(sortby)) {
Collections.sort(sessions, new SessionShortNameComparator());
} else {
Collections.sort(sessions, new SessionNameComparator());
......@@ -242,7 +242,7 @@ public class SessionController extends PaginationController {
return null;
}
if (sortby != null && sortby.equals("shortname")) {
if ("shortname".equals(sortby)) {
Collections.sort(sessions, new SessionInfoShortNameComparator());
} else {
Collections.sort(sessions, new SessionInfoNameComparator());
......
......@@ -57,7 +57,7 @@ public class SocketController extends AbstractController {
@Autowired
private ARSnovaSocket server;
private static final Logger LOGGER = LoggerFactory.getLogger(SocketController.class);
private static final Logger logger = LoggerFactory.getLogger(SocketController.class);
@ApiOperation(value = "requested to assign Websocket session",
nickname = "authorize")
......@@ -70,13 +70,13 @@ public class SocketController extends AbstractController {
public void authorize(@ApiParam(value = "sessionMap", required = true) @RequestBody final Map <String, String> sessionMap, @ApiParam(value = "response", required = true) final HttpServletResponse response) {
String socketid = sessionMap.get("session");
if (null == socketid) {
LOGGER.debug("Expected property 'session' missing");
logger.debug("Expected property 'session' missing");
response.setStatus(HttpStatus.BAD_REQUEST.value());
return;
}
User u = userService.getCurrentUser();
if (null == u) {
LOGGER.debug("Client {} requested to assign Websocket session but has not authenticated", socketid);
logger.debug("Client {} requested to assign Websocket session but has not authenticated", socketid);
response.setStatus(HttpStatus.FORBIDDEN.value());
return;
}
......
......@@ -48,7 +48,7 @@ public class UserController extends AbstractController {
@Autowired
private UserSessionService userSessionService;
public static final Logger LOGGER = LoggerFactory
private static final Logger logger = LoggerFactory
.getLogger(UserController.class);
@RequestMapping(value = "/register", method = RequestMethod.POST)
......
......@@ -41,7 +41,7 @@ public class LearningProgressFactory implements NovaEventVisitor, ILearningProgr
@Override
public LearningProgress create(String progressType, String questionVariant) {
VariantLearningProgress learningProgress;
if (progressType.equals("questions")) {
if ("questions".equals(progressType)) {
learningProgress = new QuestionBasedLearningProgress(databaseDao);
} else {
learningProgress = new PointBasedLearningProgress(databaseDao);
......
......@@ -57,7 +57,7 @@ public class QuestionScore implements Iterable<UserScore> {
}
public boolean hasScores() {
return this.userScores.size() > 0;
return !this.userScores.isEmpty();
}
public void add(int piRound, String username, int userscore) {
......
......@@ -142,6 +142,6 @@ public class Motd {
return false;
}
Motd other = (Motd) obj;
return (this.getMotdkey().equals(other.getMotdkey()));
return this.getMotdkey().equals(other.getMotdkey());
}
}
......@@ -653,9 +653,9 @@ public class Question implements Serializable {
public int calculateValue(Answer answer) {
if (answer.isAbstention()) {
return 0;
} else if (this.questionType.equals("mc")) {
} else if ("mc".equals(this.questionType)) {
return calculateMultipleChoiceValue(answer);
} else if (this.questionType.equals("grid")) {
} else if ("grid".equals(this.questionType)) {
return calculateGridValue(answer);
} else {
return calculateRegularValue(answer);
......@@ -780,7 +780,7 @@ public class Question implements Serializable {
int value = 0;
String[] answers = answer.getAnswerText().split(",");
for (int i = 0; i < this.possibleAnswers.size() && i < answers.length; i++) {
if (answers[i].equals("1")) {
if ("1".equals(answers[i])) {
PossibleAnswer p = this.possibleAnswers.get(i);
value += p.getValue();
}
......
......@@ -155,10 +155,6 @@ public class ImportExportSession {
private List<Answer> answers;
public ImportExportQuestion() {
}
public ImportExportQuestion(Question q) {
setType(q.getType());
setQuestionType(q.getQuestionType());
......
......@@ -21,6 +21,7 @@ import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.Session;
import java.util.HashMap;
import java.util.Map;
/**
* Fires whenever voting on a question is disabled.
......@@ -48,8 +49,8 @@ public class LockVoteEvent extends SessionEvent {
return this.question.isVotingDisabled();
}
public HashMap<String, Object> getVotingAdmission() {
HashMap<String, Object> map = new HashMap<>();
public Map<String, Object> getVotingAdmission() {
Map<String, Object> map = new HashMap<>();
map.put("_id", getQuestionId());
map.put("variant", getQuestionVariant());
......
......@@ -21,6 +21,7 @@ import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.Session;
import java.util.HashMap;
import java.util.Map;
/**
* Fires whenever a delayed peer instruction round is initiated. The delayed part denotes that this round might not
......@@ -69,8 +70,8 @@ public class PiRoundDelayedStartEvent extends SessionEvent {
return piRound;
}
public HashMap<String, Object> getPiRoundInformations() {
HashMap<String, Object> map = new HashMap<>();
public Map<String, Object> getPiRoundInformations() {
Map<String, Object> map = new HashMap<>();
map.put("_id", getQuestionId());
map.put("endTime", getEndTime());
......
......@@ -21,6 +21,7 @@ import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.Session;
import java.util.HashMap;
import java.util.Map;
/**
* Fires whenever a peer instruction round has ended.
......@@ -51,8 +52,8 @@ public class PiRoundEndEvent extends SessionEvent {
return questionVariant;
}
public HashMap<String, String> getPiRoundEndInformations() {
HashMap<String, String> map = new HashMap<>();
public Map<String, String> getPiRoundEndInformations() {
Map<String, String> map = new HashMap<>();
map.put("_id", getQuestionId());
map.put("variant", getQuestionVariant());
......
......@@ -21,6 +21,7 @@ import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.Session;
import java.util.HashMap;
import java.util.Map;
/**
* Fires whenever a peer instruction round is reset.
......@@ -51,8 +52,8 @@ public class PiRoundResetEvent extends SessionEvent {
return questionVariant;
}
public HashMap<String, String> getPiRoundResetInformations() {
HashMap<String, String> map = new HashMap<>();
public Map<String, String> getPiRoundResetInformations() {
Map<String, String> map = new HashMap<>();
map.put("_id", getQuestionId());
map.put("variant", getQuestionVariant());
......
......@@ -21,6 +21,7 @@ import de.thm.arsnova.entities.Question;
import de.thm.arsnova.entities.Session;
import java.util.HashMap;
import java.util.Map;
/**
* Fires whenever voting on a question is enabled.
......@@ -48,8 +49,8 @@ public class UnlockVoteEvent extends SessionEvent {
return this.question.isVotingDisabled();
}
public HashMap<String, Object> getVotingAdmission() {
HashMap<String, Object> map = new HashMap<>();
public Map<String, Object> getVotingAdmission() {
Map<String, Object> map = new HashMap<>();
map.put("_id", getQuestionId());
map.put("variant", getQuestionVariant());
......
......@@ -27,8 +27,6 @@ import de.thm.arsnova.exceptions.UnauthorizedException;
import org.scribe.up.profile.facebook.FacebookProfile;
import org.scribe.up.profile.google.Google2Profile;
import org.scribe.up.profile.twitter.TwitterProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.PermissionEvaluator;
......@@ -43,10 +41,8 @@ import java.util.Arrays;
*/
public class ApplicationPermissionEvaluator implements PermissionEvaluator {
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationPermissionEvaluator.class);
@Value("${security.admin-accounts}")
private String adminAccounts;
private String[] adminAccounts;
@Autowired
private IDatabaseDao dao;
......@@ -99,9 +95,7 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator {