Search in sources :

Example 1 with UserFollowsDoc

use of com.pratilipi.data.type.UserFollowsDoc in project pratilipi by Pratilipi.

the class UserDocUtil method updateUserFollows.

public static void updateUserFollows(Long userId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    List<UserAuthorDoc> followingAuthorList = new ArrayList<>();
    List<UserAuthorDoc> unfollowedAuthorList = new ArrayList<>();
    List<UserAuthorDoc> ignoredAuthorList = new ArrayList<>();
    DataListIterator<UserAuthor> userAuthorListIterator = dataAccessor.getUserAuthorListIterator(userId, null, null, null, null);
    while (userAuthorListIterator.hasNext()) {
        UserAuthor userAuthor = userAuthorListIterator.next();
        UserAuthorDoc userAuthorDoc = docAccessor.newUserAuthorDoc();
        userAuthorDoc.setAuthorId(userAuthor.getAuthorId());
        userAuthorDoc.setFollowDate(userAuthor.getFollowDate());
        switch(userAuthor.getFollowState()) {
            case FOLLOWING:
                followingAuthorList.add(userAuthorDoc);
                break;
            case UNFOLLOWED:
                unfollowedAuthorList.add(userAuthorDoc);
                break;
            case IGNORED:
                ignoredAuthorList.add(userAuthorDoc);
                break;
        }
    }
    UserFollowsDoc userFollowingDoc = docAccessor.newUserFollowsDoc();
    userFollowingDoc.setFollows(UserFollowState.FOLLOWING, followingAuthorList);
    userFollowingDoc.setFollows(UserFollowState.UNFOLLOWED, unfollowedAuthorList);
    userFollowingDoc.setFollows(UserFollowState.IGNORED, ignoredAuthorList);
    docAccessor.save(userId, userFollowingDoc);
}
Also used : UserAuthorDoc(com.pratilipi.data.type.UserAuthorDoc) DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) ArrayList(java.util.ArrayList) UserAuthor(com.pratilipi.data.type.UserAuthor) UserFollowsDoc(com.pratilipi.data.type.UserFollowsDoc)

Example 2 with UserFollowsDoc

use of com.pratilipi.data.type.UserFollowsDoc in project pratilipi by Pratilipi.

the class UserDataUtil method updateUserAuthorStats.

public static void updateUserAuthorStats(Long userId) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    User user = dataAccessor.getUser(userId);
    UserFollowsDoc followsDoc = docAccessor.getUserFollowsDoc(userId);
    if (user.getFollowCount().equals(followsDoc.getFollows(UserFollowState.FOLLOWING).size()))
        return;
    AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_UPDATE, user);
    user.setFollowCount((long) followsDoc.getFollows(UserFollowState.FOLLOWING).size());
    user = dataAccessor.createOrUpdateUser(user, auditLog);
}
Also used : User(com.pratilipi.data.type.User) DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) UserFollowsDoc(com.pratilipi.data.type.UserFollowsDoc) AuditLog(com.pratilipi.data.type.AuditLog)

Aggregations

DataAccessor (com.pratilipi.data.DataAccessor)2 DocAccessor (com.pratilipi.data.DocAccessor)2 UserFollowsDoc (com.pratilipi.data.type.UserFollowsDoc)2 AuditLog (com.pratilipi.data.type.AuditLog)1 User (com.pratilipi.data.type.User)1 UserAuthor (com.pratilipi.data.type.UserAuthor)1 UserAuthorDoc (com.pratilipi.data.type.UserAuthorDoc)1 ArrayList (java.util.ArrayList)1