use of com.pratilipi.data.type.UserAuthorDoc in project pratilipi by Pratilipi.
the class AuthorDataUtil method getRecommendedAuthorList.
public static DataListCursorTuple<AuthorData> getRecommendedAuthorList(Long userId, Language language, String cursorStr, Integer resultCount) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
UserFollowsDoc followsDoc = docAccessor.getUserFollowsDoc(userId);
// Authors to ignore = Authors Following + Authors Ignored
List<Long> authorIdsToIgnore = new ArrayList<Long>();
if (followsDoc != null) {
for (UserAuthorDoc userAuthorDoc : followsDoc.getFollows(UserFollowState.FOLLOWING)) authorIdsToIgnore.add(userAuthorDoc.getAuthorId());
for (UserAuthorDoc userAuthorDoc : followsDoc.getFollows(UserFollowState.IGNORED)) if (new Date().getTime() - userAuthorDoc.getFollowDate().getTime() >= TimeUnit.DAYS.toMillis(30))
authorIdsToIgnore.add(userAuthorDoc.getAuthorId());
}
// Get global list of recommended authors
List<Long> recommendedList = _getRecommendAuthorGlobalList(language);
// If cursor is passed, drop all items up till cursor
Long cursor = cursorStr == null ? null : Long.parseLong(cursorStr);
if (cursor != null && recommendedList.contains(cursor))
while (!recommendedList.remove(0).equals(cursor)) continue;
// Remove Author ids to be ignored
recommendedList.removeAll(authorIdsToIgnore);
// Drop items if recommendedList size is requested count
if (resultCount != null)
recommendedList = recommendedList.subList(0, Math.min(resultCount, recommendedList.size()));
Map<Long, Author> authors = dataAccessor.getAuthors(recommendedList);
Map<Long, Page> authorPages = dataAccessor.getPages(PageType.AUTHOR, recommendedList);
List<AuthorData> recommendAuthorData = new ArrayList<>(recommendedList.size());
for (Long authorId : recommendedList) recommendAuthorData.add(createAuthorData(authors.get(authorId), authorPages.get(authorId)));
Collections.shuffle(recommendAuthorData);
return new DataListCursorTuple<AuthorData>(recommendAuthorData, recommendedList.isEmpty() ? null : recommendedList.get(recommendedList.size() - 1).toString());
}
use of com.pratilipi.data.type.UserAuthorDoc in project pratilipi by Pratilipi.
the class UserFollowsDocImpl method setFollows.
@Override
public void setFollows(UserFollowState state, List<UserAuthorDoc> userFollows) {
if (state == null || userFollows == null || userFollows.size() == 0) {
if (this.follows != null)
this.follows.remove(state);
return;
}
List<UserAuthorDocImpl> userFollowList = new ArrayList<>(userFollows.size());
for (UserAuthorDoc follow : userFollows) userFollowList.add((UserAuthorDocImpl) follow);
if (this.follows == null)
this.follows = new HashMap<>();
this.follows.put(state, userFollowList);
}
use of com.pratilipi.data.type.UserAuthorDoc 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);
}
Aggregations