Example usage for com.liferay.portal.kernel.util PropsKeys DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED

List of usage examples for com.liferay.portal.kernel.util PropsKeys DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED

Introduction

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

Prototype

String DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED

To view the source code for com.liferay.portal.kernel.util PropsKeys DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED.

Click Source Link

Usage

From source file:com.liferay.message.boards.internal.service.SubscriptionMBMessageLocalServiceWrapper.java

License:Open Source License

protected void notifyDiscussionSubscribers(long userId, MBMessage message, ServiceContext serviceContext)
        throws PortalException {

    if (!PrefsPropsUtil.getBoolean(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED)) {

        return;/* w  w  w.  ja v  a  2s.c  o  m*/
    }

    MBDiscussion mbDiscussion = _mbDiscussionLocalService.getThreadDiscussion(message.getThreadId());

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    contentURL = _http.addParameter(contentURL, serviceContext.getAttribute("namespace") + "messageId",
            message.getMessageId());

    String userAddress = StringPool.BLANK;
    String userName = (String) serviceContext.getAttribute("pingbackUserName");

    if (Validator.isNull(userName)) {
        userAddress = _portal.getUserEmailAddress(message.getUserId());
        userName = _portal.getUserName(message.getUserId(), StringPool.BLANK);
    }

    String fromName = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String subject = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_SUBJECT);
    String body = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_BODY);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(message.getCompanyId());
    subscriptionSender.setClassName(MBDiscussion.class.getName());
    subscriptionSender.setClassPK(mbDiscussion.getDiscussionId());
    subscriptionSender.setContextAttribute("[$COMMENTS_BODY$]", message.getBody(message.isFormatBBCode()),
            false);
    subscriptionSender.setContextAttributes("[$COMMENTS_USER_ADDRESS$]", userAddress, "[$COMMENTS_USER_NAME$]",
            userName, "[$CONTENT_URL$]", contentURL);
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(message.getBody());
    subscriptionSender.setEntryURL(contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    Date modifiedDate = message.getModifiedDate();

    subscriptionSender.setMailId("mb_discussion", message.getCategoryId(), message.getMessageId(),
            modifiedDate.getTime());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (serviceContext.isCommandUpdate()) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    String portletId = PortletProviderUtil.getPortletId(Comment.class.getName(), PortletProvider.Action.VIEW);

    subscriptionSender.setPortletId(portletId);

    subscriptionSender.setScopeGroupId(message.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUniqueMailId(false);

    String className = (String) serviceContext.getAttribute("className");
    long classPK = ParamUtil.getLong(serviceContext, "classPK");

    subscriptionSender.addPersistedSubscribers(className, classPK);

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.portlet.messageboards.service.impl.MBMessageLocalServiceImpl.java

License:Open Source License

protected void notifyDiscussionSubscribers(MBMessage message, ServiceContext serviceContext)
        throws SystemException {

    if (!PrefsPropsUtil.getBoolean(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED)) {

        return;//  w  w  w. j av a 2 s.co m
    }

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    String userAddress = StringPool.BLANK;
    String userName = (String) serviceContext.getAttribute("pingbackUserName");

    if (Validator.isNull(userName)) {
        userAddress = PortalUtil.getUserEmailAddress(message.getUserId());
        userName = PortalUtil.getUserName(message.getUserId(), StringPool.BLANK);
    }

    String fromName = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String subject = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_SUBJECT);
    String body = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_BODY);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(message.getCompanyId());
    subscriptionSender.setContextAttributes("[$COMMENTS_BODY$]", message.getBody(true),
            "[$COMMENTS_USER_ADDRESS$]", userAddress, "[$COMMENTS_USER_NAME$]", userName, "[$CONTENT_URL$]",
            contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("mb_discussion", message.getCategoryId(), message.getMessageId());
    subscriptionSender.setScopeGroupId(message.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(message.getUserId());

    String className = (String) serviceContext.getAttribute("className");
    long classPK = GetterUtil.getLong((String) serviceContext.getAttribute("classPK"));

    subscriptionSender.addPersistedSubscribers(className, classPK);

    subscriptionSender.flushNotificationsAsync();
}