use of com.pratilipi.data.client.AuthorData in project pratilipi by Pratilipi.
the class AuthorApi method get.
@Get
public Response get(GetRequest request) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Author author = dataAccessor.getAuthor(request.authorId);
UserAuthor userAuthor = dataAccessor.getUserAuthor(AccessTokenFilter.getAccessToken().getUserId(), request.authorId);
AuthorData authorData = AuthorDataUtil.createAuthorData(author, null, null);
Response response = new Response(authorData);
response.setFollowing(userAuthor != null && userAuthor.getFollowState() == UserFollowState.FOLLOWING);
return response;
}
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 AuthorApi method post.
@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
Gson gson = new Gson();
AuthorData authorData = gson.fromJson(gson.toJson(request), AuthorData.class);
if (// New authors (added by AEEs) are ACTIVE by default
request.getId() == null)
authorData.setState(AuthorState.ACTIVE);
authorData = AuthorDataUtil.saveAuthorData(authorData);
return new Response(authorData);
}
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() != null && 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 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);
// List<AuthorData> authorDataList = AuthorDataUtil.createAuthorDataListEcs( authorIdList );
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;
}
Aggregations