quota:fixes

This commit is contained in:
Abhinandan Prateek 2015-08-04 11:45:25 +05:30
parent e2c2e0696d
commit 173f6ba730
6 changed files with 16 additions and 11 deletions

View File

@ -36,7 +36,7 @@ public interface QuotaBalanceDao extends GenericDao<QuotaBalanceVO, Long> {
List<QuotaBalanceVO> findQuotaBalance(Long accountId, Long domainId, Date startDate, Date endDate);
List<QuotaBalanceVO> findQuotaBalance(Long accountId, Long domainId, Date startDate);
List<QuotaBalanceVO> lastQuotaBalanceVO(Long accountId, Long domainId, Date startDate);
BigDecimal lastQuotaBalance(Long accountId, Long domainId, Date startDate);

View File

@ -127,7 +127,9 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase<QuotaBalanceVO, Long> im
return new ArrayList<QuotaBalanceVO>();
}
quotaUsageRecords = listBy(sc);
quotaUsageRecords.addAll(findQuotaBalance(accountId, domainId, startDate));
if (quotaUsageRecords.size() == 0) {
quotaUsageRecords.addAll(lastQuotaBalanceVO(accountId, domainId, startDate));
}
} finally {
txn.close();
}
@ -136,9 +138,10 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase<QuotaBalanceVO, Long> im
return quotaUsageRecords;
}
@SuppressWarnings("deprecation")
@Override
public List<QuotaBalanceVO> findQuotaBalance(final Long accountId, final Long domainId, final Date startDate) {
public List<QuotaBalanceVO> lastQuotaBalanceVO(final Long accountId, final Long domainId, final Date pivotDate) {
final short opendb = TransactionLegacy.currentTxn().getDatabaseId();
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB);
@ -155,8 +158,8 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase<QuotaBalanceVO, Long> im
if (domainId != null) {
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
}
if ((startDate != null)) {
sc.addAnd("updatedOn", SearchCriteria.Op.LTEQ, startDate);
if ((pivotDate != null)) {
sc.addAnd("updatedOn", SearchCriteria.Op.LTEQ, pivotDate);
}
quotaUsageRecords = search(sc, filter);
@ -182,7 +185,7 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase<QuotaBalanceVO, Long> im
@Override
public BigDecimal lastQuotaBalance(final Long accountId, final Long domainId, Date startDate) {
List<QuotaBalanceVO> quotaBalance = findQuotaBalance(accountId, domainId, startDate);
List<QuotaBalanceVO> quotaBalance = lastQuotaBalanceVO(accountId, domainId, startDate);
if (quotaBalance.size() == 0) {
new InvalidParameterValueException("There are no balance entries on or before the requested date.");
}

View File

@ -175,7 +175,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
BigDecimal totalUsage = new BigDecimal(0);
quotaUsage.add(new QuotaUsageVO());// boundary
QuotaUsageVO prev = quotaUsage.get(0);
s_logger.info("createQuotaStatementResponse record count=" + quotaUsage.size());
//s_logger.info("createQuotaStatementResponse record count=" + quotaUsage.size());
for (final QuotaUsageVO quotaRecord : quotaUsage) {
//s_logger.info("createQuotaStatementResponse Type=" + quotaRecord.getUsageType() + " usage=" + usage + " name" + quotaRecord.getUsageItemId());
if (type != quotaRecord.getUsageType()) {
@ -385,7 +385,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
@Override
public List<QuotaBalanceVO> getQuotaBalance(QuotaBalanceCmd cmd) {
return _quotaService.getQuotaBalance(cmd.getAccountId(), cmd.getAccountName(), cmd.getDomainId(), cmd.getStartDate(), cmd.getEndDate());
return _quotaService.findQuotaBalanceVO(cmd.getAccountId(), cmd.getAccountName(), cmd.getDomainId(), cmd.getStartDate(), cmd.getEndDate());
}
@Override

View File

@ -28,7 +28,7 @@ public interface QuotaService extends PluggableService {
List<QuotaUsageVO> getQuotaUsage(Long accountId, String accountName, Long domainId, Integer usageType, Date startDate, Date endDate);
List<QuotaBalanceVO> getQuotaBalance(Long accountId, String accountName, Long domainId, Date startDate, Date endDate);
List<QuotaBalanceVO> findQuotaBalanceVO(Long accountId, String accountName, Long domainId, Date startDate, Date endDate);
Date computeAdjustedTime(Date date);

View File

@ -137,7 +137,7 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi
}
@Override
public List<QuotaBalanceVO> getQuotaBalance(Long accountId, String accountName, Long domainId, Date startDate, Date endDate) {
public List<QuotaBalanceVO> findQuotaBalanceVO(Long accountId, String accountName, Long domainId, Date startDate, Date endDate) {
final short opendb = TransactionLegacy.currentTxn().getDatabaseId();
TransactionLegacy.open(TransactionLegacy.CLOUD_DB).close();
@ -169,7 +169,7 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi
// adjust start date to end of day as there is no end date
Date adjustedStartDate = computeAdjustedTime(_respBldr.startOfNextDay(startDate));
s_logger.debug("getQuotaBalance1: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", on or before " + adjustedStartDate);
List<QuotaBalanceVO> qbrecords = _quotaBalanceDao.findQuotaBalance(accountId, domainId, adjustedStartDate);
List<QuotaBalanceVO> qbrecords = _quotaBalanceDao.lastQuotaBalanceVO(accountId, domainId, adjustedStartDate);
s_logger.info("Found records size=" + qbrecords.size());
if (qbrecords.size() == 0) {
throw new InvalidParameterValueException("Incorrect Date there are no quota records before this date " + adjustedStartDate);

View File

@ -157,9 +157,11 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana
@Override
public void checkAndSendQuotaAlertEmails() {
s_logger.info("Running checkAndSendQuotaAlertEmails");
List<DeferredQuotaEmail> deferredQuotaEmailList = new ArrayList<DeferredQuotaEmail>();
final BigDecimal zeroBalance = new BigDecimal(0);
for (final QuotaAccountVO quotaAccount : _quotaAcc.listAll()) {
s_logger.info("checkAndSendQuotaAlertEmails accId=" + quotaAccount.getId());
BigDecimal accountBalance = quotaAccount.getQuotaBalance();
Date balanceDate = quotaAccount.getQuotaBalanceDate();
Date alertDate = quotaAccount.getQuotaAlertDate();