Search in sources :

Example 6 with DataListCursorTuple

use of com.pratilipi.data.DataListCursorTuple in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method getPratilipiReviewList.

public static DataListCursorTuple<UserPratilipiData> getPratilipiReviewList(Long pratilipiId, String cursor, Integer offset, Integer resultCount) throws UnexpectedServerException {
    DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
    PratilipiReviewsDoc reviewsDoc = docAccessor.getPratilipiReviewsDoc(pratilipiId);
    List<UserPratilipiDoc> reviewDocList = reviewsDoc.getReviews();
    // Reverse Sort
    Collections.reverse(reviewDocList);
    // Using next UserPratilipiId as the cursor
    int fromIndex = 0;
    if (cursor != null && !cursor.equals("-1")) {
        for (int i = 0; i < reviewDocList.size(); i++) {
            if (reviewDocList.get(i).getId().equals(cursor)) {
                fromIndex = i;
                break;
            }
        }
        if (offset != null)
            fromIndex = fromIndex + offset;
    }
    if (fromIndex >= reviewDocList.size() || (cursor != null && cursor.equals("-1"))) {
        return new DataListCursorTuple<UserPratilipiData>(new ArrayList<UserPratilipiData>(), "-1", (long) (int) reviewsDoc.getReviews().size());
    }
    int toIndex = resultCount == null ? reviewDocList.size() : Math.min(fromIndex + resultCount, reviewDocList.size());
    // Next cursor
    cursor = toIndex == reviewDocList.size() ? "-1" : reviewDocList.get(toIndex).getId();
    reviewDocList = reviewDocList.subList(fromIndex, toIndex);
    List<UserPratilipiData> userPratilipiDataList = new ArrayList<>(reviewDocList.size());
    for (UserPratilipiDoc review : reviewDocList) userPratilipiDataList.add(createUserPratilipiData(review));
    return new DataListCursorTuple<UserPratilipiData>(userPratilipiDataList, cursor, (long) (int) reviewsDoc.getReviews().size());
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) DocAccessor(com.pratilipi.data.DocAccessor) UserPratilipiDoc(com.pratilipi.data.type.UserPratilipiDoc) ArrayList(java.util.ArrayList) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) PratilipiReviewsDoc(com.pratilipi.data.type.PratilipiReviewsDoc)

Example 7 with DataListCursorTuple

use of com.pratilipi.data.DataListCursorTuple in project pratilipi by Pratilipi.

the class UserPratilipiDataUtil method getUserLibrary.

public static DataListCursorTuple<PratilipiData> getUserLibrary(Long userId, String cursor, Integer offset, Integer resultCount) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    DataListCursorTuple<Long> pratilipiIdListCursorTuple = dataAccessor.getUserLibrary(userId, cursor, offset, resultCount);
    return new DataListCursorTuple<PratilipiData>(PratilipiDataUtil.createPratilipiDataList(pratilipiIdListCursorTuple.getDataList(), true), pratilipiIdListCursorTuple.getCursor());
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) DataAccessor(com.pratilipi.data.DataAccessor)

Example 8 with DataListCursorTuple

use of com.pratilipi.data.DataListCursorTuple in project pratilipi by Pratilipi.

the class UserAuthorDataUtil method getAuthorFollowList.

public static DataListCursorTuple<UserData> getAuthorFollowList(Long authorId, String cursor, Integer offset, Integer resultCount) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = dataAccessor.getAuthor(authorId);
    if (author.getFollowCount() == 0L)
        return new DataListCursorTuple<>(new ArrayList<UserData>(0), null, 0L);
    DataListCursorTuple<Long> userIdListCursorTuple = dataAccessor.getUserAuthorFollowList(null, authorId, cursor, offset, resultCount);
    List<Long> userIdList = userIdListCursorTuple.getDataList();
    Map<Long, UserData> users = UserDataUtil.createUserDataList(userIdList, true);
    List<UserData> userDataList = new ArrayList<>(userIdList.size());
    for (Long userId : userIdList) userDataList.add(users.get(userId));
    // Setting UserData.isFollowing flag
    if (AccessTokenFilter.getAccessToken().getUserId().equals(author.getUserId())) {
        for (UserData userData : userDataList) userData.setFollowing(true);
    } else {
        Author authorProfile = dataAccessor.getAuthorByUserId(AccessTokenFilter.getAccessToken().getUserId());
        if (authorProfile != null) {
            List<UserAuthor> userAuthorList = dataAccessor.getUserAuthorList(userIdList, authorProfile.getId());
            for (int i = 0; i < userIdList.size(); i++) if (userAuthorList.get(i) != null && userAuthorList.get(i).getFollowState() == UserFollowState.FOLLOWING)
                userDataList.get(i).setFollowing(true);
        }
    }
    // Setting AuthorData.isFollowing flag
    List<Long> authorIdList = new ArrayList<>(userDataList.size());
    for (UserData userData : userDataList) authorIdList.add(userData.getAuthor().getId());
    List<UserAuthor> userAuthorList = dataAccessor.getUserAuthorList(AccessTokenFilter.getAccessToken().getUserId(), authorIdList);
    if (userAuthorList.size() != 0)
        for (int i = 0; i < authorIdList.size(); i++) if (userAuthorList.get(i) != null && userAuthorList.get(i).getFollowState() == UserFollowState.FOLLOWING)
            userDataList.get(i).getAuthor().setFollowing(true);
    return new DataListCursorTuple<>(userDataList, userIdListCursorTuple.getCursor(), author.getFollowCount());
}
Also used : UserData(com.pratilipi.data.client.UserData) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) UserAuthor(com.pratilipi.data.type.UserAuthor) Author(com.pratilipi.data.type.Author) UserAuthor(com.pratilipi.data.type.UserAuthor)

Example 9 with DataListCursorTuple

use of com.pratilipi.data.DataListCursorTuple in project pratilipi by Pratilipi.

the class AuthorDataUtil method getAuthorDataList.

public static DataListCursorTuple<AuthorData> getAuthorDataList(String searchQuery, AuthorFilter authorFilter, String cursor, Integer resultCount) throws InsufficientAccessException {
    if (!hasAccessToListAuthorData(authorFilter.getLanguage()))
        throw new InsufficientAccessException();
    // Processing search query
    if (searchQuery != null)
        searchQuery = searchQuery.toLowerCase().trim().replaceAll(",|\\sor\\s", " ").replaceAll("[\\s]+", " OR ");
    DataListCursorTuple<Long> authorIdListCursorTuple = DataAccessorFactory.getSearchAccessor().searchAuthor(searchQuery, authorFilter, cursor, null, resultCount);
    List<AuthorData> authorDataList = createAuthorDataList(authorIdListCursorTuple.getDataList(), true);
    return new DataListCursorTuple<AuthorData>(authorDataList, authorIdListCursorTuple.getCursor());
}
Also used : DataListCursorTuple(com.pratilipi.data.DataListCursorTuple) AuthorData(com.pratilipi.data.client.AuthorData) InsufficientAccessException(com.pratilipi.common.exception.InsufficientAccessException)

Aggregations

DataListCursorTuple (com.pratilipi.data.DataListCursorTuple)9 DataAccessor (com.pratilipi.data.DataAccessor)6 ArrayList (java.util.ArrayList)4 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)3 DocAccessor (com.pratilipi.data.DocAccessor)3 AuthorData (com.pratilipi.data.client.AuthorData)3 Author (com.pratilipi.data.type.Author)3 UserData (com.pratilipi.data.client.UserData)2 PratilipiReviewsDoc (com.pratilipi.data.type.PratilipiReviewsDoc)2 UserAuthor (com.pratilipi.data.type.UserAuthor)2 UserPratilipiDoc (com.pratilipi.data.type.UserPratilipiDoc)2 CommentData (com.pratilipi.data.client.CommentData)1 PratilipiData (com.pratilipi.data.client.PratilipiData)1 UserAuthorData (com.pratilipi.data.client.UserAuthorData)1 UserPratilipiData (com.pratilipi.data.client.UserPratilipiData)1 CommentDoc (com.pratilipi.data.type.CommentDoc)1 Notification (com.pratilipi.data.type.Notification)1 Page (com.pratilipi.data.type.Page)1 User (com.pratilipi.data.type.User)1 UserAuthorDoc (com.pratilipi.data.type.UserAuthorDoc)1