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

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

Introduction

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

Prototype

public void setLocalizedContextAttributeWithFunction(String key, Function<Locale, String> function) 

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);//  www . ja va2s .c  om
    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.mentions.internal.util.DefaultMentionsNotifier.java

License:Open Source License

@Override
public void notify(long userId, long groupId, String title, String content, String className, long classPK,
        LocalizedValuesMap subjectLocalizedValuesMap, LocalizedValuesMap bodyLocalizedValuesMap,
        ServiceContext serviceContext) throws PortalException {

    String[] mentionedUsersScreenNames = getMentionedUsersScreenNames(userId, className, content);

    if (ArrayUtil.isEmpty(mentionedUsersScreenNames)) {
        return;//from w w w  . java 2  s  . co  m
    }

    User user = _userLocalService.getUser(userId);

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

    String messageUserEmailAddress = _portal.getUserEmailAddress(userId);
    String messageUserName = _portal.getUserName(userId, StringPool.BLANK);

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

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    subscriptionSender.setClassName(className);
    subscriptionSender.setClassPK(classPK);
    subscriptionSender.setCompanyId(user.getCompanyId());
    subscriptionSender.setContextAttribute("[$CONTENT$]", content, false);
    subscriptionSender.setContextAttributes("[$USER_ADDRESS$]", messageUserEmailAddress, "[$USER_NAME$]",
            messageUserName, "[$CONTENT_URL$]", contentURL);
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(title);
    subscriptionSender.setEntryURL(contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedContextAttributeWithFunction("[$ASSET_ENTRY_NAME$]",
            locale -> getAssetEntryName(className, locale));
    subscriptionSender.setMailId("mb_discussion", classPK);
    subscriptionSender.setNotificationType(MentionsConstants.NOTIFICATION_TYPE_MENTION);
    subscriptionSender.setPortletId(MentionsPortletKeys.MENTIONS);
    subscriptionSender.setScopeGroupId(groupId);
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));

    for (String mentionedUserScreenName : mentionedUsersScreenNames) {
        User mentionedUser = _userLocalService.fetchUserByScreenName(user.getCompanyId(),
                mentionedUserScreenName);

        if (mentionedUser == null) {
            continue;
        }

        subscriptionSender.addRuntimeSubscribers(mentionedUser.getEmailAddress(), mentionedUser.getFullName());
    }

    subscriptionSender.flushNotificationsAsync();
}