コード例 #1
0
ファイル: MBUtil.java プロジェクト: xyang2005/liferay-portal
  public static String[] getThreadPriority(
      MBGroupServiceSettings mbGroupServiceSettings,
      String languageId,
      double value,
      ThemeDisplay themeDisplay)
      throws Exception {

    String[] priorities = mbGroupServiceSettings.getPriorities(languageId);

    String[] priorityPair = _findThreadPriority(value, themeDisplay, priorities);

    if (priorityPair == null) {
      String defaultLanguageId = LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault());

      priorities = mbGroupServiceSettings.getPriorities(defaultLanguageId);

      priorityPair = _findThreadPriority(value, themeDisplay, priorities);
    }

    return priorityPair;
  }
コード例 #2
0
ファイル: MBUtil.java プロジェクト: xyang2005/liferay-portal
  public static String[] getUserRank(
      MBGroupServiceSettings mbGroupServiceSettings, String languageId, MBStatsUser statsUser)
      throws Exception {

    String[] rank = {StringPool.BLANK, StringPool.BLANK};

    int maxPosts = 0;

    Group group = GroupLocalServiceUtil.getGroup(statsUser.getGroupId());

    long companyId = group.getCompanyId();

    String[] ranks = mbGroupServiceSettings.getRanks(languageId);

    for (int i = 0; i < ranks.length; i++) {
      String[] kvp = StringUtil.split(ranks[i], CharPool.EQUAL);

      String curRank = kvp[0];
      String curRankValue = kvp[1];

      String[] curRankValueKvp = StringUtil.split(curRankValue, CharPool.COLON);

      if (curRankValueKvp.length <= 1) {
        int posts = GetterUtil.getInteger(curRankValue);

        if ((posts <= statsUser.getMessageCount()) && (posts >= maxPosts)) {

          rank[0] = curRank;
          maxPosts = posts;
        }
      } else {
        String entityType = curRankValueKvp[0];
        String entityValue = curRankValueKvp[1];

        try {
          if (_isEntityRank(companyId, statsUser, entityType, entityValue)) {

            rank[1] = curRank;

            break;
          }
        } catch (Exception e) {
          if (_log.isWarnEnabled()) {
            _log.warn(e);
          }
        }
      }
    }

    return rank;
  }
コード例 #3
0
ファイル: MBUtil.java プロジェクト: xyang2005/liferay-portal
  public static String getUserRank(
      MBGroupServiceSettings mbGroupServiceSettings, String languageId, int posts)
      throws Exception {

    String rank = StringPool.BLANK;

    String[] ranks = mbGroupServiceSettings.getRanks(languageId);

    for (int i = 0; i < ranks.length; i++) {
      String[] kvp = StringUtil.split(ranks[i], CharPool.EQUAL);

      String kvpName = kvp[0];
      int kvpPosts = GetterUtil.getInteger(kvp[1]);

      if (posts >= kvpPosts) {
        rank = kvpName;
      } else {
        break;
      }
    }

    return rank;
  }
コード例 #4
0
  protected MBMessage updateMessage(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long messageId = ParamUtil.getLong(actionRequest, "messageId");

    long groupId = themeDisplay.getScopeGroupId();
    long categoryId = ParamUtil.getLong(actionRequest, "mbCategoryId");
    long threadId = ParamUtil.getLong(actionRequest, "threadId");
    long parentMessageId = ParamUtil.getLong(actionRequest, "parentMessageId");
    String subject = ParamUtil.getString(actionRequest, "subject");
    String body = ParamUtil.getString(actionRequest, "body");

    MBGroupServiceSettings mbGroupServiceSettings = MBGroupServiceSettings.getInstance(groupId);

    List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<>(5);

    try {
      UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

      for (int i = 1; i <= 5; i++) {
        String fileName = uploadPortletRequest.getFileName("msgFile" + i);
        InputStream inputStream = uploadPortletRequest.getFileAsStream("msgFile" + i);

        if ((inputStream == null) || Validator.isNull(fileName)) {
          continue;
        }

        ObjectValuePair<String, InputStream> inputStreamOVP =
            new ObjectValuePair<>(fileName, inputStream);

        inputStreamOVPs.add(inputStreamOVP);
      }

      boolean question = ParamUtil.getBoolean(actionRequest, "question");
      boolean anonymous = ParamUtil.getBoolean(actionRequest, "anonymous");
      double priority = ParamUtil.getDouble(actionRequest, "priority");
      boolean allowPingbacks = ParamUtil.getBoolean(actionRequest, "allowPingbacks");

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(MBMessage.class.getName(), actionRequest);

      boolean preview = ParamUtil.getBoolean(actionRequest, "preview");

      serviceContext.setAttribute("preview", preview);

      MBMessage message = null;

      if (messageId <= 0) {
        if (PropsValues.CAPTCHA_CHECK_PORTLET_MESSAGE_BOARDS_EDIT_MESSAGE) {

          CaptchaUtil.check(actionRequest);
        }

        if (threadId <= 0) {

          // Post new thread

          message =
              _mbMessageService.addMessage(
                  groupId,
                  categoryId,
                  subject,
                  body,
                  mbGroupServiceSettings.getMessageFormat(),
                  inputStreamOVPs,
                  anonymous,
                  priority,
                  allowPingbacks,
                  serviceContext);

          if (question) {
            _mbThreadLocalService.updateQuestion(message.getThreadId(), true);
          }
        } else {

          // Post reply

          message =
              _mbMessageService.addMessage(
                  parentMessageId,
                  subject,
                  body,
                  mbGroupServiceSettings.getMessageFormat(),
                  inputStreamOVPs,
                  anonymous,
                  priority,
                  allowPingbacks,
                  serviceContext);
        }
      } else {
        List<String> existingFiles = new ArrayList<>();

        for (int i = 1; i <= 5; i++) {
          String path = ParamUtil.getString(actionRequest, "existingPath" + i);

          if (Validator.isNotNull(path)) {
            existingFiles.add(path);
          }
        }

        // Update message

        message =
            _mbMessageService.updateMessage(
                messageId,
                subject,
                body,
                inputStreamOVPs,
                existingFiles,
                priority,
                allowPingbacks,
                serviceContext);

        if (message.isRoot()) {
          _mbThreadLocalService.updateQuestion(message.getThreadId(), question);
        }
      }

      PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

      boolean subscribe = ParamUtil.getBoolean(actionRequest, "subscribe");

      if (!preview
          && subscribe
          && MBMessagePermission.contains(permissionChecker, message, ActionKeys.SUBSCRIBE)) {

        _mbMessageService.subscribeMessage(message.getMessageId());
      }

      return message;
    } finally {
      for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) {

        InputStream inputStream = inputStreamOVP.getValue();

        StreamUtil.cleanUp(inputStream);
      }
    }
  }