Example usage for com.liferay.portal.kernel.util SubscriptionSender setBody

List of usage examples for com.liferay.portal.kernel.util SubscriptionSender setBody

Introduction

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

Prototype

public void setBody(String body) 

Source Link

Usage

From source file:com.liferay.flags.internal.messaging.FlagsRequestMessageListener.java

License:Open Source License

protected void notify(long reporterUserId, Company company, Group group, String reporterEmailAddress,
        String reporterUserName, String reportedEmailAddress, String reportedUserName, String reportedUserURL,
        long contentId, String contentTitle, String contentType, String contentURL, String reason,
        String fromName, String fromAddress, String toName, String toAddress, String subject, String body,
        ServiceContext serviceContext) throws Exception {

    Date now = new Date();

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(company.getCompanyId());
    subscriptionSender.setContextAttributes("[$CONTENT_ID$]", contentId, "[$CONTENT_TYPE$]", contentType,
            "[$DATE$]", now.toString(), "[$REASON$]", reason, "[$REPORTED_USER_ADDRESS$]", reportedEmailAddress,
            "[$REPORTED_USER_NAME$]", reportedUserName, "[$REPORTED_USER_URL$]", reportedUserURL,
            "[$REPORTER_USER_ADDRESS$]", reporterEmailAddress, "[$REPORTER_USER_NAME$]", reporterUserName);
    subscriptionSender.setContextAttribute("[$CONTENT_TITLE$]", contentTitle, false);
    subscriptionSender.setContextAttribute("[$CONTENT_URL$]", contentURL, false);
    subscriptionSender.setCreatorUserId(reporterUserId);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedContextAttributeWithFunction("[$SITE_NAME$]",
            locale -> _getGroupDescriptiveName(group, locale));
    subscriptionSender.setMailId("flags_request", contentId);
    subscriptionSender.setPortletId(PortletKeys.FLAGS);
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);

    subscriptionSender.addRuntimeSubscribers(toAddress, toName);

    subscriptionSender.flushNotificationsAsync();
}

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 . j  a v  a  2 s. 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();
}