use of org.apache.cloudstack.quota.QuotaAlertManagerImpl.DeferredQuotaEmail in project cloudstack by apache.
the class QuotaStatementImpl method sendStatement.
@Override
public void sendStatement() {
List<DeferredQuotaEmail> deferredQuotaEmailList = new ArrayList<DeferredQuotaEmail>();
for (final QuotaAccountVO quotaAccount : _quotaAcc.listAllQuotaAccount()) {
if (quotaAccount.getQuotaBalance() == null) {
// no quota usage for this account ever, ignore
continue;
}
//check if it is statement time
Calendar[] interval = statementTime(Calendar.getInstance(), _period);
Date lastStatementDate = quotaAccount.getLastStatementDate();
if (interval != null) {
AccountVO account = _accountDao.findById(quotaAccount.getId());
if (account != null) {
if (lastStatementDate == null || getDifferenceDays(lastStatementDate, new Date()) >= s_LAST_STATEMENT_SENT_DAYS + 1) {
BigDecimal quotaUsage = _quotaUsage.findTotalQuotaUsage(account.getAccountId(), account.getDomainId(), null, interval[0].getTime(), interval[1].getTime());
s_logger.info("For account=" + quotaAccount.getId() + ", quota used = " + quotaUsage);
// send statement
deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, quotaUsage, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT));
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("For " + quotaAccount.getId() + " the statement has been sent recently");
}
}
}
} else if (lastStatementDate != null) {
s_logger.info("For " + quotaAccount.getId() + " it is already more than " + getDifferenceDays(lastStatementDate, new Date()) + " days, will send statement in next cycle");
}
}
for (DeferredQuotaEmail emailToBeSent : deferredQuotaEmailList) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Attempting to send quota STATEMENT email to users of account: " + emailToBeSent.getAccount().getAccountName());
}
_quotaAlert.sendQuotaAlert(emailToBeSent);
}
}
Aggregations