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

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

Introduction

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

Prototype

public void setLocalizedSubjectMap(Map<Locale, String> localizedSubjectMap) 

Source Link

Usage

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

License:Open Source License

private static SubscriptionSender _getSubscriptionSender(PortletPreferences portletPreferences,
        List<AssetEntry> assetEntries) {

    if (assetEntries.isEmpty()) {
        return null;
    }/* w w w. j  a v  a 2 s.c o  m*/

    AssetEntry assetEntry = assetEntries.get(0);

    String fromName = _assetPublisherWebUtil.getEmailFromName(portletPreferences, assetEntry.getCompanyId());
    String fromAddress = _assetPublisherWebUtil.getEmailFromAddress(portletPreferences,
            assetEntry.getCompanyId());

    Map<Locale, String> localizedSubjectMap = _assetPublisherWebUtil
            .getEmailAssetEntryAddedSubjectMap(portletPreferences);
    Map<Locale, String> localizedBodyMap = _assetPublisherWebUtil
            .getEmailAssetEntryAddedBodyMap(portletPreferences);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setCompanyId(assetEntry.getCompanyId());
    subscriptionSender.setContextAttributes("[$ASSET_ENTRIES$]",
            ListUtil.toString(assetEntries, _titleAccessor, StringPool.COMMA_AND_SPACE));
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(localizedBodyMap);
    subscriptionSender
            .setLocalizedPortletTitleMap(PortletConfigurationUtil.getPortletTitleMap(portletPreferences));
    subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap);
    subscriptionSender.setMailId("asset_entry", assetEntry.getEntryId());
    subscriptionSender.setPortletId(AssetPublisherPortletKeys.ASSET_PUBLISHER);
    subscriptionSender.setReplyToAddress(fromAddress);

    return subscriptionSender;
}

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, BlogsEntry entry, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    String entryURL = (String) workflowContext.get(WorkflowConstants.CONTEXT_URL);

    if (!entry.isApproved() || Validator.isNull(entryURL)) {
        return;//from   w w w  .j  av a2  s .  com
    }

    BlogsGroupServiceSettings blogsGroupServiceSettings = BlogsGroupServiceSettings
            .getInstance(entry.getGroupId());

    boolean sendEmailEntryUpdated = GetterUtil.getBoolean(serviceContext.getAttribute("sendEmailEntryUpdated"));

    if (serviceContext.isCommandAdd() && blogsGroupServiceSettings.isEmailEntryAddedEnabled()) {
    } else if (sendEmailEntryUpdated && serviceContext.isCommandUpdate()
            && blogsGroupServiceSettings.isEmailEntryUpdatedEnabled()) {
    } else {
        return;
    }

    Group group = groupPersistence.findByPrimaryKey(entry.getGroupId());

    String entryTitle = entry.getTitle();

    String fromName = blogsGroupServiceSettings.getEmailFromName();
    String fromAddress = blogsGroupServiceSettings.getEmailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (serviceContext.isCommandUpdate()) {
        subjectLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryUpdatedSubject();
        bodyLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryAddedSubject();
        bodyLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryAddedBody();
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            BlogsPermission.RESOURCE_NAME);

    subscriptionSender.setClassPK(entry.getEntryId());
    subscriptionSender.setClassName(entry.getModelClassName());
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttribute("[$BLOGS_ENTRY_CONTENT$]",
            StringUtil.shorten(HtmlUtil.stripHtml(entry.getContent()), 500), false);
    subscriptionSender.setContextAttributes("[$BLOGS_ENTRY_CREATE_DATE$]",
            Time.getSimpleDate(entry.getCreateDate(), "yyyy/MM/dd"), "[$BLOGS_ENTRY_DESCRIPTION$]",
            entry.getDescription(), "[$BLOGS_ENTRY_SITE_NAME$]",
            group.getDescriptiveName(serviceContext.getLocale()), "[$BLOGS_ENTRY_STATUS_BY_USER_NAME$]",
            entry.getStatusByUserName(), "[$BLOGS_ENTRY_TITLE$]", entryTitle, "[$BLOGS_ENTRY_UPDATE_COMMENT$]",
            HtmlUtil.replaceNewLine(
                    GetterUtil.getString(serviceContext.getAttribute("emailEntryUpdatedComment"))),
            "[$BLOGS_ENTRY_URL$]", entryURL, "[$BLOGS_ENTRY_USER_PORTRAIT_URL$]",
            workflowContext.get(WorkflowConstants.CONTEXT_USER_PORTRAIT_URL), "[$BLOGS_ENTRY_USER_URL$]",
            workflowContext.get(WorkflowConstants.CONTEXT_USER_URL));
    subscriptionSender.setContextCreatorUserPrefix("BLOGS_ENTRY");
    subscriptionSender.setCreatorUserId(entry.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    if (bodyLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    }

    if (subjectLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    }

    subscriptionSender.setMailId("blogs_entry", entry.getEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

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

    subscriptionSender.setNotificationType(notificationType);

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

    subscriptionSender.setPortletId(portletId);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(BlogsEntry.class.getName(), entry.getGroupId());

    subscriptionSender.addPersistedSubscribers(BlogsEntry.class.getName(), entry.getEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, BookmarksEntry entry, ServiceContext serviceContext)
        throws PortalException {

    String layoutFullURL = serviceContext.getLayoutFullURL();

    if (!entry.isApproved() || Validator.isNull(layoutFullURL)) {
        return;/*from   w w  w.j a va2  s . c o m*/
    }

    BookmarksGroupServiceOverriddenConfiguration bookmarksGroupServiceOverriddenConfiguration = configurationProvider
            .getConfiguration(BookmarksGroupServiceOverriddenConfiguration.class,
                    new GroupServiceSettingsLocator(entry.getGroupId(), BookmarksConstants.SERVICE_NAME));

    if ((serviceContext.isCommandAdd()
            && !bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedEnabled())
            || (serviceContext.isCommandUpdate()
                    && !bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedEnabled())) {

        return;
    }

    String statusByUserName = StringPool.BLANK;

    try {
        User user = userLocalService.getUserById(serviceContext.getGuestOrUserId());

        statusByUserName = user.getFullName();
    } catch (Exception e) {
        _log.error(e, e);
    }

    String entryTitle = entry.getName();

    StringBundler sb = new StringBundler(7);

    sb.append(layoutFullURL);
    sb.append(Portal.FRIENDLY_URL_SEPARATOR);
    sb.append("bookmarks");
    sb.append(StringPool.SLASH);
    sb.append("folder");
    sb.append(StringPool.SLASH);
    sb.append(entry.getFolderId());

    String entryURL = sb.toString();

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

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (serviceContext.isCommandUpdate()) {
        subjectLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedSubject();
        bodyLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedSubject();
        bodyLocalizedValuesMap = bookmarksGroupServiceOverriddenConfiguration.emailEntryAddedBody();
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            BookmarksResourcePermissionChecker.RESOURCE_NAME);

    subscriptionSender.setClassName(entry.getModelClassName());
    subscriptionSender.setClassPK(entry.getEntryId());
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttributes("[$BOOKMARKS_ENTRY_STATUS_BY_USER_NAME$]", statusByUserName,
            "[$BOOKMARKS_ENTRY_URL$]", entryURL);
    subscriptionSender.setContextCreatorUserPrefix("BOOKMARKS_ENTRY");
    subscriptionSender.setCreatorUserId(entry.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    if (bodyLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    }

    if (subjectLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    }

    subscriptionSender.setMailId("bookmarks_entry", entry.getEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

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

    subscriptionSender.setNotificationType(notificationType);

    subscriptionSender.setPortletId(BookmarksPortletKeys.BOOKMARKS);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    BookmarksFolder folder = entry.getFolder();

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), ancestorFolderId);
        }
    }

    subscriptionSender.addPersistedSubscribers(BookmarksFolder.class.getName(), entry.getGroupId());

    subscriptionSender.addPersistedSubscribers(BookmarksEntry.class.getName(), entry.getEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.document.library.internal.service.SubscriptionDLAppHelperLocalServiceWrapper.java

License:Open Source License

protected void notifySubscribers(long userId, FileVersion fileVersion, String entryURL,
        ServiceContext serviceContext) throws PortalException {

    if (!fileVersion.isApproved() || Validator.isNull(entryURL)) {
        return;//from  w w w  .java  2  s .co  m
    }

    DLGroupServiceSettings dlGroupServiceSettings = DLGroupServiceSettings
            .getInstance(fileVersion.getGroupId());

    boolean commandUpdate = false;

    if (serviceContext.isCommandUpdate() || Constants.CHECKIN.equals(serviceContext.getCommand())) {

        commandUpdate = true;
    }

    if (serviceContext.isCommandAdd() && dlGroupServiceSettings.isEmailFileEntryAddedEnabled()) {
    } else if (commandUpdate && dlGroupServiceSettings.isEmailFileEntryUpdatedEnabled()) {
    } else {
        return;
    }

    String entryTitle = fileVersion.getTitle();

    String fromName = dlGroupServiceSettings.getEmailFromName();
    String fromAddress = dlGroupServiceSettings.getEmailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (commandUpdate) {
        subjectLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryUpdatedSubject();
        bodyLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryAddedSubject();
        bodyLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryAddedBody();
    }

    FileEntry fileEntry = fileVersion.getFileEntry();

    Folder folder = null;

    long folderId = fileEntry.getFolderId();

    if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        folder = _dlAppLocalService.getFolder(folderId);
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            DLPermission.RESOURCE_NAME);

    DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

    DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService
            .getDLFileEntryType(dlFileEntry.getFileEntryTypeId());

    subscriptionSender.setClassPK(fileVersion.getFileEntryId());
    subscriptionSender.setClassName(DLFileEntryConstants.getClassName());
    subscriptionSender.setCompanyId(fileVersion.getCompanyId());

    if (folder != null) {
        subscriptionSender.setContextAttribute("[$FOLDER_NAME$]", folder.getName(), true);
    } else {
        subscriptionSender.setLocalizedContextAttribute("[$FOLDER_NAME$]",
                new EscapableLocalizableFunction(locale -> LanguageUtil.get(locale, "home")));
    }

    subscriptionSender.setContextAttributes("[$DOCUMENT_STATUS_BY_USER_NAME$]",
            fileVersion.getStatusByUserName(), "[$DOCUMENT_TITLE$]", entryTitle, "[$DOCUMENT_URL$]", entryURL);
    subscriptionSender.setContextCreatorUserPrefix("DOCUMENT");
    subscriptionSender.setCreatorUserId(fileVersion.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    subscriptionSender.setLocalizedContextAttribute("[$DOCUMENT_TYPE$]",
            new EscapableLocalizableFunction(locale -> dlFileEntryType.getName(locale)));
    subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    subscriptionSender.setMailId("file_entry", fileVersion.getFileEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (commandUpdate) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

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

    subscriptionSender.setPortletId(portletId);

    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(fileVersion.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), fileVersion.getGroupId());

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), ancestorFolderId);
        }
    }

    if (dlFileEntryType.getFileEntryTypeId() == DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {

        subscriptionSender.addPersistedSubscribers(DLFileEntryType.class.getName(), fileVersion.getGroupId());
    } else {
        subscriptionSender.addPersistedSubscribers(DLFileEntryType.class.getName(),
                dlFileEntryType.getFileEntryTypeId());
    }

    subscriptionSender.addPersistedSubscribers(DLFileEntry.class.getName(), fileEntry.getFileEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, JournalArticle article, String action,
        ServiceContext serviceContext) throws PortalException {

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

    String articleURL = PortalUtil.getControlPanelFullURL(article.getGroupId(), portletId, null);

    if (!article.isApproved() || Validator.isNull(articleURL)) {
        return;/*from   ww  w  .j a  v  a 2 s . co m*/
    }

    JournalGroupServiceConfiguration journalGroupServiceConfiguration = getJournalGroupServiceConfiguration(
            article.getGroupId());

    String articleTitle = article.getTitle(serviceContext.getLanguageId());

    articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(),
            article.getArticleId());

    if (action.equals("add") && journalGroupServiceConfiguration.emailArticleAddedEnabled()) {
    } else if (action.equals("move_to")
            && journalGroupServiceConfiguration.emailArticleMovedToFolderEnabled()) {
    } else if (action.equals("move_from")
            && journalGroupServiceConfiguration.emailArticleMovedFromFolderEnabled()) {
    } else if (action.equals("update") && journalGroupServiceConfiguration.emailArticleUpdatedEnabled()) {
    } else {
        return;
    }

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

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

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (action.equals("add")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleAddedSubject());
        localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleAddedBody());
    } else if (action.equals("move_to")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderBody());

        notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_TO_FOLDER;
    } else if (action.equals("move_from")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderBody());

        notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_FROM_FOLDER;
    } else if (action.equals("update")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleUpdatedSubject());
        localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleUpdatedBody());

        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    String articleContent = StringPool.BLANK;
    String articleDiffs = StringPool.BLANK;

    JournalArticle previousApprovedArticle = getPreviousApprovedArticle(article);

    try {
        PortletRequestModel portletRequestModel = new PortletRequestModel(
                serviceContext.getLiferayPortletRequest(), serviceContext.getLiferayPortletResponse());

        JournalArticleDisplay articleDisplay = getArticleDisplay(article, null, Constants.VIEW,
                LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), 1, portletRequestModel,
                serviceContext.getThemeDisplay());

        articleContent = articleDisplay.getContent();

        articleDiffs = JournalUtil.diffHtml(article.getGroupId(), article.getArticleId(),
                previousApprovedArticle.getVersion(), article.getVersion(),
                LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), portletRequestModel,
                serviceContext.getThemeDisplay());
    } catch (Exception e) {
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            JournalPermission.RESOURCE_NAME);

    subscriptionSender.setClassName(article.getModelClassName());
    subscriptionSender.setClassPK(article.getId());
    subscriptionSender.setCompanyId(article.getCompanyId());
    subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT$]", articleContent, false);
    subscriptionSender.setContextAttribute("[$ARTICLE_DIFFS$]", DiffHtmlUtil.replaceStyles(articleDiffs),
            false);

    JournalFolder folder = article.getFolder();

    subscriptionSender.setContextAttributes("[$ARTICLE_ID$]", article.getArticleId(), "[$ARTICLE_TITLE$]",
            articleTitle, "[$ARTICLE_URL$]", articleURL, "[$ARTICLE_VERSION$]", article.getVersion(),
            "[$FOLDER_NAME$]", folder.getName());

    subscriptionSender.setContextCreatorUserPrefix("ARTICLE");
    subscriptionSender.setCreatorUserId(article.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(articleTitle);
    subscriptionSender.setEntryURL(articleURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(localizedBodyMap);
    subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap);
    subscriptionSender.setMailId("journal_article", article.getId());
    subscriptionSender.setNotificationType(notificationType);
    subscriptionSender.setPortletId(portletId);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(article.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), article.getGroupId());

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), ancestorFolderId);
        }
    }

    DDMStructure ddmStructure = ddmStructureLocalService.getStructure(article.getGroupId(),
            classNameLocalService.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true);

    subscriptionSender.addPersistedSubscribers(DDMStructure.class.getName(), ddmStructure.getStructureId());

    subscriptionSender.addPersistedSubscribers(JournalArticle.class.getName(), article.getResourcePrimKey());

    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());//from   www.  j  a v a 2  s . co  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.service.MentionsWikiPageServiceWrapper.java

License:Open Source License

protected void notifySubscribers(long userId, WikiPage page, String pageURL, ServiceContext serviceContext)
        throws PortalException {

    if (!page.isApproved() || Validator.isNull(pageURL)) {
        return;/* w w  w . j  a  v a 2  s  .  c o  m*/
    }

    WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = _configurationProvider
            .getConfiguration(WikiGroupServiceOverriddenConfiguration.class,
                    new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME));

    boolean update = false;

    if (page.getVersion() > WikiPageConstants.VERSION_DEFAULT) {
        update = true;
    }

    if (!update && wikiGroupServiceOverriddenConfiguration.emailPageAddedEnabled()) {
    } else if (update && wikiGroupServiceOverriddenConfiguration.emailPageUpdatedEnabled()) {
    } else {
        return;
    }

    String portalURL = serviceContext.getPortalURL();

    WikiPage previousVersionPage = getPreviousVersionPage(page);

    String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(serviceContext.getPathMain(),
            serviceContext.getPlid(), page.getNodeId(), page.getTitle());

    attachmentURLPrefix = portalURL + attachmentURLPrefix;

    String pageDiffs = StringPool.BLANK;

    try {
        pageDiffs = _wikiEngineRenderer.diffHtml(previousVersionPage, page, null, null, attachmentURLPrefix);
    } catch (Exception e) {
    }

    String pageContent = null;

    if (Objects.equals(page.getFormat(), "creole")) {
        pageContent = _wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix);
    } else {
        pageContent = page.getContent();
        pageContent = WikiUtil.processContent(pageContent);
    }

    String pageTitle = page.getTitle();

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

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (update) {
        subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedSubject();
        bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedBody();
    } else {
        subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedSubject();
        bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedBody();
    }

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setClassName(page.getModelClassName());
    subscriptionSender.setClassPK(page.getPageId());
    subscriptionSender.setCompanyId(page.getCompanyId());
    subscriptionSender.setContextAttribute("[$PAGE_CONTENT$]", pageContent, false);
    subscriptionSender.setContextAttribute("[$PAGE_DIFFS$]", DiffHtmlUtil.replaceStyles(pageDiffs), false);

    WikiNode node = page.getNode();

    subscriptionSender.setContextAttributes("[$DIFFS_URL$]",
            getDiffsURL(page, previousVersionPage, serviceContext), "[$NODE_NAME$]", node.getName(),
            "[$PAGE_DATE_UPDATE$]", page.getModifiedDate(), "[$PAGE_ID$]", page.getPageId(), "[$PAGE_SUMMARY$]",
            page.getSummary(), "[$PAGE_TITLE$]", pageTitle, "[$PAGE_URL$]", pageURL);

    subscriptionSender.setContextCreatorUserPrefix("PAGE");
    subscriptionSender.setCreatorUserId(page.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(pageTitle);
    subscriptionSender.setEntryURL(pageURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    if (bodyLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    }

    if (subjectLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    }

    subscriptionSender.setMailId("wiki_page", page.getNodeId(), page.getPageId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (update) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    subscriptionSender.setPortletId(WikiPortletKeys.WIKI);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(page.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(User.class.getName(), userId);

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

From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, WikiPage page, String pageURL, ServiceContext serviceContext)
        throws PortalException {

    if (!page.isApproved() || Validator.isNull(pageURL)) {
        return;/*from   w  w  w.  j  a va 2  s  .  c  om*/
    }

    WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = configurationProvider
            .getConfiguration(WikiGroupServiceOverriddenConfiguration.class,
                    new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME));

    boolean update = false;

    if (page.getVersion() > WikiPageConstants.VERSION_DEFAULT) {
        update = true;
    }

    if (!update && wikiGroupServiceOverriddenConfiguration.emailPageAddedEnabled()) {
    } else if (update && wikiGroupServiceOverriddenConfiguration.emailPageUpdatedEnabled()) {
    } else {
        return;
    }

    String portalURL = serviceContext.getPortalURL();

    WikiPage previousVersionPage = getPreviousVersionPage(page);

    String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(serviceContext.getPathMain(),
            serviceContext.getPlid(), page.getNodeId(), page.getTitle());

    attachmentURLPrefix = portalURL + attachmentURLPrefix;

    String pageDiffs = StringPool.BLANK;

    try {
        pageDiffs = wikiEngineRenderer.diffHtml(previousVersionPage, page, null, null, attachmentURLPrefix);
    } catch (Exception e) {
    }

    String pageContent = null;

    if (Objects.equals(page.getFormat(), "creole")) {
        pageContent = wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix);
    } else {
        pageContent = page.getContent();
        pageContent = WikiUtil.processContent(pageContent);
    }

    String pageTitle = page.getTitle();

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

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (update) {
        subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedSubject();
        bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedBody();
    } else {
        subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedSubject();
        bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedBody();
    }

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setClassName(page.getModelClassName());
    subscriptionSender.setClassPK(page.getPageId());
    subscriptionSender.setCompanyId(page.getCompanyId());
    subscriptionSender.setContextAttribute("[$PAGE_CONTENT$]", pageContent, false);
    subscriptionSender.setContextAttribute("[$PAGE_DIFFS$]", DiffHtmlUtil.replaceStyles(pageDiffs), false);

    WikiNode node = page.getNode();

    subscriptionSender.setContextAttributes("[$DIFFS_URL$]",
            getDiffsURL(page, previousVersionPage, serviceContext), "[$NODE_NAME$]", node.getName(),
            "[$PAGE_DATE_UPDATE$]", page.getModifiedDate(), "[$PAGE_ID$]", page.getPageId(), "[$PAGE_SUMMARY$]",
            page.getSummary(), "[$PAGE_TITLE$]", pageTitle, "[$PAGE_URL$]", pageURL);

    subscriptionSender.setContextCreatorUserPrefix("PAGE");
    subscriptionSender.setCreatorUserId(page.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(pageTitle);
    subscriptionSender.setEntryURL(pageURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    if (bodyLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    }

    if (subjectLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    }

    subscriptionSender.setMailId("wiki_page", page.getNodeId(), page.getPageId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (update) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    subscriptionSender.setPortletId(WikiPortletKeys.WIKI);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(page.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(WikiNode.class.getName(), page.getNodeId());

    subscriptionSender.addPersistedSubscribers(WikiPage.class.getName(), page.getResourcePrimKey());

    subscriptionSender.flushNotificationsAsync();
}