Search in sources :

Example 16 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class AuthenticationInterceptor method preHandle.

@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception {
    final Long currentUserId = authenticationService.getCurrentUserId();
    if (currentUserId != null) {
        final Principal principal = principalService.get(currentUserId);
        SessionManager.setPrincipal(principal);
    }
    return super.preHandle(request, response, handler);
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal)

Example 17 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class NotifyUnfollowFeatureStrategy method completeCron.

@Override
public void completeCron(final Long userId) throws WTFDYUMException {
    final Principal principal = principalService.get(userId);
    final Set<Long> followers = twitterService.getFollowers(userId, Optional.ofNullable(principal));
    followersService.saveFollowers(userId, followers);
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal)

Example 18 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class TweetUnfollowFeatureStrategy method completeCron.

@Override
public void completeCron(final Long userId) throws WTFDYUMException {
    final Principal principal = principalService.get(userId);
    final Set<Long> followers = twitterService.getFollowers(userId, Optional.ofNullable(principal));
    followersService.saveFollowers(userId, followers);
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal)

Example 19 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class TweetUnfollowFeatureStrategy method cron.

@Override
public Set<Event> cron(final Long userId) throws WTFDYUMException {
    final Set<Event> result = new HashSet<>();
    final Principal principal = principalService.get(userId);
    final Set<Long> followers = twitterService.getFollowers(userId, Optional.ofNullable(principal));
    final Set<Long> unfollowersId = followersService.getUnfollowers(userId, followers);
    final List<User> unfollowers = twitterService.getUsers(principal, Longs.toArray(unfollowersId));
    for (final User unfollower : unfollowers) {
        result.add(new Event(EventType.UNFOLLOW, unfollower.getScreenName()));
        twitterService.tweet(principal, String.format(unfollowTweetText, unfollower.getScreenName()));
    }
    return result;
}
Also used : User(com.jeanchampemont.wtfdyum.dto.User) Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) HashSet(java.util.HashSet)

Example 20 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class AuthenticationServiceTest method authenticateTest.

@Test
public void authenticateTest() {
    sut.authenticate(new Principal(120L, "tok", "secret"));
    verify(session, times(1)).setAttribute(anyString(), eq(120L));
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Aggregations

Principal (com.jeanchampemont.wtfdyum.dto.Principal)37 Test (org.junit.Test)27 ResponseListMockForTest (com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest)15 Event (com.jeanchampemont.wtfdyum.dto.Event)9 User (com.jeanchampemont.wtfdyum.dto.User)5 Random (java.util.Random)4 AccessToken (twitter4j.auth.AccessToken)4 WTFDYUMException (com.jeanchampemont.wtfdyum.utils.WTFDYUMException)3 HashSet (java.util.HashSet)2 RequestToken (twitter4j.auth.RequestToken)2 HttpSession (javax.servlet.http.HttpSession)1 Bean (org.springframework.context.annotation.Bean)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 StopWatch (org.springframework.util.StopWatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1