Search in sources :

Example 36 with Principal

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

the class CronServiceImpl method checkCredentials.

@Override
@Scheduled(fixedDelayString = "${wtfdyum.credentials-check-delay}", initialDelay = 120000L)
public void checkCredentials() {
    log.debug("Checking credentials...");
    final StopWatch watch = new StopWatch();
    watch.start();
    final Set<Long> members = principalService.getMembers();
    for (final Long userId : members) {
        final Principal principal = principalService.get(userId);
        if (!twitterService.verifyCredentials(principal)) {
            userService.applyLimit(userId, UserLimitType.CREDENTIALS_INVALID);
            userService.addEvent(userId, new Event(EventType.INVALID_TWITTER_CREDENTIALS, ""));
        } else {
            userService.resetLimit(userId, UserLimitType.CREDENTIALS_INVALID);
        }
    }
    watch.stop();
    log.debug("Finished checking credentials in {} ms", watch.getTotalTimeMillis());
}
Also used : Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) StopWatch(org.springframework.util.StopWatch) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 37 with Principal

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

the class NotifyUnfollowFeatureStrategy 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.sendDirectMessage(principal, userId, String.format(unfollowDMText, 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)

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