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

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

Introduction

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

Prototype

public void addRuntimeSubscribers(String toAddress, String toName) 

Source Link

Usage

From source file:com.liferay.asset.publisher.web.internal.messaging.AssetEntriesCheckerUtil.java

License:Open Source License

private static void _notifySubscribers(List<Subscription> subscriptions, PortletPreferences portletPreferences,
        List<AssetEntry> assetEntries) {

    if (!_assetPublisherWebUtil.getEmailAssetEntryAddedEnabled(portletPreferences)) {

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

    Map<List<AssetEntry>, List<User>> assetEntriesToUsersMap = new HashMap<>();

    for (Subscription subscription : subscriptions) {
        long userId = subscription.getUserId();

        User user = _userLocalService.fetchUser(userId);

        if ((user == null) || !user.isActive()) {
            continue;
        }

        List<AssetEntry> filteredAssetEntries = _filterAssetEntries(userId, assetEntries);

        if (filteredAssetEntries.isEmpty()) {
            continue;
        }

        List<User> users = assetEntriesToUsersMap.get(filteredAssetEntries);

        if (users == null) {
            users = new LinkedList<>();

            assetEntriesToUsersMap.put(filteredAssetEntries, users);
        }

        users.add(user);
    }

    for (Map.Entry<List<AssetEntry>, List<User>> entry : assetEntriesToUsersMap.entrySet()) {

        List<AssetEntry> filteredAssetEntries = entry.getKey();
        List<User> users = entry.getValue();

        SubscriptionSender subscriptionSender = _getSubscriptionSender(portletPreferences,
                filteredAssetEntries);

        if (subscriptionSender == null) {
            continue;
        }

        for (User user : users) {
            subscriptionSender.addRuntimeSubscribers(user.getEmailAddress(), user.getFullName());
        }

        subscriptionSender.flushNotificationsAsync();
    }
}

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);/*from   w  ww.j  a  va2  s .  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.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void sendEmail(JournalArticle article, String articleURL, PortletPreferences preferences,
        String emailType, ServiceContext serviceContext) throws PortalException {

    JournalGroupServiceConfiguration journalGroupServiceConfiguration = getJournalGroupServiceConfiguration(
            article.getGroupId());// w w  w . j a va  2  s .  c  o m

    if (preferences == null) {
        return;
    } else if (emailType.equals("denied")
            && journalGroupServiceConfiguration.emailArticleApprovalDeniedEnabled()) {
    } else if (emailType.equals("granted")
            && journalGroupServiceConfiguration.emailArticleApprovalGrantedEnabled()) {
    } else if (emailType.equals("requested")
            && journalGroupServiceConfiguration.emailArticleApprovalRequestedEnabled()) {
    } else if (emailType.equals("review") && journalGroupServiceConfiguration.emailArticleReviewEnabled()) {
    } else {
        return;
    }

    Company company = companyLocalService.getCompany(article.getCompanyId());

    User user = userLocalService.getUser(article.getUserId());

    String fromName = journalGroupServiceConfiguration.emailFromName();
    String fromAddress = journalGroupServiceConfiguration.emailFromAddress();

    String toName = user.getFullName();
    String toAddress = user.getEmailAddress();

    if (emailType.equals("requested")) {
        String tempToName = fromName;
        String tempToAddress = fromAddress;

        fromName = toName;
        fromAddress = toAddress;

        toName = tempToName;
        toAddress = tempToAddress;
    }

    Map<Locale, String> localizedSubjectMap = null;
    Map<Locale, String> localizedBodyMap = null;

    if (emailType.equals("denied")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleApprovalDeniedSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleApprovalDeniedBody());
    } else if (emailType.equals("granted")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleApprovalGrantedSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleApprovalGrantedBody());
    } else if (emailType.equals("requested")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleApprovalGrantedSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleApprovalGrantedBody());
    } else if (emailType.equals("review")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleReviewSubject());
        localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleReviewBody());
    }

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setCompanyId(company.getCompanyId());
    subscriptionSender.setContextAttributes("[$ARTICLE_ID$]", article.getArticleId(), "[$ARTICLE_TITLE$]",
            article.getTitle(serviceContext.getLanguageId()), "[$ARTICLE_URL$]", articleURL,
            "[$ARTICLE_USER_NAME$]", article.getUserName(), "[$ARTICLE_VERSION$]", article.getVersion());
    subscriptionSender.setContextCreatorUserPrefix("ARTICLE");
    subscriptionSender.setCreatorUserId(article.getUserId());
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(localizedBodyMap);
    subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap);
    subscriptionSender.setMailId("journal_article", article.getId());

    String portletId = PortletProviderUtil.getPortletId(JournalArticle.class.getName(),
            PortletProvider.Action.EDIT);

    subscriptionSender.setPortletId(portletId);

    subscriptionSender.setScopeGroupId(article.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    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 . j  a v a 2s. c om
    }

    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();
}