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);
}
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);
}
Aggregations