@Override
  public MBStatsUser addStatsUser(long groupId, long userId) {
    long statsUserId = counterLocalService.increment();

    MBStatsUser statsUser = mbStatsUserPersistence.create(statsUserId);

    statsUser.setGroupId(groupId);
    statsUser.setUserId(userId);

    try {
      mbStatsUserPersistence.update(statsUser);
    } catch (SystemException se) {
      if (_log.isWarnEnabled()) {
        _log.warn("Add failed, fetch {groupId=" + groupId + ", userId=" + userId + "}");
      }

      statsUser = mbStatsUserPersistence.fetchByG_U(groupId, userId, false);

      if (statsUser == null) {
        throw se;
      }
    }

    return statsUser;
  }
  public void updateStatsUser(long groupId, long userId) throws PortalException, SystemException {

    MBStatsUser statsUser = getStatsUser(groupId, userId);

    statsUser.setMessageCount(statsUser.getMessageCount() + 1);
    statsUser.setLastPostDate(new Date());

    mbStatsUserPersistence.update(statsUser);
  }
예제 #3
0
  public static String[] getUserRank(
      PortletPreferences preferences, 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 = LocalizationUtil.getPreferencesValues(preferences, "ranks", 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;
  }
  @Override
  public MBStatsUser updateStatsUser(
      long groupId, long userId, int messageCount, Date lastPostDate) {

    MBStatsUser statsUser = getStatsUser(groupId, userId);

    statsUser.setMessageCount(messageCount);

    if (lastPostDate != null) {
      statsUser.setLastPostDate(lastPostDate);
    }

    mbStatsUserPersistence.update(statsUser);

    return statsUser;
  }
  public MBStatsUser getStatsUser(long groupId, long userId)
      throws PortalException, SystemException {

    MBStatsUser statsUser = mbStatsUserPersistence.fetchByG_U(groupId, userId);

    if (statsUser == null) {
      long statsUserId = counterLocalService.increment();

      statsUser = mbStatsUserPersistence.create(statsUserId);

      statsUser.setGroupId(groupId);
      statsUser.setUserId(userId);

      mbStatsUserPersistence.update(statsUser);
    }

    return statsUser;
  }
예제 #6
0
  private static boolean _isEntityRank(
      long companyId, MBStatsUser statsUser, String entityType, String entityValue)
      throws Exception {

    long groupId = statsUser.getGroupId();
    long userId = statsUser.getUserId();

    if (entityType.equals("organization-role") || entityType.equals("site-role")) {

      Role role = RoleLocalServiceUtil.getRole(companyId, entityValue);

      if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(userId, groupId, role.getRoleId(), true)) {

        return true;
      }
    } else if (entityType.equals("organization")) {
      Organization organization =
          OrganizationLocalServiceUtil.getOrganization(companyId, entityValue);

      if (OrganizationLocalServiceUtil.hasUserOrganization(
          userId, organization.getOrganizationId(), false, false)) {

        return true;
      }
    } else if (entityType.equals("regular-role")) {
      if (RoleLocalServiceUtil.hasUserRole(userId, companyId, entityValue, true)) {

        return true;
      }
    } else if (entityType.equals("user-group")) {
      UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, entityValue);

      if (UserLocalServiceUtil.hasUserGroupUser(userGroup.getUserGroupId(), userId)) {

        return true;
      }
    }

    return false;
  }
  protected int getStatsUserMessageCount() throws Exception {
    MBStatsUser statsUser =
        MBStatsUserLocalServiceUtil.getStatsUser(_group.getGroupId(), TestPropsValues.getUserId());

    return statsUser.getMessageCount();
  }