diff --git a/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java b/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java index 2b44caf6df441502fedc47521ad1290a979cf043..0bab2ff2e32f867ea8999e0e18399d143687ad57 100644 --- a/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/CommentServiceImpl.java @@ -11,8 +11,9 @@ import de.thm.arsnova.exceptions.NotFoundException; import de.thm.arsnova.exceptions.UnauthorizedException; import de.thm.arsnova.persistance.CommentRepository; import de.thm.arsnova.persistance.SessionRepository; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationEventPublisher; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; @@ -22,18 +23,26 @@ import java.util.List; * Performs all comment related operations. */ @Service -public class CommentServiceImpl implements CommentService { - @Autowired +public class CommentServiceImpl extends EntityService<Comment> implements CommentService { private UserService userService; - @Autowired private CommentRepository commentRepository; - @Autowired private SessionRepository sessionRepository; private ApplicationEventPublisher publisher; + public CommentServiceImpl( + CommentRepository repository, + SessionRepository sessionRepository, + UserService userService, + @Qualifier("defaultJsonMessageConverter") MappingJackson2HttpMessageConverter jackson2HttpMessageConverter) { + super(Comment.class, repository, jackson2HttpMessageConverter.getObjectMapper()); + this.commentRepository = repository; + this.sessionRepository = sessionRepository; + this.userService = userService; + } + @Override @PreAuthorize("isAuthenticated()") public boolean save(final Comment comment) { diff --git a/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java b/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java index e63bab822ba615f73b07946ee5312681d7fedd03..7ab3d3f23d9c68185315729321f05a5f5bb5f1aa 100644 --- a/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/ContentServiceImpl.java @@ -31,10 +31,11 @@ import de.thm.arsnova.persistance.ContentRepository; import de.thm.arsnova.persistance.SessionRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; @@ -50,20 +51,15 @@ import java.util.TimerTask; * Performs all content and answer related operations. */ @Service -public class ContentServiceImpl implements ContentService, ApplicationEventPublisherAware { - @Autowired +public class ContentServiceImpl extends EntityService<Content> implements ContentService, ApplicationEventPublisherAware { private UserService userService; - @Autowired private SessionRepository sessionRepository; - @Autowired private ContentRepository contentRepository; - @Autowired private AnswerRepository answerRepository; - @Autowired private ImageUtils imageUtils; @Value("${upload.filesize_b}") @@ -75,6 +71,21 @@ public class ContentServiceImpl implements ContentService, ApplicationEventPubli private HashMap<String, Timer> timerList = new HashMap<>(); + public ContentServiceImpl( + ContentRepository repository, + AnswerRepository answerRepository, + SessionRepository sessionRepository, + UserService userService, + ImageUtils imageUtils, + @Qualifier("defaultJsonMessageConverter") MappingJackson2HttpMessageConverter jackson2HttpMessageConverter) { + super(Content.class, repository, jackson2HttpMessageConverter.getObjectMapper()); + this.contentRepository = repository; + this.answerRepository = answerRepository; + this.sessionRepository = sessionRepository; + this.userService = userService; + this.imageUtils = imageUtils; + } + @Override @PreAuthorize("isAuthenticated()") public List<Content> getBySessionKey(final String sessionkey) { diff --git a/src/main/java/de/thm/arsnova/services/MotdServiceImpl.java b/src/main/java/de/thm/arsnova/services/MotdServiceImpl.java index b51a6ccc5d6fb615930c81ee55daa8bcd1a50eca..1400daf561ba19b23ba882ee57584b1de5791859 100644 --- a/src/main/java/de/thm/arsnova/services/MotdServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/MotdServiceImpl.java @@ -24,7 +24,8 @@ import de.thm.arsnova.entities.User; import de.thm.arsnova.exceptions.BadRequestException; import de.thm.arsnova.persistance.MotdListRepository; import de.thm.arsnova.persistance.MotdRepository; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; @@ -37,19 +38,28 @@ import java.util.StringTokenizer; * Performs all question, interposed question, and answer related operations. */ @Service -public class MotdServiceImpl implements MotdService { - @Autowired +public class MotdServiceImpl extends EntityService<Motd> implements MotdService { private UserService userService; - @Autowired private SessionService sessionService; - @Autowired private MotdRepository motdRepository; - @Autowired private MotdListRepository motdListRepository; + public MotdServiceImpl( + MotdRepository repository, + MotdListRepository motdListRepository, + UserService userService, + SessionService sessionService, + @Qualifier("defaultJsonMessageConverter") MappingJackson2HttpMessageConverter jackson2HttpMessageConverter) { + super(Motd.class, repository, jackson2HttpMessageConverter.getObjectMapper()); + this.motdRepository = repository; + this.motdListRepository = motdListRepository; + this.userService = userService; + this.sessionService = sessionService; + } + @Override @PreAuthorize("isAuthenticated()") public Motd getByKey(final String key) { diff --git a/src/main/java/de/thm/arsnova/services/SessionServiceImpl.java b/src/main/java/de/thm/arsnova/services/SessionServiceImpl.java index 8763ffdf8d27395fc96d12badd56710a6d144889..bfc3532d8250e9e0d4515998e627cad6b01be784 100644 --- a/src/main/java/de/thm/arsnova/services/SessionServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/SessionServiceImpl.java @@ -45,9 +45,11 @@ import de.thm.arsnova.persistance.VisitedSessionRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; @@ -61,11 +63,50 @@ import java.util.UUID; * Performs all session related operations. */ @Service -public class SessionServiceImpl implements SessionService, ApplicationEventPublisherAware { +public class SessionServiceImpl extends EntityService<Session> implements SessionService, ApplicationEventPublisherAware { + private static final long SESSION_INACTIVITY_CHECK_INTERVAL_MS = 30 * 60 * 1000L; + + private static final Logger logger = LoggerFactory.getLogger(SessionServiceImpl.class); - @Autowired private SessionRepository sessionRepository; + private VisitedSessionRepository visitedSessionRepository; + + private UserService userService; + + private FeedbackService feedbackService; + + private ScoreCalculatorFactory scoreCalculatorFactory; + + private ConnectorClient connectorClient; + + private ImageUtils imageUtils; + + @Value("${session.guest-session.cleanup-days:0}") + private int guestSessionInactivityThresholdDays; + + @Value("${pp.logofilesize_b}") + private int uploadFileSizeByte; + + private ApplicationEventPublisher publisher; + + public SessionServiceImpl( + SessionRepository repository, + VisitedSessionRepository visitedSessionRepository, + UserService userService, + FeedbackService feedbackService, + ScoreCalculatorFactory scoreCalculatorFactory, + ImageUtils imageUtils, + @Qualifier("defaultJsonMessageConverter") MappingJackson2HttpMessageConverter jackson2HttpMessageConverter) { + super(Session.class, repository, jackson2HttpMessageConverter.getObjectMapper()); + this.sessionRepository = repository; + this.visitedSessionRepository = visitedSessionRepository; + this.userService = userService; + this.feedbackService = feedbackService; + this.scoreCalculatorFactory = scoreCalculatorFactory; + this.imageUtils = imageUtils; + } + public static class SessionNameComparator implements Comparator<Session>, Serializable { private static final long serialVersionUID = 1L; @@ -102,35 +143,10 @@ public class SessionServiceImpl implements SessionService, ApplicationEventPubli } } - private static final long SESSION_INACTIVITY_CHECK_INTERVAL_MS = 30 * 60 * 1000L; - - @Autowired - private VisitedSessionRepository visitedSessionRepository; - - @Autowired - private UserService userService; - - @Autowired - private FeedbackService feedbackService; - - @Autowired - private ScoreCalculatorFactory scoreCalculatorFactory; - @Autowired(required = false) - private ConnectorClient connectorClient; - - @Autowired - private ImageUtils imageUtils; - - @Value("${session.guest-session.cleanup-days:0}") - private int guestSessionInactivityThresholdDays; - - @Value("${pp.logofilesize_b}") - private int uploadFileSizeByte; - - private ApplicationEventPublisher publisher; - - private static final Logger logger = LoggerFactory.getLogger(SessionServiceImpl.class); + public void setConnectorClient(ConnectorClient connectorClient) { + this.connectorClient = connectorClient; + } @Scheduled(fixedDelay = SESSION_INACTIVITY_CHECK_INTERVAL_MS) public void deleteInactiveSessions() { diff --git a/src/main/java/de/thm/arsnova/services/StatisticsServiceImpl.java b/src/main/java/de/thm/arsnova/services/StatisticsServiceImpl.java index 8dda842380ff5141fbc4982958588028bcc40dec..7345ec3b667d66f0450f40d8db61ad6ec0d2993d 100644 --- a/src/main/java/de/thm/arsnova/services/StatisticsServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/StatisticsServiceImpl.java @@ -19,7 +19,6 @@ package de.thm.arsnova.services; import de.thm.arsnova.entities.Statistics; import de.thm.arsnova.persistance.StatisticsRepository; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -29,12 +28,17 @@ import org.springframework.stereotype.Service; */ @Service public class StatisticsServiceImpl implements StatisticsService { - @Autowired private StatisticsRepository statisticsRepository; - @Autowired private UserService userService; + public StatisticsServiceImpl( + StatisticsRepository repository, + UserService userService) { + this.statisticsRepository = repository; + this.userService = userService; + } + private Statistics statistics = new Statistics(); @Scheduled(initialDelay = 0, fixedRate = 10000) diff --git a/src/main/java/de/thm/arsnova/services/UserServiceImpl.java b/src/main/java/de/thm/arsnova/services/UserServiceImpl.java index c6e5d18e741a070921c32b7ad4fde2b9e125e5ed..2adce602e2084a0f5dd9f93d5dddaf60fa3f5300 100644 --- a/src/main/java/de/thm/arsnova/services/UserServiceImpl.java +++ b/src/main/java/de/thm/arsnova/services/UserServiceImpl.java @@ -32,7 +32,6 @@ import org.pac4j.oauth.profile.twitter.TwitterProfile; import org.pac4j.springframework.security.authentication.Pac4jAuthenticationToken; 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.mail.MailException; import org.springframework.mail.javamail.JavaMailSender; @@ -95,10 +94,8 @@ public class UserServiceImpl implements UserService { /* used for Socket.IO online check solution (new) */ private static final ConcurrentHashMap<User, String> user2session = new ConcurrentHashMap<>(); - @Autowired private UserRepository userRepository; - @Autowired private JavaMailSender mailSender; @Value("${root-url}") @@ -151,6 +148,11 @@ public class UserServiceImpl implements UserService { loginBans = Collections.synchronizedSet(new HashSet<String>()); } + public UserServiceImpl(UserRepository repository, JavaMailSender mailSender) { + this.userRepository = repository; + this.mailSender = mailSender; + } + @Scheduled(fixedDelay = LOGIN_TRY_RESET_DELAY_MS) public void resetLoginTries() { if (!loginTries.isEmpty()) { diff --git a/src/test/java/de/thm/arsnova/config/TestAppConfig.java b/src/test/java/de/thm/arsnova/config/TestAppConfig.java index c3517272dc82ac670dab6f4708b561452eba08f4..eea3d564fbee6a679fea09baf9971d1e63e38aa5 100644 --- a/src/test/java/de/thm/arsnova/config/TestAppConfig.java +++ b/src/test/java/de/thm/arsnova/config/TestAppConfig.java @@ -1,5 +1,6 @@ package de.thm.arsnova.config; +import de.thm.arsnova.persistance.UserRepository; import de.thm.arsnova.services.StubUserService; import de.thm.arsnova.websocket.ArsnovaSocketioServer; import de.thm.arsnova.websocket.ArsnovaSocketioServerImpl; @@ -15,6 +16,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.aspectj.EnableSpringConfigured; import org.springframework.context.support.SimpleThreadScope; +import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mock.web.MockServletContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.support.AnnotationConfigContextLoader; @@ -70,7 +72,7 @@ public class TestAppConfig { @Bean @Primary - public StubUserService stubUserService() { - return new StubUserService(); + public StubUserService stubUserService(UserRepository repository, JavaMailSender mailSender) { + return new StubUserService(repository, mailSender); } } diff --git a/src/test/java/de/thm/arsnova/services/StubUserService.java b/src/test/java/de/thm/arsnova/services/StubUserService.java index 6a923b213d6c493a2a8901932b7ca576b419aec1..278f02b36c469b1659dc48436a23e23ad876f7cf 100644 --- a/src/test/java/de/thm/arsnova/services/StubUserService.java +++ b/src/test/java/de/thm/arsnova/services/StubUserService.java @@ -18,12 +18,18 @@ package de.thm.arsnova.services; import de.thm.arsnova.entities.User; +import de.thm.arsnova.persistance.UserRepository; +import org.springframework.mail.javamail.JavaMailSender; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; public class StubUserService extends UserServiceImpl { private User stubUser = null; + public StubUserService(UserRepository repository, JavaMailSender mailSender) { + super(repository, mailSender); + } + public void setUserAuthenticated(boolean isAuthenticated) { this.setUserAuthenticated(isAuthenticated, "ptsr00"); }