Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
ARSnova Backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Paul-Christian Volkmer
ARSnova Backend
Commits
c2b9e028
Commit
c2b9e028
authored
Aug 07, 2017
by
Daniel Gerhardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make services implement EntityService and use constructor DI
parent
aced7782
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
116 additions
and
56 deletions
+116
-56
CommentServiceImpl.java
...main/java/de/thm/arsnova/services/CommentServiceImpl.java
+14
-5
ContentServiceImpl.java
...main/java/de/thm/arsnova/services/ContentServiceImpl.java
+18
-7
MotdServiceImpl.java
src/main/java/de/thm/arsnova/services/MotdServiceImpl.java
+16
-6
SessionServiceImpl.java
...main/java/de/thm/arsnova/services/SessionServiceImpl.java
+46
-30
StatisticsServiceImpl.java
...n/java/de/thm/arsnova/services/StatisticsServiceImpl.java
+7
-3
UserServiceImpl.java
src/main/java/de/thm/arsnova/services/UserServiceImpl.java
+5
-3
TestAppConfig.java
src/test/java/de/thm/arsnova/config/TestAppConfig.java
+4
-2
StubUserService.java
src/test/java/de/thm/arsnova/services/StubUserService.java
+6
-0
No files found.
src/main/java/de/thm/arsnova/services/CommentServiceImpl.java
View file @
c2b9e028
...
...
@@ -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
)
{
...
...
src/main/java/de/thm/arsnova/services/ContentServiceImpl.java
View file @
c2b9e028
...
...
@@ -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
)
{
...
...
src/main/java/de/thm/arsnova/services/MotdServiceImpl.java
View file @
c2b9e028
...
...
@@ -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
)
{
...
...
src/main/java/de/thm/arsnova/services/SessionServiceImpl.java
View file @
c2b9e028
...
...
@@ -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
()
{
...
...
src/main/java/de/thm/arsnova/services/StatisticsServiceImpl.java
View file @
c2b9e028
...
...
@@ -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
)
...
...
src/main/java/de/thm/arsnova/services/UserServiceImpl.java
View file @
c2b9e028
...
...
@@ -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
())
{
...
...
src/test/java/de/thm/arsnova/config/TestAppConfig.java
View file @
c2b9e028
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
);
}
}
src/test/java/de/thm/arsnova/services/StubUserService.java
View file @
c2b9e028
...
...
@@ -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"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment