/**
   * Removes the stored activity and its mirror activity from the database.
   *
   * @param activity the activity to be removed
   * @throws SystemException if a system exception occurred
   */
  public void deleteActivity(SocialActivity activity) throws SystemException {
    socialActivityPersistence.remove(activity);

    try {
      socialActivityPersistence.removeByMirrorActivityId(activity.getActivityId());
    } catch (NoSuchActivityException nsae) {
    }
  }
  @Async
  @Override
  public void addActivity(SocialActivity activity, SocialActivity mirrorActivity)
      throws PortalException {

    if (ExportImportThreadLocal.isImportInProcess()) {
      return;
    }

    if ((activity.getActivityId() > 0)
        || ((mirrorActivity != null) && (mirrorActivity.getActivityId() > 0))) {

      throw new PortalException("Activity and mirror activity must not have primary keys set");
    }

    if (isLogActivity(activity)) {
      long activityId = counterLocalService.increment(SocialActivity.class.getName());

      activity.setActivityId(activityId);

      socialActivityPersistence.update(activity);

      if (mirrorActivity != null) {
        long mirrorActivityId = counterLocalService.increment(SocialActivity.class.getName());

        mirrorActivity.setActivityId(mirrorActivityId);
        mirrorActivity.setMirrorActivityId(activity.getPrimaryKey());

        socialActivityPersistence.update(mirrorActivity);
      }

      if (PropsValues.SOCIAL_ACTIVITY_SETS_ENABLED) {
        socialActivityInterpreterLocalService.updateActivitySet(activity.getActivityId());
      }
    }

    socialActivityCounterLocalService.addActivityCounters(activity);
  }
  @Async
  public void addActivity(SocialActivity activity, SocialActivity mirrorActivity)
      throws PortalException, SystemException {

    if (ImportExportThreadLocal.isImportInProcess()) {
      return;
    }

    if ((activity.getActivityId() > 0)
        || ((mirrorActivity != null) && (mirrorActivity.getActivityId() > 0))) {

      throw new PortalException("Activity and mirror activity must not have primary keys set");
    }

    SocialActivityDefinition activityDefinition =
        socialActivitySettingLocalService.getActivityDefinition(
            activity.getGroupId(), activity.getClassName(), activity.getType());

    if ((activityDefinition == null) || activityDefinition.isLogActivity()) {

      long activityId = counterLocalService.increment(SocialActivity.class.getName());

      activity.setActivityId(activityId);

      socialActivityPersistence.update(activity, false);

      if (mirrorActivity != null) {
        long mirrorActivityId = counterLocalService.increment(SocialActivity.class.getName());

        mirrorActivity.setActivityId(mirrorActivityId);
        mirrorActivity.setMirrorActivityId(activity.getPrimaryKey());

        socialActivityPersistence.update(mirrorActivity, false);
      }
    }

    socialActivityCounterLocalService.addActivityCounters(activity);
  }
  /**
   * Removes the stored activity and its mirror activity from the database.
   *
   * @param activity the activity to be removed
   * @throws PortalException if the user's activity counters could not be deleted or if a portal
   *     exception occurred
   */
  @Override
  public void deleteActivity(SocialActivity activity) throws PortalException {
    if (PropsValues.SOCIAL_ACTIVITY_SETS_ENABLED) {
      socialActivitySetLocalService.decrementActivityCount(activity.getActivitySetId());
    }

    socialActivityPersistence.remove(activity);

    SocialActivity mirrorActivity =
        socialActivityPersistence.fetchByMirrorActivityId(activity.getActivityId());

    if (mirrorActivity != null) {
      socialActivityPersistence.remove(mirrorActivity);
    }
  }