QUOTA: Ensuring that the dates displayed are as per user expectations

When querying db we use start of next day to query quota usage for
    today, but while displaying it to user we still need to show it as
    todays date
This commit is contained in:
Abhinandan Prateek 2015-12-08 09:59:06 +05:30
parent 312b9aff94
commit 1e17c3e38c
3 changed files with 16 additions and 11 deletions

View File

@ -83,7 +83,12 @@ public class QuotaBalanceCmd extends BaseCmd {
} }
public Date getEndDate() { public Date getEndDate() {
return endDate == null ? null : _responseBuilder.startOfNextDay(endDate == null ? null : new Date(endDate.getTime())); if (endDate == null){
return null;
}
else{
return _responseBuilder.startOfNextDay(new Date(endDate.getTime()));
}
} }
public void setEndDate(Date endDate) { public void setEndDate(Date endDate) {
@ -113,10 +118,10 @@ public class QuotaBalanceCmd extends BaseCmd {
List<QuotaBalanceVO> quotaUsage = _responseBuilder.getQuotaBalance(this); List<QuotaBalanceVO> quotaUsage = _responseBuilder.getQuotaBalance(this);
QuotaBalanceResponse response; QuotaBalanceResponse response;
if (getEndDate() == null) { if (endDate == null) {
response = _responseBuilder.createQuotaLastBalanceResponse(quotaUsage, getStartDate()); response = _responseBuilder.createQuotaLastBalanceResponse(quotaUsage, getStartDate());
} else { } else {
response = _responseBuilder.createQuotaBalanceResponse(quotaUsage, getStartDate(), endDate == null ? null : new Date(endDate.getTime())); response = _responseBuilder.createQuotaBalanceResponse(quotaUsage, getStartDate(), new Date(endDate.getTime()));
} }
response.setResponseName(getCommandName()); response.setResponseName(getCommandName());
setResponseObject(response); setResponseObject(response);

View File

@ -233,9 +233,9 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
// order is desc last item is the start item // order is desc last item is the start item
QuotaBalanceVO startItem = quotaBalance.get(quotaBalance.size() - 1); QuotaBalanceVO startItem = quotaBalance.get(quotaBalance.size() - 1);
QuotaBalanceVO endItem = quotaBalance.get(0); QuotaBalanceVO endItem = quotaBalance.get(0);
resp.setStartDate(startItem.getUpdatedOn()); resp.setStartDate(startDate);
resp.setStartQuota(startItem.getCreditBalance()); resp.setStartQuota(startItem.getCreditBalance());
resp.setEndDate(endItem.getUpdatedOn()); resp.setEndDate(endDate);
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("createQuotaBalanceResponse: Start Entry=" + startItem); s_logger.debug("createQuotaBalanceResponse: Start Entry=" + startItem);
s_logger.debug("createQuotaBalanceResponse: End Entry=" + endItem); s_logger.debug("createQuotaBalanceResponse: End Entry=" + endItem);
@ -479,7 +479,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
lastCredits = lastCredits.add(entry.getCreditBalance()); lastCredits = lastCredits.add(entry.getCreditBalance());
} }
resp.setStartQuota(lastCredits); resp.setStartQuota(lastCredits);
resp.setStartDate(_quotaService.computeAdjustedTime(startDate)); resp.setStartDate(startDate);
resp.setCurrency(QuotaConfig.QuotaCurrencySymbol.value()); resp.setCurrency(QuotaConfig.QuotaCurrencySymbol.value());
resp.setObjectName("balance"); resp.setObjectName("balance");
return resp; return resp;

View File

@ -138,8 +138,8 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi
@Override @Override
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] { QuotaPluginEnabled, QuotaEnableEnforcement, QuotaCurrencySymbol, QuotaStatementPeriod, QuotaSmtpHost, QuotaSmtpPort, QuotaSmtpTimeout, QuotaSmtpUser, QuotaSmtpPassword, return new ConfigKey<?>[] {QuotaPluginEnabled, QuotaEnableEnforcement, QuotaCurrencySymbol, QuotaStatementPeriod, QuotaSmtpHost, QuotaSmtpPort, QuotaSmtpTimeout,
QuotaSmtpAuthType, QuotaSmtpSender }; QuotaSmtpUser, QuotaSmtpPassword, QuotaSmtpAuthType, QuotaSmtpSender};
} }
@Override @Override
@ -193,8 +193,8 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi
} else if (startDate.before(endDate)) { } else if (startDate.before(endDate)) {
Date adjustedEndDate = computeAdjustedTime(endDate); Date adjustedEndDate = computeAdjustedTime(endDate);
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("getQuotaBalance2: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + " and " s_logger.debug("getQuotaBalance2: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate
+ adjustedEndDate); + " and " + adjustedEndDate);
} }
List<QuotaBalanceVO> qbrecords = _quotaBalanceDao.findQuotaBalance(accountId, domainId, adjustedStartDate, adjustedEndDate); List<QuotaBalanceVO> qbrecords = _quotaBalanceDao.findQuotaBalance(accountId, domainId, adjustedStartDate, adjustedEndDate);
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
@ -243,7 +243,7 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi
Date adjustedEndDate = computeAdjustedTime(endDate); Date adjustedEndDate = computeAdjustedTime(endDate);
Date adjustedStartDate = computeAdjustedTime(startDate); Date adjustedStartDate = computeAdjustedTime(startDate);
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Getting quota records for account: " + accountId + ", domainId: " + domainId + ", between " + startDate + " and " + endDate); s_logger.debug("Getting quota records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + " and " + adjustedEndDate);
} }
return _quotaUsageDao.findQuotaUsage(accountId, domainId, usageType, adjustedStartDate, adjustedEndDate); return _quotaUsageDao.findQuotaUsage(accountId, domainId, usageType, adjustedStartDate, adjustedEndDate);
} }