use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class CommentDataUtil method saveCommentData.
public static CommentData saveCommentData(CommentData commentData) throws InvalidArgumentException, InsufficientAccessException {
_validateCommentDataForSave(commentData);
boolean isNew = commentData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Comment comment = isNew ? dataAccessor.newComment() : dataAccessor.getComment(commentData.getId());
if (isNew && !hasAccessToAddCommentData(commentData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdateCommentData(comment))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.COMMENT_ADD : AccessType.COMMENT_UPDATE, comment);
if (isNew) {
comment.setUserId(commentData.getUserId());
comment.setParentType(commentData.getParentType());
comment.setParentId(commentData.getParentId());
if (commentData.getParentType() == CommentParentType.REVIEW) {
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(commentData.getParentId());
comment.setReferenceType(ReferenceType.PRATILIPI);
comment.setReferenceId(userPratilipi.getPratilipiId());
}
comment.setCreationDate(new Date());
} else {
comment.setLastUpdated(new Date());
}
if (commentData.hasContent())
comment.setContent(commentData.getContent());
if (commentData.hasState())
comment.setState(commentData.getState());
comment = dataAccessor.createOrUpdateComment(comment, auditLog);
User user = dataAccessor.getUser(commentData.getUserId());
UserData userData = UserDataUtil.createUserData(user);
commentData = createCommentData(comment);
commentData.setUser(userData);
return commentData;
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class EmailDataUtil method _createDataModelForUserPratilipiEmail.
private static Object[] _createDataModelForUserPratilipiEmail(String userPratilipiId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserPratilipiData userPratilipi = UserPratilipiDataUtil.createUserPratilipiData(dataAccessor.getUserPratilipi(userPratilipiId));
PratilipiData pratilipi = PratilipiDataUtil.createPratilipiData(dataAccessor.getPratilipi(userPratilipi.getPratilipiId()));
UserData reviewer = UserDataUtil.createUserData(dataAccessor.getUser(userPratilipi.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_name", reviewer.getAuthor().getName() != null ? reviewer.getAuthor().getName() : reviewer.getAuthor().getNameEn());
dataModel.put("reviewer_page_url", _getDomainName(pratilipi.getLanguage()) + reviewer.getProfilePageUrl());
dataModel.put("reviewer_image_url", reviewer.getAuthor().getProfileImageUrl(100));
dataModel.put("review_creation_date", _getDateFormat(userPratilipi.getReviewDate()));
if (userPratilipi.getRating() != null)
dataModel.put("rating", userPratilipi.getRating());
if (userPratilipi.getReview() != null)
dataModel.put("review_review", HtmlUtil.truncateText(userPratilipi.getReview(), 250));
if (userPratilipi.getCommentCount() != null)
dataModel.put("review_comment_count", userPratilipi.getCommentCount().toString());
return new Object[] { dataModel, pratilipi.getLanguage() };
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method createUserPratilipiData.
public static UserPratilipiData createUserPratilipiData(UserPratilipi userPratilipi) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DocAccessor docAccessor = DataAccessorFactory.getDocAccessor();
User user = dataAccessor.getUser(userPratilipi.getUserId());
UserData userData = UserDataUtil.createUserData(user);
PratilipiReviewsDoc reviewsDoc = docAccessor.getPratilipiReviewsDoc(userPratilipi.getPratilipiId());
UserPratilipiData userPratilipiData = new UserPratilipiData();
userPratilipiData.setId(userPratilipi.getId());
userPratilipiData.setUserId(userPratilipi.getUserId());
userPratilipiData.setPratilipiId(userPratilipi.getPratilipiId());
userPratilipiData.setUser(userData);
userPratilipiData.setUserName(userData.getDisplayName());
userPratilipiData.setUserImageUrl(userData.getProfileImageUrl());
userPratilipiData.setUserProfilePageUrl(userData.getProfilePageUrl());
userPratilipiData.setRating(userPratilipi.getRating());
userPratilipiData.setReview(processReview(userPratilipi.getReviewTitle(), userPratilipi.getReview()));
userPratilipiData.setReviewState(userPratilipi.getReviewState());
userPratilipiData.setReviewDate(userPratilipi.getReviewDate());
for (UserPratilipiDoc review : reviewsDoc.getReviews()) {
if (review.getId().equals(userPratilipi.getId())) {
userPratilipiData.setCommentCount(review.getCommentCount());
userPratilipiData.setLikeCount(review.getLikeCount());
userPratilipiData.setLiked(review.getLikedByUserIds().contains(AccessTokenFilter.getAccessToken().getUserId()));
break;
}
}
userPratilipiData.setAddedToLib(userPratilipi.isAddedToLib());
userPratilipiData.setAccessToReview(hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_REVIEW));
return userPratilipiData;
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserPasswordUpdateApi method post.
@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
UserData userData;
if (request.getEmail() != null && request.getVerificationToken() != null) {
// Verifying email
UserDataUtil.verifyUserEmail(request.getEmail(), request.getVerificationToken());
// Updating password
UserDataUtil.updateUserPassword(request.getEmail(), request.getVerificationToken(), request.getNewPassword());
// Logging-in the user
userData = UserDataUtil.loginUser(request.getEmail(), request.getVerificationToken());
} else if (request.getPassword() != null) {
// Updating password
UserDataUtil.updateUserPassword(request.getPassword(), request.getNewPassword());
userData = UserDataUtil.getCurrentUser();
} else {
throw new InvalidArgumentException(GenericRequest.ERR_INSUFFICIENT_ARGS);
}
return new UserV1Api.Response(userData, UserPasswordUpdateApi.class);
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserDataUtil method _loginFederatedUser.
private static UserData _loginFederatedUser(UserData apiUserData, User user, UserSignUpSource signUpSource) throws InsufficientAccessException {
// Do nothing if a user is already logged in
if (!AccessTokenFilter.getAccessToken().getUserId().equals(0L))
return getCurrentUser();
// Note: Users having Facebook or Google Id can never be in GUEST or REFERRAL state.
// Note: No action required for REGISTERED or ACTIVE users.
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
boolean isNew = false;
if (user == null || user.getState() == UserState.DELETED) {
if (apiUserData.getEmail() != null)
user = dataAccessor.getUserByEmail(apiUserData.getEmail());
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), null, null);
if (user == null || user.getState() == UserState.DELETED) {
user = dataAccessor.newUser();
auditLog.setAccessType(AccessType.USER_ADD);
auditLog.setEventDataOld(user);
user.setEmail(apiUserData.getEmail());
// Counting on Facebook / Google for e-mail/user verification
user.setState(UserState.ACTIVE);
user.setSignUpDate(new Date());
user.setSignUpSource(signUpSource);
isNew = true;
} else if (user.getState() == UserState.REFERRAL) {
auditLog.setAccessType(AccessType.USER_ADD);
auditLog.setEventDataOld(user);
// Counting on Facebook / Google for e-mail/user verification
user.setState(UserState.ACTIVE);
user.setSignUpDate(new Date());
user.setSignUpSource(signUpSource);
isNew = true;
} else if (user.getState() == UserState.REGISTERED) {
auditLog.setAccessType(AccessType.USER_UPDATE);
auditLog.setEventDataOld(user);
// Counting on Facebook / google for e-mail/user verification
user.setState(UserState.ACTIVE);
} else {
// user.getState() == UserState.ACTIVE || user.getState() == UserState.BLOCKED
auditLog.setAccessType(AccessType.USER_UPDATE);
auditLog.setEventDataOld(user);
}
if (apiUserData.getFacebookId() != null)
user.setFacebookId(apiUserData.getFacebookId());
if (apiUserData.getGoogleId() != null)
user.setGoogleId(apiUserData.getGoogleId());
user.setLastUpdated(new Date());
user = dataAccessor.createOrUpdateUser(user, auditLog);
}
if (user.getState() == UserState.BLOCKED)
throw new InsufficientAccessException(GenericRequest.ERR_ACCOUNT_BLOCKED);
_loginUser(AccessTokenFilter.getAccessToken(), user);
UserData userData = createUserData(user);
if (isNew) {
userData.setFirstName(apiUserData.getFirstName());
userData.setLastName(apiUserData.getLastName());
userData.setGender(apiUserData.getGender());
userData.setDateOfBirth(apiUserData.getDateOfBirth());
}
return userData;
}
Aggregations