use of com.pratilipi.data.client.UserData 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.client.UserData in project pratilipi by Pratilipi.
the class GoogleApi method getUserData.
public static UserData getUserData(String googleIdToken) throws InvalidArgumentException, UnexpectedServerException {
try {
GoogleIdToken idToken = UxModeFilter.isAndroidApp() ? getAndroidIdTokenVerifier().verify(googleIdToken) : getWebIdTokenVerifier().verify(googleIdToken);
String authorisedParty = UxModeFilter.isAndroidApp() ? getAppClientId() : getWebClientId();
if (idToken == null || idToken.getPayload() == null || !idToken.getPayload().getAuthorizedParty().equals(authorisedParty)) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("googleIdToken", "Invalid GoogleIdToken !");
throw new InvalidArgumentException(jsonObject);
}
Payload payload = idToken.getPayload();
logger.log(Level.INFO, "GoogleApi Payload : " + new Gson().toJson(payload));
if (payload.get("given_name") == null || ((String) payload.get("given_name")).isEmpty()) {
logger.log(Level.SEVERE, "Google given_name is missing for GoogleUser: " + payload.getSubject());
throw new UnexpectedServerException();
}
UserData userData = new UserData();
userData.setGoogleId(payload.getSubject());
userData.setFirstName((String) payload.get("given_name"));
userData.setLastName((String) payload.get("family_name"));
userData.setEmail(payload.getEmail());
return userData;
} catch (GeneralSecurityException | IOException e) {
logger.log(Level.SEVERE, "Google id token verification failed: " + e);
throw new UnexpectedServerException();
}
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class FacebookApi method getUserData.
public static UserData getUserData(String fbUserAccessToken) throws InvalidArgumentException, UnexpectedServerException {
Map<String, String> paramsMap = new HashMap<String, String>();
paramsMap.put("access_token", fbUserAccessToken);
paramsMap.put("fields", "id,first_name,last_name,gender,birthday,email");
String responsePayload = HttpUtil.doGet(GRAPH_API_2p6_URL + "/me", paramsMap);
JsonObject responseJson = new Gson().fromJson(responsePayload, JsonElement.class).getAsJsonObject();
if (responseJson.get("error") != null) {
logger.log(Level.SEVERE, "Error response from Graph Api.");
// Facebook returns code 190 if access-token is expired
if (responseJson.get("error").getAsJsonObject().get("code").getAsInt() == 190)
throw new InvalidArgumentException("Facebook AccessToken is expired.");
else
throw new UnexpectedServerException();
} else {
if (responseJson.get("first_name") == null || responseJson.get("first_name").getAsString().isEmpty()) {
logger.log(Level.INFO, "HTTP Response : " + responseJson);
logger.log(Level.SEVERE, "Facebook first_name is missing for FacebookUser: " + responseJson.get("id").getAsString());
throw new UnexpectedServerException();
}
UserData userData = new UserData();
userData.setFacebookId(responseJson.get("id").getAsString());
userData.setFirstName(responseJson.get("first_name").getAsString());
userData.setLastName(responseJson.get("last_name").getAsString());
if (responseJson.get("gender") != null)
userData.setGender(Gender.valueOf(responseJson.get("gender").getAsString().toUpperCase()));
if (responseJson.get("birthday") != null) {
String dob = responseJson.get("birthday").getAsString();
String year = dob.substring(6);
String month = dob.substring(0, 2);
String date = dob.substring(3, 5);
userData.setDateOfBirth(year + "-" + month + "-" + date);
}
if (responseJson.get("email") != null)
userData.setEmail(responseJson.get("email").getAsString());
return userData;
}
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class BlogPostDataUtil method createBlogPostData.
public static BlogPostData createBlogPostData(BlogPost blogPost, Page blogPostPage) {
BlogPostData blogPostData = new BlogPostData(blogPost.getId());
blogPostData.setBlogId(blogPost.getBlogId());
blogPostData.setTitle(blogPost.getTitle());
blogPostData.setTitleEn(blogPost.getTitleEn());
blogPostData.setContent(blogPost.getContent());
blogPostData.setLanguage(blogPost.getLanguage());
blogPostData.setState(blogPost.getState());
User user = DataAccessorFactory.getDataAccessor().getUser(blogPost.getCreatedBy());
if (user != null) {
UserData userData = UserDataUtil.createUserData(user);
blogPostData.setCreatedBy(userData);
}
blogPostData.setCreationDate(blogPost.getCreationDate());
blogPostData.setLastUpdated(blogPost.getLastUpdated());
blogPostData.setPageUrl(blogPostPage.getUriAlias() == null ? blogPostPage.getUri() : blogPostPage.getUriAlias());
blogPostData.setAccessToUpdate(hasAccessToUpdateBlogPostData(blogPost, null));
return blogPostData;
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class EmailDataUtil method _createDataModelForVoteReviewEmail.
private static Object[] _createDataModelForVoteReviewEmail(String voteId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Vote vote = dataAccessor.getVote(voteId);
UserPratilipiData userPratilipi = UserPratilipiDataUtil.createUserPratilipiData(dataAccessor.getUserPratilipi(vote.getParentId()));
PratilipiData pratilipi = PratilipiDataUtil.createPratilipiData(dataAccessor.getPratilipi(userPratilipi.getPratilipiId()));
UserData voter = UserDataUtil.createUserData(dataAccessor.getUser(vote.getUserId()));
Map<String, Object> dataModel = new HashMap<>();
dataModel.put("pratilipi_title", pratilipi.getTitle() != null ? pratilipi.getTitle() : pratilipi.getTitleEn());
dataModel.put("pratilipi_page_url", _getDomainName(pratilipi.getLanguage()) + pratilipi.getPageUrl());
dataModel.put("reviewer_page_url", _getDomainName(userPratilipi.getUser().getLanguage()) + userPratilipi.getUser().getProfilePageUrl());
dataModel.put("reviewer_image_url", userPratilipi.getUser().getAuthor().getProfileImageUrl(64));
dataModel.put("reviewer_name", userPratilipi.getUser().getAuthor().getName() != null ? userPratilipi.getUser().getAuthor().getName() : userPratilipi.getUser().getAuthor().getNameEn());
dataModel.put("review_creation_date", _getDateFormat(userPratilipi.getReviewDate()));
dataModel.put("review_review", HtmlUtil.toPlainText(userPratilipi.getReview()));
if (userPratilipi.getRating() != null)
dataModel.put("rating", userPratilipi.getRating());
dataModel.put("voter_name", voter.getAuthor().getName() != null ? voter.getAuthor().getName() : voter.getAuthor().getNameEn());
return new Object[] { dataModel, pratilipi.getLanguage() };
}
Aggregations