Beispiel #1
0
  protected String getLink(SocialActivity activity, ServiceContext serviceContext)
      throws Exception {

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(activity.getClassName());

    long classPK = activity.getClassPK();

    if ((trashHandler != null)
        && (trashHandler.isInTrash(classPK) || trashHandler.isInTrashContainer(classPK))) {

      PortletURL portletURL =
          TrashUtil.getViewContentURL(
              serviceContext.getRequest(), activity.getClassName(), classPK);

      if (portletURL == null) {
        return null;
      }

      return portletURL.toString();
    }

    String path = getPath(activity, serviceContext);

    if (Validator.isNull(path)) {
      return null;
    }

    if (!path.startsWith(StringPool.SLASH)) {
      return path;
    }

    return serviceContext.getPortalURL() + serviceContext.getPathMain() + path;
  }
  @Override
  protected String getBody(SocialActivity activity, ServiceContext serviceContext)
      throws Exception {

    MBMessage message = getMessage(activity);

    if (message.getCategoryId() <= 0) {
      return StringPool.BLANK;
    }

    StringBundler sb = new StringBundler(4);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/message_boards/find_category?mbCategoryId=");
    sb.append(message.getCategoryId());

    String categoryLink = sb.toString();

    categoryLink =
        addNoSuchEntryRedirect(
            categoryLink, MBCategory.class.getName(), message.getCategoryId(), serviceContext);

    return wrapLink(categoryLink, "go-to-category", serviceContext);
  }
Beispiel #3
0
  protected String getGroupName(long groupId, ServiceContext serviceContext) {
    try {
      if (groupId <= 0) {
        return StringPool.BLANK;
      }

      Group group = GroupLocalServiceUtil.getGroup(groupId);

      String groupName = group.getDescriptiveName();

      if (group.getGroupId() == serviceContext.getScopeGroupId()) {
        return HtmlUtil.escape(groupName);
      }

      String groupDisplayURL =
          serviceContext.getPortalURL()
              + serviceContext.getPathMain()
              + "/my_sites/view?groupId="
              + group.getGroupId();

      if (group.hasPublicLayouts()) {
        groupDisplayURL = groupDisplayURL + "&privateLayout=0";
      } else if (group.hasPrivateLayouts()) {
        groupDisplayURL = groupDisplayURL + "&privateLayout=1";
      } else {
        return HtmlUtil.escape(groupName);
      }

      groupName =
          "<a class=\"group\" href=\""
              + groupDisplayURL
              + "\">"
              + HtmlUtil.escape(groupName)
              + "</a>";

      return groupName;
    } catch (Exception e) {
      return StringPool.BLANK;
    }
  }
  @Override
  protected String getLink(SocialActivity activity, ServiceContext serviceContext)
      throws Exception {

    StringBundler sb = new StringBundler(8);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/document_library/get_file?groupId=");

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(activity.getClassPK());

    sb.append(fileEntry.getRepositoryId());

    sb.append("&folderId=");
    sb.append(fileEntry.getFolderId());
    sb.append("&title=");
    sb.append(HttpUtil.encodeURL(fileEntry.getTitle()));

    String downloadLink = wrapLink(sb.toString(), serviceContext.translate("download"));

    return "<span>" + downloadLink + "</span>";
  }
  protected String getFolderLink(long classPK, ServiceContext serviceContext) throws Exception {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    if (fileEntry.getFolderId() <= 0) {
      return null;
    }

    StringBundler sb = new StringBundler(6);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/document_library/find_folder?groupId=");
    sb.append(fileEntry.getRepositoryId());
    sb.append("&folderId=");
    sb.append(fileEntry.getFolderId());

    Folder folder = fileEntry.getFolder();

    String folderName = HtmlUtil.escape(folder.getName());

    return wrapLink(sb.toString(), folderName);
  }
  protected void notifySubscribers(KBArticle kbArticle, ServiceContext serviceContext)
      throws PortalException, SystemException {

    if (Validator.isNull(serviceContext.getLayoutFullURL())) {
      return;
    }

    PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

    if (preferences == null) {
      long ownerId = kbArticle.getGroupId();
      int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
      long plid = PortletKeys.PREFS_PLID_SHARED;
      String portletId = PortletKeys.KNOWLEDGE_BASE_ADMIN;
      String defaultPreferences = null;

      preferences =
          portletPreferencesLocalService.getPreferences(
              kbArticle.getCompanyId(), ownerId, ownerType, plid, portletId, defaultPreferences);
    }

    if (serviceContext.isCommandAdd() && !AdminUtil.getEmailKBArticleAddedEnabled(preferences)) {

      return;
    }

    if (serviceContext.isCommandUpdate()
        && !AdminUtil.getEmailKBArticleUpdatedEnabled(preferences)) {

      return;
    }

    String fromName = AdminUtil.getEmailFromName(preferences);
    String fromAddress = AdminUtil.getEmailFromAddress(preferences);

    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.getEmailKBArticleUpdatedBody(preferences);
    } else {
      subject = AdminUtil.getEmailKBArticleUpdatedSubject(preferences);
      body = AdminUtil.getEmailKBArticleUpdatedBody(preferences);
    }

    SubscriptionSender subscriptionSender = new AdminSubscriptionSender(kbArticle, serviceContext);

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(kbArticle.getCompanyId());
    subscriptionSender.setContextAttributes(
        "[$ARTICLE_CONTENT$]",
        kbArticleContent,
        "[$ARTICLE_CONTENT_DIFF$]",
        kbArticleDiffs.get("content"),
        "[$ARTICLE_TITLE$]",
        kbArticle.getTitle(),
        "[$ARTICLE_TITLE_DIFF$]",
        kbArticleDiffs.get("title"));
    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 =
          getLatestKBArticle(
              kbArticle.getParentResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);

      subscriptionSender.addPersistedSubscribers(
          KBArticle.class.getName(), kbArticle.getResourcePrimKey());
    }

    subscriptionSender.flushNotificationsAsync();
  }
  protected void sendEmail(
      String emailAddress, MemberRequest memberRequest, ServiceContext serviceContext)
      throws Exception {

    long companyId = memberRequest.getCompanyId();

    Group group = groupLocalService.getGroup(memberRequest.getGroupId());

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

    User receiverUser = null;

    if (memberRequest.getReceiverUserId() > 0) {
      receiverUser = userLocalService.getUser(memberRequest.getReceiverUserId());
    }

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

    String toName = StringPool.BLANK;
    String toAddress = emailAddress;

    if (receiverUser != null) {
      toName = receiverUser.getFullName();
    }

    String subject =
        StringUtil.read(getClassLoader(), "com/liferay/so/invitemembers/dependencies/subject.tmpl");

    String body = StringPool.BLANK;

    if (memberRequest.getReceiverUserId() > 0) {
      body =
          StringUtil.read(
              getClassLoader(),
              "com/liferay/so/invitemembers/dependencies/" + "existing_user_body.tmpl");
    } else {
      body =
          StringUtil.read(
              getClassLoader(),
              "com/liferay/so/invitemembers/dependencies/" + "new_user_body.tmpl");
    }

    subject =
        StringUtil.replace(
            subject,
            new String[] {"[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_USER$]"},
            new String[] {
              group.getDescriptiveName(serviceContext.getLocale()), user.getFullName()
            });

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

    if (Validator.isNull(createAccountURL)) {
      createAccountURL = serviceContext.getPortalURL();
    }

    createAccountURL = HttpUtil.addParameter(createAccountURL, "key", memberRequest.getKey());

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

    if (Validator.isNull(loginURL)) {
      loginURL = serviceContext.getPortalURL();
    }

    loginURL = HttpUtil.addParameter(loginURL, "key", memberRequest.getKey());

    body =
        StringUtil.replace(
            body,
            new String[] {
              "[$ADMIN_ADDRESS$]",
              "[$ADMIN_NAME$]",
              "[$MEMBER_REQUEST_CREATE_ACCOUNT_URL$]",
              "[$MEMBER_REQUEST_GROUP$]",
              "[$MEMBER_REQUEST_LOGIN_URL$]",
              "[$MEMBER_REQUEST_USER$]"
            },
            new String[] {
              fromAddress,
              fromName,
              createAccountURL,
              group.getDescriptiveName(serviceContext.getLocale()),
              loginURL,
              user.getFullName()
            });

    InternetAddress from = new InternetAddress(fromAddress, fromName);

    InternetAddress to = new InternetAddress(toAddress, toName);

    MailMessage mailMessage = new MailMessage(from, to, subject, body, true);

    MailServiceUtil.sendEmail(mailMessage);
  }
  public void merge(ServiceContext serviceContext) {
    setAddGroupPermissions(serviceContext.isAddGroupPermissions());
    setAddGuestPermissions(serviceContext.isAddGuestPermissions());

    if (serviceContext.getAssetCategoryIds() != null) {
      setAssetCategoryIds(serviceContext.getAssetCategoryIds());
    }

    if (serviceContext.getAssetLinkEntryIds() != null) {
      setAssetLinkEntryIds(serviceContext.getAssetLinkEntryIds());
    }

    if (serviceContext.getAssetTagNames() != null) {
      setAssetTagNames(serviceContext.getAssetTagNames());
    }

    if (serviceContext.getAttributes() != null) {
      setAttributes(serviceContext.getAttributes());
    }

    if (Validator.isNotNull(serviceContext.getCommand())) {
      setCommand(serviceContext.getCommand());
    }

    if (serviceContext.getCompanyId() > 0) {
      setCompanyId(serviceContext.getCompanyId());
    }

    if (serviceContext.getCreateDate() != null) {
      setCreateDate(serviceContext.getCreateDate());
    }

    if (Validator.isNotNull(serviceContext.getCurrentURL())) {
      setCurrentURL(serviceContext.getCurrentURL());
    }

    if (serviceContext.getExpandoBridgeAttributes() != null) {
      setExpandoBridgeAttributes(serviceContext.getExpandoBridgeAttributes());
    }

    if (serviceContext.getGroupPermissions() != null) {
      setGroupPermissions(serviceContext.getGroupPermissions());
    }

    if (serviceContext.getGuestPermissions() != null) {
      setGuestPermissions(serviceContext.getGuestPermissions());
    }

    if (serviceContext.getHeaders() != null) {
      setHeaders(serviceContext.getHeaders());
    }

    setFailOnPortalException(serviceContext.isFailOnPortalException());
    setLanguageId(serviceContext.getLanguageId());

    if (Validator.isNotNull(serviceContext.getLayoutFullURL())) {
      setLayoutFullURL(serviceContext.getLayoutFullURL());
    }

    if (Validator.isNotNull(serviceContext.getLayoutURL())) {
      setLayoutURL(serviceContext.getLayoutURL());
    }

    if (serviceContext.getModifiedDate() != null) {
      setModifiedDate(serviceContext.getModifiedDate());
    }

    if (Validator.isNotNull(serviceContext.getPathMain())) {
      setPathMain(serviceContext.getPathMain());
    }

    if (serviceContext.getPlid() > 0) {
      setPlid(serviceContext.getPlid());
    }

    if (Validator.isNotNull(serviceContext.getPortalURL())) {
      setPortalURL(serviceContext.getPortalURL());
    }

    if (serviceContext.getPortletPreferencesIds() != null) {
      setPortletPreferencesIds(serviceContext.getPortletPreferencesIds());
    }

    if (Validator.isNotNull(serviceContext.getRemoteAddr())) {
      setRemoteAddr(serviceContext.getRemoteAddr());
    }

    if (Validator.isNotNull(serviceContext.getRemoteHost())) {
      setRemoteHost(serviceContext.getRemoteHost());
    }

    if (serviceContext.getScopeGroupId() > 0) {
      setScopeGroupId(serviceContext.getScopeGroupId());
    }

    setSignedIn(serviceContext.isSignedIn());

    if (Validator.isNotNull(serviceContext.getUserDisplayURL())) {
      setUserDisplayURL(serviceContext.getUserDisplayURL());
    }

    if (serviceContext.getUserId() > 0) {
      setUserId(serviceContext.getUserId());
    }

    if (Validator.isNotNull(serviceContext.getUuid())) {
      setUuid(serviceContext.getUuid());
    }

    if (serviceContext.getWorkflowAction() > 0) {
      setWorkflowAction(serviceContext.getWorkflowAction());
    }
  }
  protected void notifySubscribers(KBComment kbComment, ServiceContext serviceContext)
      throws PortalException {

    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("[$ARTICLE_TITLE$]", kbArticle.getTitle(), false);
    subscriptionSender.setContextAttribute("[$COMMENT_CONTENT$]", kbComment.getContent(), 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();
  }