public void testUpdateExisting() throws Exception {
    long pk = nextLong();

    SocialEquityLog newSocialEquityLog = _persistence.create(pk);

    newSocialEquityLog.setGroupId(nextLong());
    newSocialEquityLog.setCompanyId(nextLong());
    newSocialEquityLog.setUserId(nextLong());
    newSocialEquityLog.setAssetEntryId(nextLong());
    newSocialEquityLog.setActionId(randomString());
    newSocialEquityLog.setActionDate(nextInt());
    newSocialEquityLog.setActive(randomBoolean());
    newSocialEquityLog.setExpiration(nextInt());
    newSocialEquityLog.setType(nextInt());
    newSocialEquityLog.setValue(nextInt());
    newSocialEquityLog.setExtraData(randomString());

    _persistence.update(newSocialEquityLog, false);

    SocialEquityLog existingSocialEquityLog =
        _persistence.findByPrimaryKey(newSocialEquityLog.getPrimaryKey());

    assertEquals(existingSocialEquityLog.getEquityLogId(), newSocialEquityLog.getEquityLogId());
    assertEquals(existingSocialEquityLog.getGroupId(), newSocialEquityLog.getGroupId());
    assertEquals(existingSocialEquityLog.getCompanyId(), newSocialEquityLog.getCompanyId());
    assertEquals(existingSocialEquityLog.getUserId(), newSocialEquityLog.getUserId());
    assertEquals(existingSocialEquityLog.getAssetEntryId(), newSocialEquityLog.getAssetEntryId());
    assertEquals(existingSocialEquityLog.getActionId(), newSocialEquityLog.getActionId());
    assertEquals(existingSocialEquityLog.getActionDate(), newSocialEquityLog.getActionDate());
    assertEquals(existingSocialEquityLog.getActive(), newSocialEquityLog.getActive());
    assertEquals(existingSocialEquityLog.getExpiration(), newSocialEquityLog.getExpiration());
    assertEquals(existingSocialEquityLog.getType(), newSocialEquityLog.getType());
    assertEquals(existingSocialEquityLog.getValue(), newSocialEquityLog.getValue());
    assertEquals(existingSocialEquityLog.getExtraData(), newSocialEquityLog.getExtraData());
  }
  protected void addEquityLog(
      User user, AssetEntry assetEntry, User assetEntryUser, SocialEquitySetting equitySetting)
      throws PortalException, SystemException {

    if (!isAddEquityLog(user.getUserId(), assetEntry.getEntryId(), equitySetting)) {

      return;
    }

    int actionDate = getEquityDate();

    double k = calculateK(equitySetting.getValue(), equitySetting.getLifespan());
    double b = calculateB(actionDate, equitySetting.getValue(), equitySetting.getLifespan());

    SocialEquityValue socialEquity = new SocialEquityValue(k, b);

    if (equitySetting.getType() == SocialEquitySettingConstants.TYPE_INFORMATION) {

      socialEquityLogLocalService.incrementSocialEquityAssetEntry_IQ(
          assetEntry.getEntryId(), socialEquity);

      if ((assetEntryUser != null) && !assetEntryUser.isDefaultUser()) {
        socialEquityLogLocalService.incrementSocialEquityUser_CQ(
            assetEntry.getGroupId(), assetEntryUser.getUserId(), socialEquity);
      }
    } else if (equitySetting.getType() == SocialEquitySettingConstants.TYPE_PARTICIPATION) {

      if (!user.isDefaultUser()) {
        socialEquityLogLocalService.incrementSocialEquityUser_PQ(
            assetEntry.getGroupId(), user.getUserId(), socialEquity);
      }
    }

    long equityLogId = counterLocalService.increment();

    SocialEquityLog equityLog = socialEquityLogPersistence.create(equityLogId);

    equityLog.setGroupId(assetEntry.getGroupId());
    equityLog.setCompanyId(user.getCompanyId());
    equityLog.setUserId(user.getUserId());
    equityLog.setAssetEntryId(assetEntry.getEntryId());
    equityLog.setActionId(equitySetting.getActionId());
    equityLog.setActionDate(actionDate);
    equityLog.setType(equitySetting.getType());
    equityLog.setValue(equitySetting.getValue());
    equityLog.setExpiration(actionDate + equitySetting.getLifespan());
    equityLog.setActive(true);

    socialEquityLogPersistence.update(equityLog, false);
  }
  protected SocialEquityLog addSocialEquityLog() throws Exception {
    long pk = nextLong();

    SocialEquityLog socialEquityLog = _persistence.create(pk);

    socialEquityLog.setGroupId(nextLong());
    socialEquityLog.setCompanyId(nextLong());
    socialEquityLog.setUserId(nextLong());
    socialEquityLog.setAssetEntryId(nextLong());
    socialEquityLog.setActionId(randomString());
    socialEquityLog.setActionDate(nextInt());
    socialEquityLog.setActive(randomBoolean());
    socialEquityLog.setExpiration(nextInt());
    socialEquityLog.setType(nextInt());
    socialEquityLog.setValue(nextInt());
    socialEquityLog.setExtraData(randomString());

    _persistence.update(socialEquityLog, false);

    return socialEquityLog;
  }