use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class EmailDataUtil method _sendConsolidatedEmail.
private static void _sendConsolidatedEmail(Long userId, List<Email> emailList) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserData user = UserDataUtil.createUserData(dataAccessor.getUser(userId));
// Dropping mails if user doesn't have name or language
if (user.getDisplayName() == null || user.getLanguage() == null) {
for (Email email : emailList) {
email.setState(EmailState.DROPPED);
email.setLastUpdated(new Date());
}
emailList = dataAccessor.createOrUpdateEmailList(emailList);
return;
}
String consolidatedContent = new String();
for (Email email : emailList) {
if (email.getState() != EmailState.PENDING)
continue;
consolidatedContent = consolidatedContent + _getContentSnippet(email, user.getLanguage());
email.setState(EmailState.SENT);
email.setLastUpdated(new Date());
}
if (// No PENDING emails
consolidatedContent.isEmpty())
return;
String content = EmailTemplateUtil.getEmailBody(consolidatedContent, user.getLanguage());
Pattern senderNamePattern = Pattern.compile("<!-- SENDER_NAME:(.+?) -->");
Pattern senderEmailPattern = Pattern.compile("<!-- SENDER_EMAIL:(.+?) -->");
String senderName = null;
String senderEmail = null;
String subject = dataAccessor.getI18nStrings(I18nGroup.EMAIL, user.getLanguage()).get("email_consolidated_subject");
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();
EmailUtil.sendMail(senderName, senderEmail, user.getDisplayName(), user.getEmail(), subject, content);
dataAccessor.createOrUpdateEmailList(emailList);
_updateUserEntity(userId);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class EventDataUtil method createEventData.
public static EventData createEventData(Event event, Boolean includePratilipiList) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
Page eventPage = dataAccessor.getPage(PageType.EVENT, event.getId());
return createEventData(event, eventPage, includePratilipiList);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class EmailDataUtil method _createDataModelForCommentReviewEmail.
private static Object[] _createDataModelForCommentReviewEmail(Long commentId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
CommentData comment = CommentDataUtil.createCommentData(dataAccessor.getComment(commentId));
comment.setUser(UserDataUtil.createUserData(dataAccessor.getUser(comment.getUserId())));
UserPratilipiData review = UserPratilipiDataUtil.createUserPratilipiData(dataAccessor.getUserPratilipi(comment.getParentId()));
PratilipiData pratilipi = PratilipiDataUtil.createPratilipiData(dataAccessor.getPratilipi(review.getPratilipiId()));
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", review.getUser().getAuthor().getName() != null ? review.getUser().getAuthor().getName() : review.getUser().getAuthor().getNameEn());
dataModel.put("reviewer_page_url", _getDomainName(review.getUser().getAuthor().getLanguage()) + review.getUser().getProfilePageUrl());
dataModel.put("reviewer_image_url", review.getUser().getAuthor().getProfileImageUrl(64));
dataModel.put("review_date", _getDateFormat(review.getReviewDate()));
dataModel.put("review_review", HtmlUtil.truncateText(review.getReview(), 250));
dataModel.put("commentor_name", comment.getUser().getAuthor().getName() != null ? comment.getUser().getAuthor().getName() : comment.getUser().getAuthor().getNameEn());
dataModel.put("commentor_page_url", _getDomainName(comment.getUser().getAuthor().getLanguage()) + comment.getUser().getProfilePageUrl());
dataModel.put("commentor_image_url", comment.getUser().getAuthor().getProfileImageUrl(50));
dataModel.put("comment_date", _getDateFormat(comment.getCreationDate()));
dataModel.put("comment_comment", HtmlUtil.truncateText(comment.getContent(), 200));
return new Object[] { dataModel, pratilipi.getLanguage() };
}
use of com.pratilipi.data.DataAccessor 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.DataAccessor in project pratilipi by Pratilipi.
the class AuditLogProcessApi method _createPratilipiPublishedEmails.
private List<Email> _createPratilipiPublishedEmails(Pratilipi pratilipi, Set<Long> followersSet) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
List<Long> followers = new ArrayList<Long>(followersSet);
List<Email> existingEmailList = dataAccessor.getEmailList(null, EmailType.PRATILIPI_PUBLISHED_FOLLOWER, pratilipi.getId(), null, null);
List<Email> emailList = new LinkedList<>();
for (Email email : existingEmailList) {
followers.remove(email.getUserId());
if (email.getState() == EmailState.DEFERRED) {
// Updating existing email state, if required
email.setState(EmailState.PENDING);
email.setLastUpdated(new Date());
emailList.add(email);
}
}
// Creating new e-mails
for (Long follower : followers) {
emailList.add(dataAccessor.newEmail(follower, EmailType.PRATILIPI_PUBLISHED_FOLLOWER, pratilipi.getId()));
}
return emailList;
}
Aggregations