コード例 #1
0
  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);
  }
コード例 #2
0
  protected SocialEquityActionMapping getMergedEquityActionMapping(
      long groupId, SocialEquityActionMapping equityActionMapping) throws Exception {

    SocialEquityActionMapping mergedEquityActionMapping = equityActionMapping.clone();

    List<SocialEquitySetting> equitySettings =
        SocialEquitySettingLocalServiceUtil.getEquitySettings(
            groupId, equityActionMapping.getClassName(), equityActionMapping.getActionId());

    for (SocialEquitySetting equitySetting : equitySettings) {
      if (equitySetting.getType() == SocialEquitySettingConstants.TYPE_INFORMATION) {

        mergedEquityActionMapping.setInformationDailyLimit(equitySetting.getDailyLimit());
        mergedEquityActionMapping.setInformationLifespan(equitySetting.getLifespan());
        mergedEquityActionMapping.setInformationValue(equitySetting.getValue());
      } else {
        mergedEquityActionMapping.setParticipationDailyLimit(equitySetting.getDailyLimit());
        mergedEquityActionMapping.setParticipationLifespan(equitySetting.getLifespan());
        mergedEquityActionMapping.setParticipationValue(equitySetting.getValue());
      }

      mergedEquityActionMapping.setUnique(equitySetting.isUniqueEntry());
    }

    return mergedEquityActionMapping;
  }
コード例 #3
0
  public void addEquityLogs(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);

    User assetEntryUser = null;

    try {
      assetEntryUser = userPersistence.findByPrimaryKey(assetEntry.getUserId());
    } catch (NoSuchUserException nsue) {
    }

    List<SocialEquitySetting> equitySettings =
        socialEquitySettingLocalService.getEquitySettings(
            assetEntry.getGroupId(), assetEntry.getClassNameId(), actionId);

    for (SocialEquitySetting equitySetting : equitySettings) {
      if (isSocialEquityEnabled(
          assetEntry.getGroupId(), assetEntry.getClassName(), equitySetting.getType())) {

        addEquityLog(user, assetEntry, assetEntryUser, equitySetting);
      }
    }
  }
コード例 #4
0
  protected boolean isAddEquityLog(
      long userId, long assetEntryId, SocialEquitySetting equitySetting) throws SystemException {

    if (equitySetting.getDailyLimit() < 0) {
      return false;
    }

    String actionId = equitySetting.getActionId();
    int actionDate = getEquityDate();
    int type = equitySetting.getType();

    // Duplicate

    if (socialEquityLogPersistence.countByU_AEI_AID_AD_A_T(
            userId, assetEntryId, actionId, actionDate, true, type)
        > 0) {

      return false;
    }

    // Unique

    if (equitySetting.isUniqueEntry()) {
      int count = 0;

      if (type == SocialEquitySettingConstants.TYPE_INFORMATION) {
        count = socialEquityLogPersistence.countByAEI_AID_A_T(assetEntryId, actionId, true, type);
      } else {
        count = socialEquityLogPersistence.countByU_AID_A_T(userId, actionId, true, type);
      }

      if (count > 0) {
        return false;
      }
    }

    // Daily limit

    if (equitySetting.getDailyLimit() == 0) {
      return true;
    }

    int count = 0;

    if (type == SocialEquitySettingConstants.TYPE_INFORMATION) {
      count =
          socialEquityLogPersistence.countByAEI_AID_AD_A_T(
              assetEntryId, actionId, actionDate, true, type);
    } else {
      count =
          socialEquityLogPersistence.countByU_AID_AD_A_T(userId, actionId, actionDate, true, type);
    }

    if (count < equitySetting.getDailyLimit()) {
      return true;
    } else {
      return false;
    }
  }