Example usage for com.liferay.portal.kernel.util FastDateFormatConstants LONG

List of usage examples for com.liferay.portal.kernel.util FastDateFormatConstants LONG

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util FastDateFormatConstants LONG.

Prototype

int LONG

To view the source code for com.liferay.portal.kernel.util FastDateFormatConstants LONG.

Click Source Link

Usage

From source file:com.liferay.privatemessaging.service.impl.UserThreadLocalServiceImpl.java

License:Open Source License

protected void sendEmail(long mbMessageId, ThemeDisplay themeDisplay) throws Exception {

    MBMessage mbMessage = MBMessageLocalServiceUtil.getMBMessage(mbMessageId);

    User sender = UserLocalServiceUtil.getUser(mbMessage.getUserId());

    Company company = CompanyLocalServiceUtil.getCompany(sender.getCompanyId());

    InternetAddress from = new InternetAddress(company.getEmailAddress());

    String subject = StringUtil.read(PrivateMessagingPortlet.class
            .getResourceAsStream("dependencies/notification_message_subject.tmpl"));

    subject = StringUtil.replace(subject, new String[] { "[$COMPANY_NAME$]", "[$FROM_NAME$]" },
            new String[] { company.getName(), sender.getFullName() });

    String body = StringUtil.read(
            PrivateMessagingPortlet.class.getResourceAsStream("dependencies/notification_message_body.tmpl"));

    long portraitId = sender.getPortraitId();
    String tokenId = WebServerServletTokenUtil.getToken(sender.getPortraitId());
    String portraitURL = themeDisplay.getPortalURL() + themeDisplay.getPathImage() + "/user_"
            + (sender.isFemale() ? "female" : "male") + "_portrait?img_id=" + portraitId + "&t=" + tokenId;

    body = StringUtil.replace(body,/* w ww. j a v  a 2s . c o  m*/
            new String[] { "[$BODY$]", "[$COMPANY_NAME$]", "[$FROM_AVATAR$]", "[$FROM_NAME$]",
                    "[$FROM_PROFILE_URL$]", "[$SUBJECT$]" },
            new String[] { mbMessage.getBody(), company.getName(), portraitURL, sender.getFullName(),
                    sender.getDisplayURL(themeDisplay), mbMessage.getSubject() });

    List<UserThread> userThreads = UserThreadLocalServiceUtil.getMBThreadUserThreads(mbMessage.getThreadId());

    for (UserThread userThread : userThreads) {
        if ((userThread.getUserId() == mbMessage.getUserId()) && UserNotificationManagerUtil.isDeliver(
                userThread.getUserId(), PortletKeys.PRIVATE_MESSAGING, PrivateMessagingConstants.NEW_MESSAGE, 0,
                UserNotificationDeliveryConstants.TYPE_EMAIL)) {

            continue;
        }

        User recipient = UserLocalServiceUtil.getUser(userThread.getUserId());

        String threadURL = getThreadURL(recipient, mbMessage.getThreadId(), themeDisplay);

        if (Validator.isNull(threadURL)) {
            continue;
        }

        InternetAddress to = new InternetAddress(recipient.getEmailAddress());

        Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime(FastDateFormatConstants.LONG,
                FastDateFormatConstants.SHORT, recipient.getLocale(), recipient.getTimeZone());

        String userThreadBody = StringUtil.replace(body, new String[] { "[$SENT_DATE$]", "[$THREAD_URL$]" },
                new String[] { dateFormatDateTime.format(mbMessage.getCreateDate()), threadURL });

        MailMessage mailMessage = new MailMessage(from, to, subject, userThreadBody, true);

        MailServiceUtil.sendEmail(mailMessage);
    }
}