use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.
the class UserDataUtil method createUserData.
public static UserData createUserData(User user, Author author) {
if (user == null)
return null;
UserData userData = new UserData(user.getId());
userData.setFacebookId(user.getFacebookId());
userData.setPassword(user.getPassword() != null);
userData.setEmail(user.getEmail());
userData.setPhone(user.getPhone());
userData.setLanguage(user.getLanguage());
userData.setState(user.getState());
userData.setSignUpDate(user.getSignUpDate());
userData.setFollowCount(user.getFollowCount());
userData.setFirebaseToken(FirebaseApi.getCustomTokenForUser(userData.getId()));
if (author != null) {
AuthorData authorData = AuthorDataUtil.createAuthorData(author);
userData.setAuthor(authorData);
if (userData.getLanguage() == null)
userData.setLanguage(author.getLanguage());
userData.setFirstName(authorData.getFirstName() != null ? authorData.getFirstName() : authorData.getFirstNameEn());
userData.setLastName(authorData.getLastName() != null ? authorData.getLastName() : authorData.getLastNameEn());
userData.setDisplayName(userData.getFirstName() != null ? userData.getFirstName() : userData.getLastName());
userData.setGender(authorData.getGender());
userData.setDateOfBirth(authorData.getDateOfBirth());
userData.setProfilePageUrl(authorData.getPageUrl());
userData.setProfileImageUrl(authorData.getImageUrl());
}
return userData;
}
use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.
the class PratilipiDataUtil method createPratilipiDataList.
public static List<PratilipiData> createPratilipiDataList(List<Long> pratilipiIdList, boolean includeAuthorData, boolean includeMetaData) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Pratilipi> pratilipiList = dataAccessor.getPratilipiList(pratilipiIdList);
Map<Long, Page> pratilipiPages = dataAccessor.getPages(PageType.PRATILIPI, pratilipiIdList);
Map<Long, AuthorData> authorIdToDataMap = null;
if (includeAuthorData) {
List<Long> authorIdList = new LinkedList<>();
for (Pratilipi pratilipi : pratilipiList) if (pratilipi.getAuthorId() != null && !authorIdList.contains(pratilipi.getAuthorId()))
authorIdList.add(pratilipi.getAuthorId());
List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataList(authorIdList, false);
authorIdToDataMap = new HashMap<>(authorDataList.size());
for (AuthorData authorData : authorDataList) authorIdToDataMap.put(authorData.getId(), authorData);
}
List<PratilipiData> pratilipiDataList = new ArrayList<>(pratilipiList.size());
for (Pratilipi pratilipi : pratilipiList) {
PratilipiData pratilipiData = createPratilipiData(pratilipi, pratilipiPages.get(pratilipi.getId()), null, includeMetaData);
if (includeAuthorData && pratilipi.getAuthorId() != null)
pratilipiData.setAuthor(authorIdToDataMap.get(pratilipi.getAuthorId()));
pratilipiData.setRelevance(calculateRelevance(pratilipi, dataAccessor.getAuthor(pratilipi.getAuthorId())));
pratilipiDataList.add(pratilipiData);
}
// Fetching UserPratilipi list from DataStore
List<UserPratilipi> userPratilipiList = dataAccessor.getUserPratilipiList(AccessTokenFilter.getAccessToken().getUserId(), pratilipiIdList);
// Setting isAddedToLib flag for for each PratilipiData in the list
for (int i = 0; i < userPratilipiList.size(); i++) {
UserPratilipi userPratilipi = userPratilipiList.get(i);
pratilipiDataList.get(i).setAddedToLib(userPratilipi != null && userPratilipi.isAddedToLib());
}
return pratilipiDataList;
}
use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.
the class UserAuthorDataUtil method getUserFollowList.
public static DataListCursorTuple<AuthorData> getUserFollowList(Long userId, String cursor, Integer offset, Integer resultCount) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUser(userId);
if (user.getFollowCount() == 0L)
return new DataListCursorTuple<>(new ArrayList<AuthorData>(0), null, 0L);
DataListCursorTuple<Long> authorIdListCursorTuple = dataAccessor.getUserAuthorFollowList(userId, null, cursor, offset, resultCount);
List<Long> authorIdList = authorIdListCursorTuple.getDataList();
List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataList(authorIdList, true);
// Setting AuthorData.isFollowing flag
if (userId.equals(AccessTokenFilter.getAccessToken().getUserId())) {
for (AuthorData authorData : authorDataList) authorData.setFollowing(true);
} else {
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)
authorDataList.get(i).setFollowing(true);
}
// Setting UserData.isFollowing flag
Author author = dataAccessor.getAuthorByUserId(AccessTokenFilter.getAccessToken().getUserId());
if (author != null) {
List<Long> userIdList = new ArrayList<>(authorDataList.size());
List<UserData> userDataList = new ArrayList<>(authorDataList.size());
for (AuthorData authorData : authorDataList) {
if (authorData.getUser().getId() != null) {
userIdList.add(authorData.getUser().getId());
userDataList.add(authorData.getUser());
}
}
List<UserAuthor> userAuthorList = dataAccessor.getUserAuthorList(userIdList, author.getId());
if (userAuthorList != null) {
for (UserAuthor userAuthor : userAuthorList) if (userAuthor != null && userAuthor.getFollowState() == UserFollowState.FOLLOWING)
userDataList.get(userIdList.indexOf(userAuthor.getUserId())).setFollowing(true);
}
}
return new DataListCursorTuple<>(authorDataList, authorIdListCursorTuple.getCursor(), user.getFollowCount());
}
use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.
the class UserDataUtil method getCurrentUser.
public static UserData getCurrentUser() {
AccessToken accessToken = AccessTokenFilter.getAccessToken();
Long userId = accessToken.getUserId();
if (userId.equals(0L) || accessToken.isExpired()) {
UserData userData = new UserData(0L);
userData.setAuthor(new AuthorData());
userData.setFirstName("Guest");
userData.setLastName("User");
userData.setState(UserState.GUEST);
return userData;
} else {
return createUserData(DataAccessorFactory.getDataAccessor().getUser(accessToken.getUserId()));
}
}
use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.
the class AuthorListApi method get.
@Get
public Response get(GetRequest request) throws InsufficientAccessException {
AuthorFilter authorFilter = new AuthorFilter();
authorFilter.setLanguage(request.getLanguage());
authorFilter.setOrderByContentPublished(request.getOrderByContentPublished());
DataListCursorTuple<AuthorData> authorListCursorTuple = AuthorDataUtil.getAuthorDataList(request.getSearchQuery(), authorFilter, request.getCursor(), request.getResultCount() == null ? 20 : request.getResultCount());
return new Response(authorListCursorTuple.getDataList(), authorListCursorTuple.getCursor());
}
Aggregations