use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method createUserPratilipiData.
private static UserPratilipiData createUserPratilipiData(UserPratilipiDoc userPratilipiDoc) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUser(userPratilipiDoc.getUserId());
UserData userData = UserDataUtil.createUserData(user);
UserPratilipiData userPratilipiData = new UserPratilipiData();
userPratilipiData.setId(userPratilipiDoc.getId());
userPratilipiData.setUserId(userPratilipiDoc.getUserId());
userPratilipiData.setUser(userData);
userPratilipiData.setUserName(userData.getDisplayName());
userPratilipiData.setUserImageUrl(userData.getProfileImageUrl());
userPratilipiData.setUserProfilePageUrl(userData.getProfilePageUrl());
userPratilipiData.setRating(userPratilipiDoc.getRating());
userPratilipiData.setReview(processReview(userPratilipiDoc.getReviewTitle(), userPratilipiDoc.getReview()));
userPratilipiData.setReviewDate(userPratilipiDoc.getReviewDate());
userPratilipiData.setLikeCount(userPratilipiDoc.getLikeCount());
userPratilipiData.setCommentCount(userPratilipiDoc.getCommentCount());
userPratilipiData.setLiked(userPratilipiDoc.getLikedByUserIds().contains(AccessTokenFilter.getAccessToken().getUserId()));
return userPratilipiData;
}
use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.
the class UserDataUtil method registerUser.
public static UserData registerUser(String firstName, String lastName, String email, String password, UserSignUpSource signUpSource) throws InvalidArgumentException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUserByEmail(email.toLowerCase());
if (user == null || user.getState() == UserState.DELETED) {
user = dataAccessor.newUser();
} else if (user.getState() != UserState.REFERRAL) {
JsonObject errorMessages = new JsonObject();
errorMessages.addProperty("email", GenericRequest.ERR_EMAIL_REGISTERED_ALREADY);
throw new InvalidArgumentException(errorMessages);
}
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_ADD, user);
user.setPassword(PasswordUtil.getSaltedHash(password));
user.setEmail(email.toLowerCase());
user.setState(UserState.REGISTERED);
user.setSignUpDate(new Date());
user.setSignUpSource(signUpSource);
user = dataAccessor.createOrUpdateUser(user, auditLog);
UserData userData = createUserData(user);
userData.setFirstName(firstName);
userData.setLastName(lastName);
return userData;
}
use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.
the class UserDataUtil method verifyUserEmail.
public static void verifyUserEmail(String email, String verificationToken) throws InvalidArgumentException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUserByEmail(email.toLowerCase());
if (user == null || user.getState() != UserState.REGISTERED)
return;
if (!_verifyToken(user, verificationToken))
throw new InvalidArgumentException(GenericRequest.ERR_VERIFICATION_TOKEN_INVALID_OR_EXPIRED);
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_UPDATE, user);
user.setState(UserState.ACTIVE);
// Note: Do not clear VerificationToken
user = dataAccessor.createOrUpdateUser(user, auditLog);
}
use of com.pratilipi.data.type.User in project pratilipi by Pratilipi.
the class EmailProcessApi method get.
@Get
public GenericResponse get(GenericRequest request) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
RtdbAccessor rtdbAccessor = DataAccessorFactory.getRtdbAccessor();
Map<Long, UserPreferenceRtdb> userPreferences = null;
List<Email> emailList = new ArrayList<>();
DataListIterator<Email> it = dataAccessor.getEmailListIteratorForStatePending(null, false);
Set<Long> userIds = new HashSet<>();
while (it.hasNext()) {
Email email = it.next();
emailList.add(email);
userIds.add(email.getUserId());
}
userPreferences = rtdbAccessor.getUserPreferences(userIds);
Map<Long, User> users = dataAccessor.getUsers(userPreferences.keySet());
// Re-scheduling for all Emails
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss z");
dateFormat.setTimeZone(TimeZone.getTimeZone("IST"));
for (Email email : emailList) {
UserPreferenceRtdb preference = userPreferences.get(email.getUserId());
User user = users.get(email.getUserId());
if (email.getScheduledDate().before(new Date()))
continue;
if (email.getScheduledDate().equals(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate())))
continue;
logger.log(Level.INFO, "Rescheduling email: " + email.getId() + " from " + dateFormat.format(email.getScheduledDate()) + " to " + dateFormat.format(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate())));
email.setScheduledDate(preference.getEmailFrequency().getNextSchedule(user.getLastEmailedDate()));
if (// User changed setting to NEVER -> Scheduled Date will be null
email.getScheduledDate() == null)
email.setState(EmailState.DROPPED);
email.setLastUpdated(new Date());
}
// Creating Tasks
List<Task> taskList = new ArrayList<>();
Set<Long> userIdTaskSet = new HashSet<>();
for (Email email : emailList) {
if (// User changed setting to NEVER -> Email Dropped
email.getState() != EmailState.PENDING)
continue;
if (email.getScheduledDate().after(new Date()))
continue;
UserPreferenceRtdb preference = userPreferences.get(email.getUserId());
if (preference.getEmailFrequency() == EmailFrequency.IMMEDIATELY)
taskList.add(TaskQueueFactory.newTask().setUrl("/email/process").addParam("emailId", email.getId().toString()));
else
userIdTaskSet.add(email.getUserId());
email.setState(EmailState.IN_PROGRESS);
email.setLastUpdated(new Date());
}
for (Long userId : userIdTaskSet) taskList.add(TaskQueueFactory.newTask().setUrl("/email/process").addParam("userId", userId.toString()));
TaskQueueFactory.getEmailHpTaskQueue().addAll(taskList);
emailList = dataAccessor.createOrUpdateEmailList(emailList);
return new GenericResponse();
}
use of com.pratilipi.data.type.User 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;
}
Aggregations