Search in sources :

Example 1 with UserAuthorDoc

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());
}
Also used : UserAuthorDoc(com.pratilipi.data.type.UserAuthorDoc) DataAccessor(com.pratilipi.data.DataAccessor) DocAccessor(com.pratilipi.data.DocAccessor) ArrayList(java.util.ArrayList) Page(com.pratilipi.data.type.Page) Date(java.util.Date) DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) AuthorData(com.pratilipi.data.client.AuthorData) Author(com.pratilipi.data.type.Author) UserFollowsDoc(com.pratilipi.data.type.UserFollowsDoc)

Example 2 with UserAuthorDoc

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);
}
Also used : UserAuthorDoc(com.pratilipi.data.type.UserAuthorDoc) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 3 with UserAuthorDoc

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

Aggregations

UserAuthorDoc (com.pratilipi.data.type.UserAuthorDoc)3 ArrayList (java.util.ArrayList)3 DataAccessor (com.pratilipi.data.DataAccessor)2 DocAccessor (com.pratilipi.data.DocAccessor)2 UserFollowsDoc (com.pratilipi.data.type.UserFollowsDoc)2 DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)1 AuthorData (com.pratilipi.data.client.AuthorData)1 Author (com.pratilipi.data.type.Author)1 Page (com.pratilipi.data.type.Page)1 UserAuthor (com.pratilipi.data.type.UserAuthor)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1