Search in sources :

Example 1 with AdminSubscriptionSender

use of com.liferay.knowledgebase.admin.util.AdminSubscriptionSender in project liferay-ide by liferay.

the class KBArticleLocalServiceImpl method notifySubscribers.

protected void notifySubscribers(KBArticle kbArticle, ServiceContext serviceContext) throws PortalException, SystemException {
    if (Validator.isNull(serviceContext.getLayoutFullURL())) {
        return;
    }
    PortletPreferences preferences = portletPreferencesLocalService.getPreferences(kbArticle.getCompanyId(), kbArticle.getGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, PortletKeys.PREFS_PLID_SHARED, PortletKeys.KNOWLEDGE_BASE_ADMIN, null);
    if (serviceContext.isCommandAdd() && !AdminUtil.getEmailKBArticleAddedEnabled(preferences)) {
        return;
    }
    if (serviceContext.isCommandUpdate() && !AdminUtil.getEmailKBArticleUpdatedEnabled(preferences)) {
        return;
    }
    String fromName = AdminUtil.getEmailFromName(preferences, kbArticle.getCompanyId());
    String fromAddress = AdminUtil.getEmailFromAddress(preferences, kbArticle.getCompanyId());
    String kbArticleContent = StringUtil.replace(kbArticle.getContent(), new String[] { "href=\"/", "src=\"/" }, new String[] { "href=\"" + serviceContext.getPortalURL() + "/", "src=\"" + serviceContext.getPortalURL() + "/" });
    Map<String, String> kbArticleDiffs = getEmailKBArticleDiffs(kbArticle);
    for (String key : kbArticleDiffs.keySet()) {
        String value = StringUtil.replace(kbArticleDiffs.get(key), new String[] { "href=\"/", "src=\"/" }, new String[] { "href=\"" + serviceContext.getPortalURL() + "/", "src=\"" + serviceContext.getPortalURL() + "/" });
        kbArticleDiffs.put(key, value);
    }
    String subject = null;
    String body = null;
    if (serviceContext.isCommandAdd()) {
        subject = AdminUtil.getEmailKBArticleAddedSubject(preferences);
        body = AdminUtil.getEmailKBArticleAddedBody(preferences);
    } else {
        subject = AdminUtil.getEmailKBArticleUpdatedSubject(preferences);
        body = AdminUtil.getEmailKBArticleUpdatedBody(preferences);
    }
    SubscriptionSender subscriptionSender = new AdminSubscriptionSender(kbArticle, serviceContext);
    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(kbArticle.getCompanyId());
    subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT$]", kbArticleContent, false);
    subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT_DIFF$]", kbArticleDiffs.get("content"), false);
    subscriptionSender.setContextAttribute("[$ARTICLE_TITLE$]", kbArticle.getTitle(), false);
    subscriptionSender.setContextAttribute("[$ARTICLE_TITLE_DIFF$]", kbArticleDiffs.get("title"), false);
    subscriptionSender.setContextUserPrefix("ARTICLE");
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("kb_article", kbArticle.getKbArticleId());
    subscriptionSender.setPortletId(serviceContext.getPortletId());
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(kbArticle.getGroupId());
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(kbArticle.getUserId());
    subscriptionSender.addPersistedSubscribers(KBArticle.class.getName(), kbArticle.getGroupId());
    subscriptionSender.addPersistedSubscribers(KBArticle.class.getName(), kbArticle.getResourcePrimKey());
    while (!kbArticle.isRoot() && (kbArticle.getClassNameId() == kbArticle.getParentResourceClassNameId())) {
        kbArticle = getLatestKBArticle(kbArticle.getParentResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
        subscriptionSender.addPersistedSubscribers(KBArticle.class.getName(), kbArticle.getResourcePrimKey());
    }
    subscriptionSender.flushNotificationsAsync();
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) AdminSubscriptionSender(com.liferay.knowledgebase.admin.util.AdminSubscriptionSender) PortletPreferences(javax.portlet.PortletPreferences) AdminSubscriptionSender(com.liferay.knowledgebase.admin.util.AdminSubscriptionSender) SubscriptionSender(com.liferay.portal.util.SubscriptionSender)

Example 2 with AdminSubscriptionSender

use of com.liferay.knowledgebase.admin.util.AdminSubscriptionSender in project liferay-ide by liferay.

the class KBCommentLocalServiceImpl method notifySubscribers.

protected void notifySubscribers(KBComment kbComment, ServiceContext serviceContext) throws PortalException, SystemException {
    PortletPreferences preferences = portletPreferencesLocalService.getPreferences(kbComment.getCompanyId(), kbComment.getGroupId(), PortletKeys.PREFS_OWNER_TYPE_GROUP, PortletKeys.PREFS_PLID_SHARED, PortletKeys.KNOWLEDGE_BASE_ADMIN, null);
    if (!AdminUtil.isSuggestionStatusChangeNotificationEnabled(kbComment.getStatus(), preferences)) {
        return;
    }
    String fromName = AdminUtil.getEmailFromName(preferences, serviceContext.getCompanyId());
    String fromAddress = AdminUtil.getEmailFromAddress(preferences, kbComment.getCompanyId());
    String subject = AdminUtil.getEmailKBArticleSuggestionNotificationSubject(kbComment.getStatus(), preferences);
    String body = AdminUtil.getEmailKBArticleSuggestionNotificationBody(kbComment.getStatus(), preferences);
    KBArticle kbArticle = kbArticleLocalService.getLatestKBArticle(kbComment.getClassPK(), WorkflowConstants.STATUS_APPROVED);
    String kbArticleContent = StringUtil.replace(kbArticle.getContent(), new String[] { "href=\"/", "src=\"/" }, new String[] { "href=\"" + serviceContext.getPortalURL() + "/", "src=\"" + serviceContext.getPortalURL() + "/" });
    SubscriptionSender subscriptionSender = new AdminSubscriptionSender(kbArticle, serviceContext);
    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(kbArticle.getCompanyId());
    subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT$]", kbArticleContent, false);
    subscriptionSender.setContextAttribute("[$COMMENT_CONTENT$]", kbComment.getContent(), false);
    subscriptionSender.setContextAttribute("[$COMMENT_CREATE_DATE$]", getFormattedKBCommentCreateDate(kbComment, serviceContext), false);
    subscriptionSender.setContextUserPrefix("ARTICLE");
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("kb_article", kbArticle.getKbArticleId());
    subscriptionSender.setPortletId(serviceContext.getPortletId());
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(kbArticle.getGroupId());
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(kbArticle.getUserId());
    User user = userLocalService.getUser(kbComment.getUserId());
    subscriptionSender.addRuntimeSubscribers(user.getEmailAddress(), user.getFullName());
    subscriptionSender.flushNotificationsAsync();
}
Also used : User(com.liferay.portal.model.User) KBArticle(com.liferay.knowledgebase.model.KBArticle) AdminSubscriptionSender(com.liferay.knowledgebase.admin.util.AdminSubscriptionSender) PortletPreferences(javax.portlet.PortletPreferences) AdminSubscriptionSender(com.liferay.knowledgebase.admin.util.AdminSubscriptionSender) SubscriptionSender(com.liferay.portal.util.SubscriptionSender)

Aggregations

AdminSubscriptionSender (com.liferay.knowledgebase.admin.util.AdminSubscriptionSender)2 KBArticle (com.liferay.knowledgebase.model.KBArticle)2 SubscriptionSender (com.liferay.portal.util.SubscriptionSender)2 PortletPreferences (javax.portlet.PortletPreferences)2 User (com.liferay.portal.model.User)1