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