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()); }
public void deactivateEquityLogs(long userId, long assetEntryId, String actionId) throws PortalException, SystemException { if (!PropsValues.SOCIAL_EQUITY_EQUITY_LOG_ENABLED) { return; } User user = userPersistence.findByPrimaryKey(userId); AssetEntry assetEntry = assetEntryPersistence.findByPrimaryKey(assetEntryId); // Information Equity if (isSocialEquityEnabled( assetEntry.getGroupId(), assetEntry.getClassName(), SocialEquitySettingConstants.TYPE_INFORMATION)) { List<SocialEquityLog> equityLogs = socialEquityLogPersistence.findByAEI_AID_A_T( assetEntryId, actionId, true, SocialEquitySettingConstants.TYPE_INFORMATION); SocialEquityValue socialEquityValue = new SocialEquityValue(0, 0); for (SocialEquityLog equityLog : equityLogs) { double k = calculateK(equityLog.getValue(), equityLog.getLifespan()); double b = calculateB(equityLog.getActionDate(), equityLog.getValue(), equityLog.getLifespan()); socialEquityValue.subtract(new SocialEquityValue(k, b)); socialEquityLogPersistence.remove(equityLog); } socialEquityLogLocalService.incrementSocialEquityAssetEntry_IQ( assetEntryId, socialEquityValue); socialEquityLogLocalService.incrementSocialEquityUser_CQ( assetEntry.getGroupId(), assetEntry.getUserId(), socialEquityValue); } // Participation Equity if (isSocialEquityEnabled( assetEntry.getGroupId(), assetEntry.getClassName(), SocialEquitySettingConstants.TYPE_PARTICIPATION)) { List<SocialEquityLog> equityLogs = socialEquityLogPersistence.findByU_AID_A_T( userId, actionId, true, SocialEquitySettingConstants.TYPE_PARTICIPATION); SocialEquityValue socialEquityValue = new SocialEquityValue(0, 0); for (SocialEquityLog equityLog : equityLogs) { double k = calculateK(equityLog.getValue(), equityLog.getLifespan()); double b = calculateB(equityLog.getActionDate(), equityLog.getValue(), equityLog.getLifespan()); socialEquityValue.subtract(new SocialEquityValue(k, b)); socialEquityLogPersistence.remove(equityLog); } socialEquityLogLocalService.incrementSocialEquityUser_PQ( user.getGroup().getGroupId(), userId, socialEquityValue); } }