use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class EmailDataUtil method sendEmail.
public static void sendEmail(Long emailId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Email email = dataAccessor.getEmail(emailId);
if (email.getState() != EmailState.IN_PROGRESS)
return;
UserData user = UserDataUtil.createUserData(dataAccessor.getUser(email.getUserId()));
if (user.getDisplayName() == null || user.getLanguage() == null || (!_isToday(email.getScheduledDate()) && email.getScheduledDate().before(new Date()))) {
email.setState(EmailState.DROPPED);
email.setLastUpdated(new Date());
email = dataAccessor.createOrUpdateEmail(email);
return;
}
String content = _getContentSnippet(email, user.getLanguage());
Pattern senderNamePattern = Pattern.compile("<!-- SENDER_NAME:(.+?) -->");
Pattern senderEmailPattern = Pattern.compile("<!-- SENDER_EMAIL:(.+?) -->");
Pattern subjectPattern = Pattern.compile("<div subject .+?>(.+?)<\\/div>");
String senderName = null;
String senderEmail = null;
String subject = null;
Matcher m = null;
if ((m = senderNamePattern.matcher(content)).find())
senderName = m.group(1).trim();
if ((m = senderEmailPattern.matcher(content)).find())
senderEmail = m.group(1).trim();
if ((m = subjectPattern.matcher(content)).find())
subject = m.group(1).trim();
EmailUtil.sendMail(senderName, senderEmail, user.getDisplayName(), user.getEmail(), subject, EmailTemplateUtil.getEmailBody(content, user.getLanguage() != null ? user.getLanguage() : Language.ENGLISH));
email.setState(EmailState.SENT);
email.setLastUpdated(new Date());
dataAccessor.createOrUpdateEmail(email);
_updateUserEntity(email.getUserId());
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class EmailDataUtil method _createDataModelForAuthorFollowEmail.
private static Object[] _createDataModelForAuthorFollowEmail(String userAuthorId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
// Hack
Long userId = Long.parseLong(userAuthorId.substring(0, userAuthorId.indexOf("-")));
Long authorId = Long.parseLong(userAuthorId.substring(userAuthorId.indexOf("-") + 1));
logger.log(Level.INFO, "userId::" + userId);
logger.log(Level.INFO, "authorId::" + authorId);
UserData user = UserDataUtil.createUserData(dataAccessor.getUser(userId));
AuthorData follower = AuthorDataUtil.createAuthorData(dataAccessor.getAuthorByUserId(userId));
Map<String, Object> dataModel = new HashMap<>();
dataModel.put("follower_name", follower.getName() != null ? follower.getName() : follower.getNameEn());
dataModel.put("follower_page_url", _getDomainName(follower.getLanguage()) + follower.getPageUrl());
dataModel.put("follower_profile_image_url", follower.getProfileImageUrl(50));
return new Object[] { dataModel, user.getLanguage() };
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserV1Api method post.
@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
UserData userData = request.userId == null ? new UserData(AccessTokenFilter.getAccessToken().getUserId()) : new UserData(request.userId.equals(0L) ? null : request.userId);
if (request.hasName) {
String firstName = request.name.trim();
String lastName = null;
if (firstName.lastIndexOf(' ') != -1) {
lastName = firstName.substring(firstName.lastIndexOf(' ') + 1);
firstName = firstName.substring(0, firstName.lastIndexOf(' '));
}
userData.setFirstName(firstName);
userData.setLastName(lastName);
}
if (request.hasEmail)
userData.setEmail(request.email);
if (request.hasPhone)
userData.setPhone(request.phone);
if (request.hasLanguage)
userData.setLanguage(request.language);
// Save UserData
userData = UserDataUtil.saveUserData(userData);
// New User (added by AEE)
if (request.userId != null && request.userId.equals(0L)) {
// Create Author profile for the User
Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language == null ? UxModeFilter.getFilterLanguage() : request.language);
userData.setAuthor(new AuthorData(authorId));
userData.setProfilePageUrl("/author/" + authorId);
// Send welcome mail to the user
Task task = TaskQueueFactory.newTask().setUrl("/user/email").addParam("userId", userData.getId().toString()).addParam("language", request.language == null ? UxModeFilter.getDisplayLanguage().toString() : request.language.toString()).addParam("sendWelcomeMail", "true");
TaskQueueFactory.getUserTaskQueue().add(task);
}
return new Response(userData);
}
Aggregations