diff --git a/pom.xml b/pom.xml index e62c1e96fd0b65cf97522a185d9dbaaf5422c4bf..be4fe45866c55ebd822be45976c3df8557f104ff 100644 --- a/pom.xml +++ b/pom.xml @@ -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> diff --git a/src/main/java/de/thm/arsnova/CASLogoutSuccessHandler.java b/src/main/java/de/thm/arsnova/CASLogoutSuccessHandler.java index 074832b300e853ea587b6144b2c002a45f683d53..13eb9343443ed2cd00203d11f3d3c2d0562761b8 100644 --- a/src/main/java/de/thm/arsnova/CASLogoutSuccessHandler.java +++ b/src/main/java/de/thm/arsnova/CASLogoutSuccessHandler.java @@ -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( diff --git a/src/main/java/de/thm/arsnova/ImageUtils.java b/src/main/java/de/thm/arsnova/ImageUtils.java index 0203e2a148fdac38f2f2d7a4aacf083af9a3ddc5..6349cc8444a3800897cbb49275e848bfbcd10643 100644 --- a/src/main/java/de/thm/arsnova/ImageUtils.java +++ b/src/main/java/de/thm/arsnova/ImageUtils.java @@ -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; diff --git a/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java b/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java index 34792b3b2d56a99932df3d1fe82ea50d0d9ba47e..f3f4298751c83d7fa410272ff28bb3a729216453 100644 --- a/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java +++ b/src/main/java/de/thm/arsnova/LoginAuthenticationFailureHandler.java @@ -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, diff --git a/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java b/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java index f84cdaf5698d934e2ed10717817c487c84bbbbaf..714578ee6ef33665a588ae9443b495da91a8c2d3 100644 --- a/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java +++ b/src/main/java/de/thm/arsnova/LoginAuthenticationSucessHandler.java @@ -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, diff --git a/src/main/java/de/thm/arsnova/config/SecurityConfig.java b/src/main/java/de/thm/arsnova/config/SecurityConfig.java index 21af460632f6c9ef357ca70b96f3f9c3506cc3a6..73b719285094d7f118638299bfd86ef830c7ed26 100644 --- a/src/main/java/de/thm/arsnova/config/SecurityConfig.java +++ b/src/main/java/de/thm/arsnova/config/SecurityConfig.java @@ -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; diff --git a/src/main/java/de/thm/arsnova/controller/AudienceQuestionController.java b/src/main/java/de/thm/arsnova/controller/AudienceQuestionController.java index 7aec9eb6789421d943e32c8325714d68afaad002..2de2dc3638733d9ded5968821bbc7ea6a3233510 100644 --- a/src/main/java/de/thm/arsnova/controller/AudienceQuestionController.java +++ b/src/main/java/de/thm/arsnova/controller/AudienceQuestionController.java @@ -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; diff --git a/src/main/java/de/thm/arsnova/controller/ConfigurationController.java b/src/main/java/de/thm/arsnova/controller/ConfigurationController.java index 75970e43f7728e11bf6b5b3a3d4ce03f291f07fe..2a00e65b726c469a1f4da10c9a2d16300cde240a 100644 --- a/src/main/java/de/thm/arsnova/controller/ConfigurationController.java +++ b/src/main/java/de/thm/arsnova/controller/ConfigurationController.java @@ -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); diff --git a/src/main/java/de/thm/arsnova/controller/CourseController.java b/src/main/java/de/thm/arsnova/controller/CourseController.java index adc24428e62964f6d32516984c3daf9844d34826..48e4ece77443ef4d12ec17c9f9eb5083f18d8b47 100644 --- a/src/main/java/de/thm/arsnova/controller/CourseController.java +++ b/src/main/java/de/thm/arsnova/controller/CourseController.java @@ -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; diff --git a/src/main/java/de/thm/arsnova/controller/FeedbackController.java b/src/main/java/de/thm/arsnova/controller/FeedbackController.java index 5a60f2ed1671504be549a24d5c0f0ddfa6269112..d0e77fdda10508be1d3fe1ff951296a3392396b4 100644 --- a/src/main/java/de/thm/arsnova/controller/FeedbackController.java +++ b/src/main/java/de/thm/arsnova/controller/FeedbackController.java @@ -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; diff --git a/src/main/java/de/thm/arsnova/controller/LecturerQuestionController.java b/src/main/java/de/thm/arsnova/controller/LecturerQuestionController.java index 8ce847445867e2d75e622dc4515851f368abfd86..40674a0e88e135e8e2650e3f67c25f85b972035e 100644 --- a/src/main/java/de/thm/arsnova/controller/LecturerQuestionController.java +++ b/src/main/java/de/thm/arsnova/controller/LecturerQuestionController.java @@ -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; diff --git a/src/main/java/de/thm/arsnova/controller/LegacyController.java b/src/main/java/de/thm/arsnova/controller/LegacyController.java index c7a96a53c2372a6d94cd6fb86979d1c5c9ec79ba..c9f809c63b73415f788860754cec0716d9c2be90 100644 --- a/src/main/java/de/thm/arsnova/controller/LegacyController.java +++ b/src/main/java/de/thm/arsnova/controller/LegacyController.java @@ -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; diff --git a/src/main/java/de/thm/arsnova/controller/LoginController.java b/src/main/java/de/thm/arsnova/controller/LoginController.java index 672729156a1f34aaa8f5653460cf930d777356fb..0420a72400fa12dc7954ba8a93c052b927755a90 100644 --- a/src/main/java/de/thm/arsnova/controller/LoginController.java +++ b/src/main/java/de/thm/arsnova/controller/LoginController.java @@ -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); diff --git a/src/main/java/de/thm/arsnova/controller/MotdController.java b/src/main/java/de/thm/arsnova/controller/MotdController.java index 5a77d9e3d806b45ec41b597c1deff23b7089a5b4..9f1e5155476635107bb6a1cd114feeb03e8bac3a 100644 --- a/src/main/java/de/thm/arsnova/controller/MotdController.java +++ b/src/main/java/de/thm/arsnova/controller/MotdController.java @@ -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); diff --git a/src/main/java/de/thm/arsnova/controller/SecurityExceptionControllerAdvice.java b/src/main/java/de/thm/arsnova/controller/SecurityExceptionControllerAdvice.java index 128b63deee558a262977839c0b48c48d5845e603..48111c5360011167dedacd79ff9afb99374bf54d 100644 --- a/src/main/java/de/thm/arsnova/controller/SecurityExceptionControllerAdvice.java +++ b/src/main/java/de/thm/arsnova/controller/SecurityExceptionControllerAdvice.java @@ -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 */ } } diff --git a/src/main/java/de/thm/arsnova/controller/SessionController.java b/src/main/java/de/thm/arsnova/controller/SessionController.java index e27e60fbe04a772d555fe9112e25087d9f37f3e6..fb5ad95f66c81cb3d7ba9104da0fe541974957ff 100644 --- a/src/main/java/de/thm/arsnova/controller/SessionController.java +++ b/src/main/java/de/thm/arsnova/controller/SessionController.java @@ -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()); diff --git a/src/main/java/de/thm/arsnova/controller/SocketController.java b/src/main/java/de/thm/arsnova/controller/SocketController.java index 266c22eb756c0cc97af76b0040a9d1d70bdd19dd..63c9fb35a683f991710b8d57b3af9b811fcafb86 100644 --- a/src/main/java/de/thm/arsnova/controller/SocketController.java +++ b/src/main/java/de/thm/arsnova/controller/SocketController.java @@ -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; } diff --git a/src/main/java/de/thm/arsnova/controller/UserController.java b/src/main/java/de/thm/arsnova/controller/UserController.java index c036beec807c37a5965efe91684082d4f2904b90..6f955b5a8e10c17c637ac95cc90ae95301fe643b 100644 --- a/src/main/java/de/thm/arsnova/controller/UserController.java +++ b/src/main/java/de/thm/arsnova/controller/UserController.java @@ -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) diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index 326f0fa95dceda9641d2668c66e95e33ab81bf22..3a4f898471fd058a6f25dea64a660fc08691a1a1 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -39,6 +39,7 @@ import net.sf.ezmorph.bean.BeanMorpher; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import net.sf.json.util.JSONUtils; +import org.checkerframework.checker.nullness.qual.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.aop.framework.AopContext; @@ -81,7 +82,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; @Component("databaseDao") public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware { - private final int BULK_PARTITION_SIZE = 500; + private static final int BULK_PARTITION_SIZE = 500; @Autowired private ISessionService sessionService; @@ -95,7 +96,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware private final Queue<AbstractMap.SimpleEntry<Document, AnswerQueueElement>> answerQueue = new ConcurrentLinkedQueue<>(); - public static final Logger LOGGER = LoggerFactory.getLogger(CouchDBDao.class); + private static final Logger logger = LoggerFactory.getLogger(CouchDBDao.class); @Value("${couchdb.host}") public void setDatabaseHost(final String newDatabaseHost) { @@ -122,7 +123,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware * implemented (e.g. use of AspectJ's weaving). * @return the proxy for CouchDBDao */ - private IDatabaseDao getDatabaseDao() { + private @NonNull IDatabaseDao getDatabaseDao() { return (IDatabaseDao) AopContext.currentProxy(); } @@ -142,7 +143,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware try { database.saveDocument(d); } catch (final IOException e) { - LOGGER.error("Logging of '{}' event to database failed.", event); + logger.error("Logging of '{}' event to database failed.", event); } } @@ -534,7 +535,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware if (document.has("keyword")) { return (String) document.get("keyword"); } - LOGGER.error("No session found for internal id: {}", internalSessionId); + logger.error("No session found for internal id: {}", internalSessionId); return null; } @@ -547,7 +548,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware ); database = session.getDatabase(databaseName); } catch (final Exception e) { - LOGGER.error( + logger.error( "Cannot connect to CouchDB database '" + databaseName + "' on host '" + databaseHost + "' using port " + databasePort @@ -572,7 +573,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware question.set_rev(q.getRev()); return question; } catch (final IOException e) { - LOGGER.error("Could not save question {}", question); + logger.error("Could not save question {}", question); } return null; } @@ -703,7 +704,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return question; } catch (final IOException e) { - LOGGER.error("Could not update question {}", question); + logger.error("Could not update question {}", question); } return null; @@ -730,7 +731,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return question; } catch (final IOException e) { - LOGGER.error("Could not save interposed question {}", question); + logger.error("Could not save interposed question {}", question); } return null; @@ -754,7 +755,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware question.setSessionKeyword(getSessionKeyword(question.getSessionId())); return question; } catch (final IOException e) { - LOGGER.error("Could not get question with id {}", id); + logger.error("Could not get question with id {}", id); } return null; } @@ -828,7 +829,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware getDatabase().saveDocument(new Document(json)); return session; } catch (final IOException e) { - LOGGER.error("Failed to update lastOwnerActivity for Session {}", session); + logger.error("Failed to update lastOwnerActivity for Session {}", session); return session; } } @@ -855,7 +856,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return count; } catch (final IOException e) { - LOGGER.error("IOException: Could not delete question {}", question.get_id()); + logger.error("IOException: Could not delete question {}", question.get_id()); } return 0; @@ -918,14 +919,14 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware if (database.bulkSaveDocuments(answersToDelete.toArray(new Document[answersToDelete.size()]))) { count += partition.size(); } else { - LOGGER.error("Could not bulk delete answers"); + logger.error("Could not bulk delete answers"); } } log("delete", "type", "answer", "answerCount", count); return count; } catch (final IOException e) { - LOGGER.error("IOException: Could not delete answers for question {}", question.get_id()); + logger.error("IOException: Could not delete answers for question {}", question.get_id()); } return 0; @@ -1043,7 +1044,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware view.setKey(questionId); view.setGroup(true); final ViewResults results = getDatabase().view(view); - if (results.getResults().size() == 0) { + if (results.getResults().isEmpty()) { return 0; } return results.getJSONArray("rows").optJSONObject(0).optInt("value"); @@ -1056,7 +1057,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware view.setStartKey(question.get_id(), String.valueOf(piRound)); view.setEndKey(question.get_id(), String.valueOf(piRound), "{}"); final ViewResults results = getDatabase().view(view); - if (results.getResults().size() == 0) { + if (results.getResults().isEmpty()) { return 0; } @@ -1070,7 +1071,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware view.setKey(question.get_id()); final ViewResults results = getDatabase().view(view); - if (results.getResults().size() == 0) { + if (results.getResults().isEmpty()) { return 0; } @@ -1078,7 +1079,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware } private boolean isEmptyResults(final ViewResults results) { - return results == null || results.getResults().isEmpty() || results.getJSONArray("rows").size() == 0; + return results == null || results.getResults().isEmpty() || results.getJSONArray("rows").isEmpty(); } @Override @@ -1136,7 +1137,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware final NovaView view = new NovaView("skill_question/count_answers_by_session"); view.setKey(s.get_id()); final ViewResults results = getDatabase().view(view); - if (results.getResults().size() == 0) { + if (results.getResults().isEmpty()) { return 0; } return results.getJSONArray("rows").optJSONObject(0).optInt("value"); @@ -1153,7 +1154,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware view.setKey(s.get_id()); view.setGroup(true); final ViewResults results = getDatabase().view(view); - if (results.size() == 0 || results.getResults().size() == 0) { + if (results.isEmpty() || results.getResults().isEmpty()) { return 0; } return results.getJSONArray("rows").optJSONObject(0).optInt("value"); @@ -1179,7 +1180,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware private InterposedReadingCount getInterposedReadingCount(final NovaView view) { final ViewResults results = getDatabase().view(view); - if (results.size() == 0 || results.getResults().size() == 0) { + if (results.isEmpty() || results.getResults().isEmpty()) { return new InterposedReadingCount(); } // A complete result looks like this. Note that the second row is optional, and that the first one may be @@ -1199,9 +1200,9 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware } else if (fstkey.size() == 3) { type = fstkey.getString(2); } - if (type.equals("read")) { + if ("read".equals(type)) { read = fst.optInt("value"); - } else if (type.equals("unread")) { + } else if ("unread".equals(type)) { unread = fst.optInt("value"); } @@ -1212,9 +1213,9 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware } else { type = sndkey.getString(2); } - if (type.equals("read")) { + if ("read".equals(type)) { read = snd.optInt("value"); - } else if (type.equals("unread")) { + } else if ("unread".equals(type)) { unread = snd.optInt("value"); } } @@ -1347,7 +1348,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware } return stats; } catch (final Exception e) { - LOGGER.error("Error while retrieving session count", e); + logger.error("Error while retrieving session count", e); } return stats; } @@ -1361,7 +1362,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware question.setSessionId(getSessionKeyword(question.getSessionId())); return question; } catch (final IOException e) { - LOGGER.error("Could not load interposed question {}", questionId); + logger.error("Could not load interposed question {}", questionId); } return null; } @@ -1374,7 +1375,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware document.put("read", question.isRead()); getDatabase().saveDocument(document); } catch (final IOException e) { - LOGGER.error("Could not mark interposed question as read {}", question.get_id()); + logger.error("Could not mark interposed question as read {}", question.get_id()); } } @@ -1439,7 +1440,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware final Document doc = new Document(json); getDatabase().saveDocument(doc); } catch (IOException e) { - LOGGER.error("Could not clean up logged_in document of {}", user.getUsername()); + logger.error("Could not clean up logged_in document of {}", user.getUsername()); } return result; } @@ -1505,7 +1506,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware final Document doc = new Document(json); getDatabase().saveDocument(doc); } catch (IOException e) { - LOGGER.error("Could not clean up logged_in document of {}", username); + logger.error("Could not clean up logged_in document of {}", username); } return result; } @@ -1572,7 +1573,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware this.publisher.publishEvent(new NewAnswerEvent(this, e.getSession(), e.getAnswer(), e.getUser(), e.getQuestion())); } } catch (IOException e) { - LOGGER.error("Could not bulk save answers from queue"); + logger.error("Could not bulk save answers from queue"); } } @@ -1596,7 +1597,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware answer.set_rev(a.getRev()); return answer; } catch (final IOException e) { - LOGGER.error("Could not save answer {}", answer); + logger.error("Could not save answer {}", answer); } return null; } @@ -1609,7 +1610,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware database.deleteDocument(database.getDocument(answerId)); log("delete", "type", "answer"); } catch (final IOException e) { - LOGGER.error("Could not delete answer {} because of {}", answerId, e.getMessage()); + logger.error("Could not delete answer {} because of {}", answerId, e.getMessage()); } } @@ -1619,7 +1620,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware deleteDocument(question.get_id()); log("delete", "type", "comment"); } catch (final IOException e) { - LOGGER.error("Could not delete interposed question {} because of {}", question.get_id(), e.getMessage()); + logger.error("Could not delete interposed question {} because of {}", question.get_id(), e.getMessage()); } } @@ -1692,7 +1693,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return session; } catch (final IOException e) { - LOGGER.error("Could not lock session {}", session); + logger.error("Could not lock session {}", session); } return null; @@ -1707,7 +1708,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware database.saveDocument(s); session.set_rev(s.getRev()); } catch (final IOException e) { - LOGGER.error("Could not lock session {}", session); + logger.error("Could not lock session {}", session); } return session; @@ -1720,10 +1721,10 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware try { count = deleteAllQuestionsWithAnswers(session); deleteDocument(session.get_id()); - LOGGER.debug("Deleted session document {} and related data.", session.get_id()); + logger.debug("Deleted session document {} and related data.", session.get_id()); log("delete", "type", "session", "id", session.get_id()); } catch (final IOException e) { - LOGGER.error("Could not delete session {}", session); + logger.error("Could not delete session {}", session); } return count; @@ -1745,8 +1746,8 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware count[2] += qaCount[1]; } - if (results.size() > 0) { - LOGGER.info("Deleted {} inactive guest sessions.", results.size()); + if (!results.isEmpty()) { + logger.info("Deleted {} inactive guest sessions.", results.size()); log("cleanup", "type", "session", "sessionCount", results.size(), "questionCount", count[1], "answerCount", count[2]); } count[0] = results.size(); @@ -1771,28 +1772,28 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware newDoc.setRev(oldDoc.getJSONObject("value").getString("_rev")); newDoc.put("_deleted", true); newDocs.add(newDoc); - LOGGER.debug("Marked logged_in document {} for deletion.", oldDoc.getId()); + logger.debug("Marked logged_in document {} for deletion.", oldDoc.getId()); /* Use log type 'user' since effectively the user is deleted in case of guests */ log("delete", "type", "user", "id", oldDoc.getId()); } - if (newDocs.size() > 0) { + if (!newDocs.isEmpty()) { if (getDatabase().bulkSaveDocuments(newDocs.toArray(new Document[newDocs.size()]))) { count += newDocs.size(); } else { - LOGGER.error("Could not bulk delete visited session lists"); + logger.error("Could not bulk delete visited session lists"); } } } if (count > 0) { - LOGGER.info("Deleted {} visited session lists of inactive users.", count); + logger.info("Deleted {} visited session lists of inactive users.", count); log("cleanup", "type", "visitedsessions", "count", count); } return count; } catch (IOException e) { - LOGGER.error("Could not delete visited session lists of inactive users."); + logger.error("Could not delete visited session lists of inactive users."); } return 0; @@ -1917,7 +1918,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware final NovaView view = new NovaView("skill_question/count_answers_by_session_and_question_variant"); view.setKey(session.get_id(), variant); final ViewResults results = getDatabase().view(view); - if (results.getResults().size() == 0) { + if (results.getResults().isEmpty()) { return 0; } return results.getJSONArray("rows").optJSONObject(0).optInt("value"); @@ -2015,7 +2016,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware private List<String> collectQuestionIds(final NovaView view) { final ViewResults results = getDatabase().view(view); - if (results.getResults().size() == 0) { + if (results.getResults().isEmpty()) { return new ArrayList<>(); } final List<String> ids = new ArrayList<>(); @@ -2053,7 +2054,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware try { deleteDocument(document.getId()); } catch (final IOException e) { - LOGGER.error("Could not delete all interposed questions {}", session); + logger.error("Could not delete all interposed questions {}", session); } } @@ -2090,7 +2091,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware try { database.bulkSaveDocuments(documents.toArray(new Document[documents.size()])); } catch (final IOException e) { - LOGGER.error("Could not bulk publish all questions: {}", e.getMessage()); + logger.error("Could not bulk publish all questions: {}", e.getMessage()); } } @@ -2109,7 +2110,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware @Override public void setVotingAdmissions(final Session session, final boolean disableVoting, List<Question> questions) { for (final Question q : questions) { - if (!q.getQuestionType().equals("flashcard")) { + if (!"flashcard".equals(q.getQuestionType())) { q.setVotingDisabled(disableVoting); } } @@ -2124,7 +2125,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware try { database.bulkSaveDocuments(documents.toArray(new Document[documents.size()])); } catch (final IOException e) { - LOGGER.error("Could not bulk set voting admission for all questions: {}", e.getMessage()); + logger.error("Could not bulk set voting admission for all questions: {}", e.getMessage()); } } @@ -2178,7 +2179,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware try { database.bulkSaveDocuments(documents.toArray(new Document[documents.size()])); } catch (final IOException e) { - LOGGER.error("Could not bulk reset all questions round state: {}", e.getMessage()); + logger.error("Could not bulk reset all questions round state: {}", e.getMessage()); } } @@ -2202,7 +2203,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return allAnswers.size(); } catch (IOException e) { - LOGGER.error("Could not bulk delete answers: {}", e.getMessage()); + logger.error("Could not bulk delete answers: {}", e.getMessage()); } return 0; @@ -2238,7 +2239,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return new int[] {deleteList.size(), result.size()}; } catch (IOException e) { - LOGGER.error("Could not bulk delete questions and answers: {}", e.getMessage()); + logger.error("Could not bulk delete questions and answers: {}", e.getMessage()); } return new int[] {0, 0}; @@ -2311,7 +2312,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return user; } catch (IOException e) { - LOGGER.error("Could not save user {}", user); + logger.error("Could not save user {}", user); } return null; @@ -2341,7 +2342,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return true; } catch (IOException e) { - LOGGER.error("Could not delete user {}", dbUser.getId()); + logger.error("Could not delete user {}", dbUser.getId()); } return false; @@ -2364,7 +2365,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware newDoc.setRev(oldDoc.getJSONObject("value").getString("_rev")); newDoc.put("_deleted", true); newDocs.add(newDoc); - LOGGER.debug("Marked user document {} for deletion.", oldDoc.getId()); + logger.debug("Marked user document {} for deletion.", oldDoc.getId()); } if (newDocs.size() > 0) { @@ -2375,13 +2376,13 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware } if (count > 0) { - LOGGER.info("Deleted {} inactive users.", count); + logger.info("Deleted {} inactive users.", count); log("cleanup", "type", "user", "count", count); } return count; } catch (IOException e) { - LOGGER.error("Could not delete inactive users."); + logger.error("Could not delete inactive users."); } return 0; @@ -2466,7 +2467,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware database.bulkSaveDocuments(motds.toArray(new Document[motds.size()])); database.bulkSaveDocuments(documents.toArray(new Document[documents.size()])); } catch (IOException e) { - LOGGER.error("Could not import this session: {}", e.getMessage()); + logger.error("Could not import this session: {}", e.getMessage()); // Something went wrong, delete this session since we do not want a partial import this.deleteSession(session); return null; @@ -2526,7 +2527,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware } for (ImportExportQuestion question : importExportSession.getQuestions()) { numAnswers += question.getAnswers().size(); - if (question.getAnswers().size() == 0) { + if (question.getAnswers().isEmpty()) { numUnanswered++; } } @@ -2605,7 +2606,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware final Morpher dynaMorpher = new BeanMorpher(PossibleAnswer.class, morpherRegistry); morpherRegistry.registerMorpher(dynaMorpher); for (final Document document : questiondocs) { - if (!document.optString("error").equals("")) { + if (!"".equals(document.optString("error"))) { // Skip documents we could not load. Maybe they were deleted. continue; } @@ -2752,7 +2753,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return motd; } catch (IOException e) { - LOGGER.error("Could not save motd {}", motd); + logger.error("Could not save motd {}", motd); } return null; @@ -2764,7 +2765,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware try { this.deleteDocument(motd.get_id()); } catch (IOException e) { - LOGGER.error("Could not delete Motd {}", motd.get_id()); + logger.error("Could not delete Motd {}", motd.get_id()); } } @@ -2807,7 +2808,7 @@ public class CouchDBDao implements IDatabaseDao, ApplicationEventPublisherAware return motdlist; } catch (IOException e) { - LOGGER.error("Could not save motdlist {}", motdlist); + logger.error("Could not save motdlist {}", motdlist); } return null; diff --git a/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java b/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java index ce43f96393cdaa36b6b5e07ce49cbabdda08b665..89a750ce1675bf3fe33d75f571413499b4124ef9 100644 --- a/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java +++ b/src/main/java/de/thm/arsnova/domain/LearningProgressFactory.java @@ -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); diff --git a/src/main/java/de/thm/arsnova/domain/QuestionScore.java b/src/main/java/de/thm/arsnova/domain/QuestionScore.java index f57d46ed42b0d18b2c3becbb44d4f10268825880..32b5b6f52d6d89331a5eee267292a8543c9bfdff 100644 --- a/src/main/java/de/thm/arsnova/domain/QuestionScore.java +++ b/src/main/java/de/thm/arsnova/domain/QuestionScore.java @@ -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) { diff --git a/src/main/java/de/thm/arsnova/entities/Motd.java b/src/main/java/de/thm/arsnova/entities/Motd.java index 9a716f8f302d7649aa030bf3bf05b38cef900fcf..0e702ca7d1be71eb3c724ffe641f4ab53a744de6 100644 --- a/src/main/java/de/thm/arsnova/entities/Motd.java +++ b/src/main/java/de/thm/arsnova/entities/Motd.java @@ -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()); } } diff --git a/src/main/java/de/thm/arsnova/entities/Question.java b/src/main/java/de/thm/arsnova/entities/Question.java index c88c4c534e37fbb16260b64b60be2f2d13f0aa3e..a99670287ba7b6ce8c87f1bdbc730db9c2969e0e 100644 --- a/src/main/java/de/thm/arsnova/entities/Question.java +++ b/src/main/java/de/thm/arsnova/entities/Question.java @@ -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(); } diff --git a/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java b/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java index 02a01e975c8818aa1cbdac2b65a06c85ac535c55..baa9672428bb50416b55204dae415a961dc910c9 100644 --- a/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java +++ b/src/main/java/de/thm/arsnova/entities/transport/ImportExportSession.java @@ -155,10 +155,6 @@ public class ImportExportSession { private List<Answer> answers; - public ImportExportQuestion() { - - } - public ImportExportQuestion(Question q) { setType(q.getType()); setQuestionType(q.getQuestionType()); diff --git a/src/main/java/de/thm/arsnova/events/LockVoteEvent.java b/src/main/java/de/thm/arsnova/events/LockVoteEvent.java index a3831c9983cede362aa9efe5ed0c3cb99d8c4aba..b33922f4f25bdc75a5df1a520fffce1e14c0b548 100644 --- a/src/main/java/de/thm/arsnova/events/LockVoteEvent.java +++ b/src/main/java/de/thm/arsnova/events/LockVoteEvent.java @@ -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()); diff --git a/src/main/java/de/thm/arsnova/events/PiRoundDelayedStartEvent.java b/src/main/java/de/thm/arsnova/events/PiRoundDelayedStartEvent.java index 6b3418d9addc6034b6d6f220621c68cb295856ce..6fdc587e38791ae1c56c54e2fa329841dd93b9f2 100644 --- a/src/main/java/de/thm/arsnova/events/PiRoundDelayedStartEvent.java +++ b/src/main/java/de/thm/arsnova/events/PiRoundDelayedStartEvent.java @@ -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()); diff --git a/src/main/java/de/thm/arsnova/events/PiRoundEndEvent.java b/src/main/java/de/thm/arsnova/events/PiRoundEndEvent.java index 0d1d5df8374d86cb71e420d7293449eb3575eaf2..b87d12590bdd7e3667d7998367b86cbb4514b07d 100644 --- a/src/main/java/de/thm/arsnova/events/PiRoundEndEvent.java +++ b/src/main/java/de/thm/arsnova/events/PiRoundEndEvent.java @@ -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()); diff --git a/src/main/java/de/thm/arsnova/events/PiRoundResetEvent.java b/src/main/java/de/thm/arsnova/events/PiRoundResetEvent.java index 92a7095fc2279f1dedddbd5360ef281b15709a08..429aeb274c1b26fecbc1f779734316a9d2835ca1 100644 --- a/src/main/java/de/thm/arsnova/events/PiRoundResetEvent.java +++ b/src/main/java/de/thm/arsnova/events/PiRoundResetEvent.java @@ -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()); diff --git a/src/main/java/de/thm/arsnova/events/UnlockVoteEvent.java b/src/main/java/de/thm/arsnova/events/UnlockVoteEvent.java index ef3bf8c7b279966a2157ea05de3dc1d8c01d9040..69a1f45717e077339a28267700a43a8e6123703a 100644 --- a/src/main/java/de/thm/arsnova/events/UnlockVoteEvent.java +++ b/src/main/java/de/thm/arsnova/events/UnlockVoteEvent.java @@ -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()); diff --git a/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java b/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java index fef4edb33b41064fb2dd86de6f742e122dfe734f..bf0614506309d12e2f9474dce177e6174c71a9d7 100644 --- a/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java +++ b/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java @@ -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 { private boolean checkAdminPermission(final String username) { /* TODO: only allow accounts from arsnova db */ - String[] splittedAdminNames = adminAccounts.split(","); - - return Arrays.asList(splittedAdminNames).contains(username); + return Arrays.asList(adminAccounts).contains(username); } private boolean checkSessionPermission( @@ -109,9 +103,9 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator { final Serializable targetId, final Object permission ) { - if (permission instanceof String && (permission.equals("owner") || permission.equals("write"))) { + if (permission instanceof String && ("owner".equals(permission) || "write".equals(permission))) { return dao.getSessionFromKeyword(targetId.toString()).getCreator().equals(username); - } else if (permission instanceof String && permission.equals("read")) { + } else if (permission instanceof String && "read".equals(permission)) { return dao.getSessionFromKeyword(targetId.toString()).isActive(); } return false; @@ -122,7 +116,7 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator { final Serializable targetId, final Object permission ) { - if (permission instanceof String && permission.equals("owner")) { + if (permission instanceof String && "owner".equals(permission)) { final Question question = dao.getQuestion(targetId.toString()); if (question != null) { final Session session = dao.getSessionFromId(question.getSessionId()); @@ -138,7 +132,7 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator { final Serializable targetId, final Object permission ) { - if (permission instanceof String && permission.equals("owner")) { + if (permission instanceof String && "owner".equals(permission)) { final InterposedQuestion question = dao.getInterposedQuestion(targetId.toString()); if (question != null) { // Does the creator want to delete his own question? diff --git a/src/main/java/de/thm/arsnova/security/CustomLdapUserDetailsMapper.java b/src/main/java/de/thm/arsnova/security/CustomLdapUserDetailsMapper.java index b2ab7c991164fcb9b96b1b387956d3da5c0c8db8..34e4af94487c6e368be994ea37d2407d606c38c9 100644 --- a/src/main/java/de/thm/arsnova/security/CustomLdapUserDetailsMapper.java +++ b/src/main/java/de/thm/arsnova/security/CustomLdapUserDetailsMapper.java @@ -31,7 +31,7 @@ import java.util.Collection; * to get a consistent ID despite case insensitivity. */ public class CustomLdapUserDetailsMapper extends LdapUserDetailsMapper { - public static final Logger LOGGER = LoggerFactory.getLogger(CustomLdapUserDetailsMapper.class); + private static final Logger logger = LoggerFactory.getLogger(CustomLdapUserDetailsMapper.class); private String userIdAttr; @@ -43,7 +43,7 @@ public class CustomLdapUserDetailsMapper extends LdapUserDetailsMapper { Collection<? extends GrantedAuthority> authorities) { String ldapUsername = ctx.getStringAttribute(userIdAttr); if (ldapUsername == null) { - LOGGER.warn("LDAP attribute {} not set. Falling back to lowercased user provided username.", userIdAttr); + logger.warn("LDAP attribute {} not set. Falling back to lowercased user provided username.", userIdAttr); ldapUsername = username.toLowerCase(); } diff --git a/src/main/java/de/thm/arsnova/security/DbUserDetailsService.java b/src/main/java/de/thm/arsnova/security/DbUserDetailsService.java index d7fe14a6217b8db0c3935d19d6a03583658032ff..cb1000e97b2668b3071b7ded3a8b989974452481 100644 --- a/src/main/java/de/thm/arsnova/security/DbUserDetailsService.java +++ b/src/main/java/de/thm/arsnova/security/DbUserDetailsService.java @@ -41,13 +41,13 @@ public class DbUserDetailsService implements UserDetailsService { @Autowired private IDatabaseDao dao; - public static final Logger LOGGER = LoggerFactory + private static final Logger logger = LoggerFactory .getLogger(DbUserDetailsService.class); @Override public UserDetails loadUserByUsername(String username) { String uid = username.toLowerCase(); - LOGGER.debug("Load user: " + uid); + logger.debug("Load user: " + uid); DbUser dbUser = dao.getUser(uid); if (null == dbUser) { throw new UsernameNotFoundException("User does not exist."); diff --git a/src/main/java/de/thm/arsnova/services/MotdService.java b/src/main/java/de/thm/arsnova/services/MotdService.java index f4ac031e2cc3efe25bf4b4f0084d02cd23e7162b..ecda866383aadd4023b44847a43ed788ef50ff18 100644 --- a/src/main/java/de/thm/arsnova/services/MotdService.java +++ b/src/main/java/de/thm/arsnova/services/MotdService.java @@ -170,7 +170,7 @@ public class MotdService implements IMotdService { @PreAuthorize("isAuthenticated()") public MotdList getMotdListForUser(final String username) { final User user = userService.getCurrentUser(); - if (username.equals(user.getUsername()) && !user.getType().equals("guest")) { + if (username.equals(user.getUsername()) && !"guest".equals(user.getType())) { return databaseDao.getMotdListForUser(username); } return null; diff --git a/src/main/java/de/thm/arsnova/services/QuestionService.java b/src/main/java/de/thm/arsnova/services/QuestionService.java index 014539fd6a4725772bdf0261b5ada27bffed22ba..275adfedb352fec8660d4101285c27f0abfad2f8 100644 --- a/src/main/java/de/thm/arsnova/services/QuestionService.java +++ b/src/main/java/de/thm/arsnova/services/QuestionService.java @@ -67,7 +67,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis private ApplicationEventPublisher publisher; - public static final Logger LOGGER = LoggerFactory.getLogger(QuestionService.class); + private static final Logger logger = LoggerFactory.getLogger(QuestionService.class); private HashMap<String, Timer> timerList = new HashMap<>(); @@ -112,7 +112,7 @@ public class QuestionService implements IQuestionService, ApplicationEventPublis // base64 adds offset to filesize, formula taken from: http://en.wikipedia.org/wiki/Base64#MIME final int fileSize = (int) ((question.getImage().length() - 814) / 1.37); if (fileSize > uploadFileSizeByte) { - LOGGER.error("Could not save file. File is too large with " + fileSize + " Byte."); + logger.error("Could not save file. File is too large with " + fileSize + " Byte."); throw new BadRequestException(); } } diff --git a/src/main/java/de/thm/arsnova/services/SessionService.java b/src/main/java/de/thm/arsnova/services/SessionService.java index f6507520741a29c7ebc86083b1fbfad86cf5782a..7ea54a72eabbf8781455a06639e139927835c10a 100644 --- a/src/main/java/de/thm/arsnova/services/SessionService.java +++ b/src/main/java/de/thm/arsnova/services/SessionService.java @@ -126,12 +126,12 @@ public class SessionService implements ISessionService, ApplicationEventPublishe private ApplicationEventPublisher publisher; - public static final Logger LOGGER = LoggerFactory.getLogger(SessionService.class); + private static final Logger logger = LoggerFactory.getLogger(SessionService.class); @Scheduled(fixedDelay = SESSION_INACTIVITY_CHECK_INTERVAL_MS) public void deleteInactiveSessions() { if (guestSessionInactivityThresholdDays > 0) { - LOGGER.info("Delete inactive sessions."); + logger.info("Delete inactive sessions."); long unixTime = System.currentTimeMillis(); long lastActivityBefore = unixTime - guestSessionInactivityThresholdDays * 24 * 60 * 60 * 1000L; databaseDao.deleteInactiveGuestSessions(lastActivityBefore); @@ -141,7 +141,7 @@ public class SessionService implements ISessionService, ApplicationEventPublishe @Scheduled(fixedDelay = SESSION_INACTIVITY_CHECK_INTERVAL_MS) public void deleteInactiveVisitedSessionLists() { if (guestSessionInactivityThresholdDays > 0) { - LOGGER.info("Delete lists of visited session for inactive users."); + logger.info("Delete lists of visited session for inactive users."); long unixTime = System.currentTimeMillis(); long lastActivityBefore = unixTime - guestSessionInactivityThresholdDays * 24 * 60 * 60 * 1000L; databaseDao.deleteInactiveGuestVisitedSessionLists(lastActivityBefore); @@ -508,7 +508,7 @@ public class SessionService implements ISessionService, ApplicationEventPublishe // base64 adds offset to filesize, formula taken from: http://en.wikipedia.org/wiki/Base64#MIME final int fileSize = (int) ((session.getPpLogo().length() - 814) / 1.37); if (fileSize > uploadFileSizeByte) { - LOGGER.error("Could not save file. File is too large with " + fileSize + " Byte."); + logger.error("Could not save file. File is too large with " + fileSize + " Byte."); throw new PayloadTooLargeException(); } } diff --git a/src/main/java/de/thm/arsnova/services/UserService.java b/src/main/java/de/thm/arsnova/services/UserService.java index e68d0e6a728428b47057f41c1f2324402c027182..9df1adffdeec7400e11a17dd9f10133f005a53f1 100644 --- a/src/main/java/de/thm/arsnova/services/UserService.java +++ b/src/main/java/de/thm/arsnova/services/UserService.java @@ -88,7 +88,7 @@ public class UserService implements IUserService { private static final long ACTIVATION_KEY_CHECK_INTERVAL_MS = 30 * 60 * 1000L; private static final long ACTIVATION_KEY_DURABILITY_MS = 6 * 60 * 60 * 1000L; - public static final Logger LOGGER = LoggerFactory.getLogger(UserService.class); + private static final Logger logger = LoggerFactory.getLogger(UserService.class); private static final ConcurrentHashMap<UUID, User> socketid2user = new ConcurrentHashMap<>(); @@ -153,23 +153,23 @@ public class UserService implements IUserService { @Scheduled(fixedDelay = LOGIN_TRY_RESET_DELAY_MS) public void resetLoginTries() { - if (loginTries.size() > 0) { - LOGGER.debug("Reset failed login counters."); + if (!loginTries.isEmpty()) { + logger.debug("Reset failed login counters."); loginTries.clear(); } } @Scheduled(fixedDelay = LOGIN_BAN_RESET_DELAY_MS) public void resetLoginBans() { - if (loginBans.size() > 0) { - LOGGER.info("Reset temporary login bans."); + if (!loginBans.isEmpty()) { + logger.info("Reset temporary login bans."); loginBans.clear(); } } @Scheduled(fixedDelay = ACTIVATION_KEY_CHECK_INTERVAL_MS) public void deleteInactiveUsers() { - LOGGER.info("Delete inactive users."); + logger.info("Delete inactive users."); long unixTime = System.currentTimeMillis(); long lastActivityBefore = unixTime - ACTIVATION_KEY_DURABILITY_MS; databaseDao.deleteInactiveUsers(lastActivityBefore); @@ -202,7 +202,7 @@ public class UserService implements IUserService { } } - if (user == null || user.getUsername().equals("anonymous")) { + if (user == null || "anonymous".equals(user.getUsername())) { throw new UnauthorizedException(); } @@ -241,7 +241,7 @@ public class UserService implements IUserService { if (tries < loginTryLimit) { loginTries.put(addr, ++tries); if (loginTryLimit == tries) { - LOGGER.info("Temporarily banned {} from login.", new Object[] {addr}); + logger.info("Temporarily banned {} from login.", new Object[] {addr}); loginBans.add(addr); } } @@ -301,7 +301,7 @@ public class UserService implements IUserService { public void removeUserFromSessionBySocketId(final UUID socketId) { final User user = socketid2user.get(socketId); if (null == user) { - LOGGER.warn("null == user for socket {}", socketId); + logger.warn("null == user for socket {}", socketId); return; } @@ -321,7 +321,7 @@ public class UserService implements IUserService { @PreDestroy public void destroy() { - LOGGER.error("Destroy UserService"); + logger.error("Destroy UserService"); } @Override @@ -355,13 +355,13 @@ public class UserService implements IUserService { } if (null == mailPattern || !mailPattern.matcher(lcUsername).matches()) { - LOGGER.info("User registration failed. {} does not match pattern.", lcUsername); + logger.info("User registration failed. {} does not match pattern.", lcUsername); return null; } if (null != databaseDao.getUser(lcUsername)) { - LOGGER.info("User registration failed. {} already exists.", lcUsername); + logger.info("User registration failed. {} already exists.", lcUsername); return null; } @@ -376,7 +376,7 @@ public class UserService implements IUserService { if (null != result) { sendActivationEmail(result); } else { - LOGGER.error("User registration failed. {} could not be created.", lcUsername); + logger.error("User registration failed. {} could not be created.", lcUsername); } return result; @@ -402,7 +402,7 @@ public class UserService implements IUserService { dbUser.getActivationKey() ); } catch (UnsupportedEncodingException e1) { - LOGGER.error(e1.getMessage()); + logger.error(e1.getMessage()); return; } @@ -415,7 +415,7 @@ public class UserService implements IUserService { List<String> domainList = Arrays.asList(allowedEmailDomains.split(",")); - if (domainList.size() > 0) { + if (!domainList.isEmpty()) { List<String> patterns = new ArrayList<>(); if (domainList.contains("*")) { patterns.add("([a-z0-9-]+\\.)+[a-z0-9-]+"); @@ -429,7 +429,7 @@ public class UserService implements IUserService { } mailPattern = Pattern.compile("[a-z0-9._-]+?@(" + StringUtils.join(patterns, "|") + ")", Pattern.CASE_INSENSITIVE); - LOGGER.info("Allowed e-mail addresses (pattern) for registration: " + mailPattern.pattern()); + logger.info("Allowed e-mail addresses (pattern) for registration: " + mailPattern.pattern()); } } @@ -465,12 +465,12 @@ public class UserService implements IUserService { public void initiatePasswordReset(String username) { DbUser dbUser = getDbUser(username); if (null == dbUser) { - LOGGER.info("Password reset failed. User {} does not exist.", username); + logger.info("Password reset failed. User {} does not exist.", username); throw new NotFoundException(); } if (System.currentTimeMillis() < dbUser.getPasswordResetTime() + REPEATED_PASSWORD_RESET_DELAY_MS) { - LOGGER.info("Password reset failed. The reset delay for User {} is still active.", username); + logger.info("Password reset failed. The reset delay for User {} is still active.", username); throw new BadRequestException(); } @@ -479,7 +479,7 @@ public class UserService implements IUserService { dbUser.setPasswordResetTime(System.currentTimeMillis()); if (null == databaseDao.createOrUpdateUser(dbUser)) { - LOGGER.error("Password reset failed. {} could not be updated.", username); + logger.error("Password reset failed. {} could not be updated.", username); } String resetPasswordUrl; @@ -493,7 +493,7 @@ public class UserService implements IUserService { dbUser.getPasswordResetKey() ); } catch (UnsupportedEncodingException e1) { - LOGGER.error(e1.getMessage()); + logger.error(e1.getMessage()); return; } @@ -504,12 +504,12 @@ public class UserService implements IUserService { @Override public boolean resetPassword(DbUser dbUser, String key, String password) { if (null == key || "".equals(key) || !key.equals(dbUser.getPasswordResetKey())) { - LOGGER.info("Password reset failed. Invalid key provided for User {}.", dbUser.getUsername()); + logger.info("Password reset failed. Invalid key provided for User {}.", dbUser.getUsername()); return false; } if (System.currentTimeMillis() > dbUser.getPasswordResetTime() + PASSWORD_RESET_KEY_DURABILITY_MS) { - LOGGER.info("Password reset failed. Key provided for User {} is no longer valid.", dbUser.getUsername()); + logger.info("Password reset failed. Key provided for User {} is no longer valid.", dbUser.getUsername()); dbUser.setPasswordResetKey(null); dbUser.setPasswordResetTime(0); @@ -521,7 +521,7 @@ public class UserService implements IUserService { dbUser.setPassword(encodePassword(password)); dbUser.setPasswordResetKey(null); if (null == updateDbUser(dbUser)) { - LOGGER.error("Password reset failed. {} could not be updated.", dbUser.getUsername()); + logger.error("Password reset failed. {} could not be updated.", dbUser.getUsername()); } return true; @@ -536,10 +536,10 @@ public class UserService implements IUserService { helper.setSubject(subject); helper.setText(body); - LOGGER.info("Sending mail \"{}\" from \"{}\" to \"{}\"", subject, msg.getFrom(), dbUser.getUsername()); + logger.info("Sending mail \"{}\" from \"{}\" to \"{}\"", subject, msg.getFrom(), dbUser.getUsername()); mailSender.send(msg); } catch (MailException | MessagingException e) { - LOGGER.warn("Mail \"{}\" could not be sent: {}", subject, e); + logger.warn("Mail \"{}\" could not be sent: {}", subject, e); } } } diff --git a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java index 8df42e0895c0d5f049fb4bedbc5b0c52d6bf8269..0b91b686e7ffed245f728c7be80c5965990e7fe5 100644 --- a/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java +++ b/src/main/java/de/thm/arsnova/socket/ARSnovaSocketIOServer.java @@ -78,7 +78,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { @Autowired private IQuestionService questionService; - private static final Logger LOGGER = LoggerFactory.getLogger(ARSnovaSocketIOServer.class); + private static final Logger logger = LoggerFactory.getLogger(ARSnovaSocketIOServer.class); private int portNumber; private String hostIp; @@ -94,7 +94,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { @PreDestroy public void closeAllSessions() { - LOGGER.info("Close all websockets due to @PreDestroy"); + logger.info("Close all websockets due to @PreDestroy"); for (final SocketIOClient c : server.getAllClients()) { c.disconnect(); } @@ -104,7 +104,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { c.send(new Packet(PacketType.DISCONNECT)); clientCount++; } - LOGGER.info("Pending websockets at @PreDestroy: {}", clientCount); + logger.info("Pending websockets at @PreDestroy: {}", clientCount); server.stop(); } @@ -123,7 +123,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { config.setKeyStore(stream); config.setKeyStorePassword(storepass); } catch (final FileNotFoundException e) { - LOGGER.error("Keystore {} not found on filesystem", keystore); + logger.error("Keystore {} not found on filesystem", keystore); } } server = new SocketIOServer(config); @@ -134,7 +134,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { public void onData(final SocketIOClient client, final Feedback data, final AckRequest ackSender) { final User u = userService.getUser2SocketId(client.getSessionId()); if (u == null) { - LOGGER.info("Client {} tried to send feedback but is not mapped to a user", client.getSessionId()); + logger.info("Client {} tried to send feedback but is not mapped to a user", client.getSessionId()); return; } @@ -142,9 +142,9 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { final de.thm.arsnova.entities.Session session = sessionService.getSessionInternal(sessionKey, u); if (session.getFeedbackLock()) { - LOGGER.debug("Feedback save blocked: {}", u, sessionKey, data.getValue()); + logger.debug("Feedback save blocked: {}", u, sessionKey, data.getValue()); } else { - LOGGER.debug("Feedback recieved: {}", u, sessionKey, data.getValue()); + logger.debug("Feedback recieved: {}", u, sessionKey, data.getValue()); if (null != sessionKey) { feedbackService.saveFeedback(sessionKey, data.getValue(), u); } @@ -158,7 +158,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { public void onData(final SocketIOClient client, final Session session, final AckRequest ackSender) { final User u = userService.getUser2SocketId(client.getSessionId()); if (null == u) { - LOGGER.info("Client {} requested to join session but is not mapped to a user", client.getSessionId()); + logger.info("Client {} requested to join session but is not mapped to a user", client.getSessionId()); return; } @@ -193,7 +193,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { try { questionService.readInterposedQuestionInternal(question.getId(), user); } catch (NotFoundException | UnauthorizedException e) { - LOGGER.error("Loading of question {} failed for user {} with exception {}", question.getId(), user, e.getMessage()); + logger.error("Loading of question {} failed for user {} with exception {}", question.getId(), user, e.getMessage()); } } }); @@ -205,7 +205,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { try { questionService.readFreetextAnswer(answerId, user); } catch (NotFoundException | UnauthorizedException e) { - LOGGER.error("Marking answer {} as read failed for user {} with exception {}", answerId, user, e.getMessage()); + logger.error("Marking answer {} as read failed for user {} with exception {}", answerId, user, e.getMessage()); } } }); @@ -230,7 +230,9 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { server.addConnectListener(new ConnectListener() { @Override @Timed - public void onConnect(final SocketIOClient client) { } + public void onConnect(final SocketIOClient client) { + /* No implementation - only used for monitoring */ + } }); server.addDisconnectListener(new DisconnectListener() { @@ -259,14 +261,14 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { } public void stopServer() { - LOGGER.trace("In stopServer method of class: {}", getClass().getName()); + logger.trace("In stopServer method of class: {}", getClass().getName()); try { for (final SocketIOClient client : server.getAllClients()) { client.disconnect(); } } catch (final Exception e) { /* If exceptions are not caught they could prevent the Socket.IO server from shutting down. */ - LOGGER.error("Exception caught on Socket.IO shutdown: {}", e.getMessage()); + logger.error("Exception caught on Socket.IO shutdown: {}", e.getMessage()); } server.stop(); @@ -435,7 +437,7 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { } /* TODO role handling implementation, send this only to users with role audience */ - if (qs.size() > 0) { + if (!qs.isEmpty()) { broadcastInSession(session.getKeyword(), "lecQuestionAvail", questions.get(0).get_id()); // deprecated! } broadcastInSession(session.getKeyword(), "lecturerQuestionAvailable", questions); @@ -510,9 +512,9 @@ public class ARSnovaSocketIOServer implements ARSnovaSocket, NovaEventVisitor { // Update the unanswered count for the question variant that was answered. final de.thm.arsnova.entities.Question question = event.getQuestion(); - if (question.getQuestionVariant().equals("lecture")) { + if ("lecture".equals(question.getQuestionVariant())) { sendToUser(event.getUser(), "unansweredLecturerQuestions", questionService.getUnAnsweredLectureQuestionIds(sessionKey, event.getUser())); - } else if (question.getQuestionVariant().equals("preparation")) { + } else if ("preparation".equals(question.getQuestionVariant())) { sendToUser(event.getUser(), "unansweredPreparationQuestions", questionService.getUnAnsweredPreparationQuestionIds(sessionKey, event.getUser())); } } diff --git a/src/main/java/de/thm/arsnova/web/CorsFilter.java b/src/main/java/de/thm/arsnova/web/CorsFilter.java index 2671450980e76a06f7df8fcf2decc3723bbd264c..9742993d1951472522d710f4335f53b1747d958a 100644 --- a/src/main/java/de/thm/arsnova/web/CorsFilter.java +++ b/src/main/java/de/thm/arsnova/web/CorsFilter.java @@ -25,7 +25,7 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import java.util.List; public class CorsFilter extends org.springframework.web.filter.CorsFilter { - protected final Logger logger = LoggerFactory.getLogger(CorsFilter.class); + private final Logger logger = LoggerFactory.getLogger(CorsFilter.class); public CorsFilter(List<String> origins) { super(configurationSource(origins));