Search in sources :

Example 16 with DataAccessor

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);
}
Also used : Pattern(java.util.regex.Pattern) Email(com.pratilipi.data.type.Email) UserData(com.pratilipi.data.client.UserData) Matcher(java.util.regex.Matcher) DataAccessor(com.pratilipi.data.DataAccessor) Date(java.util.Date)

Example 17 with DataAccessor

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);
}
Also used : DataAccessor(com.pratilipi.data.DataAccessor) Page(com.pratilipi.data.type.Page)

Example 18 with DataAccessor

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() };
}
Also used : HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) PratilipiData(com.pratilipi.data.client.PratilipiData) CommentData(com.pratilipi.data.client.CommentData) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData)

Example 19 with DataAccessor

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() };
}
Also used : UserData(com.pratilipi.data.client.UserData) HashMap(java.util.HashMap) DataAccessor(com.pratilipi.data.DataAccessor) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData) PratilipiData(com.pratilipi.data.client.PratilipiData) UserPratilipiData(com.pratilipi.data.client.UserPratilipiData)

Example 20 with DataAccessor

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;
}
Also used : Email(com.pratilipi.data.type.Email) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Date(java.util.Date)

Aggregations

DataAccessor (com.pratilipi.data.DataAccessor)162 Date (java.util.Date)53 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)37 Pratilipi (com.pratilipi.data.type.Pratilipi)34 Author (com.pratilipi.data.type.Author)33 AuditLog (com.pratilipi.data.type.AuditLog)32 UserPratilipi (com.pratilipi.data.type.UserPratilipi)32 ArrayList (java.util.ArrayList)30 Page (com.pratilipi.data.type.Page)28 HashMap (java.util.HashMap)25 GenericResponse (com.pratilipi.api.shared.GenericResponse)24 DocAccessor (com.pratilipi.data.DocAccessor)22 User (com.pratilipi.data.type.User)22 Get (com.pratilipi.api.annotation.Get)20 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 PratilipiData (com.pratilipi.data.client.PratilipiData)15 UserData (com.pratilipi.data.client.UserData)14 BlobAccessor (com.pratilipi.data.BlobAccessor)13 Email (com.pratilipi.data.type.Email)13 JsonObject (com.google.gson.JsonObject)12