/**
   * Adds the social activity limit to the database. Also notifies the appropriate model listeners.
   *
   * @param socialActivityLimit the social activity limit
   * @return the social activity limit that was added
   * @throws SystemException if a system exception occurred
   */
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public SocialActivityLimit addSocialActivityLimit(SocialActivityLimit socialActivityLimit)
      throws SystemException {
    socialActivityLimit.setNew(true);

    return socialActivityLimitPersistence.update(socialActivityLimit);
  }
  protected boolean checkActivityLimit(
      User user, SocialActivity activity, SocialActivityCounterDefinition activityCounterDefinition)
      throws PortalException {

    if (activityCounterDefinition.getLimitValue() == 0) {
      return true;
    }

    long classPK = activity.getClassPK();

    String name = activityCounterDefinition.getName();

    if (name.equals(SocialActivityCounterConstants.NAME_PARTICIPATION)) {
      classPK = 0;
    }

    SocialActivityLimit activityLimit =
        socialActivityLimitPersistence.findByG_U_C_C_A_A(
            activity.getGroupId(),
            user.getUserId(),
            activity.getClassNameId(),
            classPK,
            activity.getType(),
            name);

    int count = activityLimit.getCount(activityCounterDefinition.getLimitPeriod());

    if (count < activityCounterDefinition.getLimitValue()) {
      activityLimit.setCount(activityCounterDefinition.getLimitPeriod(), count + 1);

      socialActivityLimitPersistence.update(activityLimit);

      return true;
    }

    return false;
  }