winterhazel commented on code in PR #13449:
URL: https://github.com/apache/cloudstack/pull/13449#discussion_r3508836474
##########
plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java:
##########
@@ -661,49 +699,77 @@ protected void
validateEndDateOnCreatingNewQuotaTariff(QuotaTariffVO newQuotaTar
}
@Override
- public QuotaCreditsResponse addQuotaCredits(Long accountId, Long domainId,
Double amount, Long updatedBy, Boolean enforce) {
+ public QuotaCreditsResponse addQuotaCredits(QuotaCreditsCmd cmd) {
+ Double value = cmd.getValue();
+ if (value == null) {
+ throw new InvalidParameterValueException("Please specify a valid
amount of credits.");
+ }
+
+ Long accountId = _accountMgr.finalizeAccountId(cmd.getAccountId(),
cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId());
+ AccountVO account = _accountDao.findById(accountId);
+ Long domainId = account.getDomainId();
+
Date depositedOn = new Date();
QuotaBalanceVO qb = _quotaBalanceDao.findLaterBalanceEntry(accountId,
domainId, depositedOn);
-
if (qb != null) {
throw new InvalidParameterValueException(String.format("Incorrect
deposit date [%s], as there are balance entries after this date.",
depositedOn));
}
- QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, new
BigDecimal(amount), updatedBy);
+ boolean lockAccountEnforcement =
"true".equalsIgnoreCase(QuotaConfig.QuotaEnableEnforcement.value());
+ QuotaCreditsVO result =
Transaction.execute(TransactionLegacy.USAGE_DB,
(TransactionCallback<QuotaCreditsVO>) status -> persistQuotaCredits(cmd, value,
depositedOn, account, lockAccountEnforcement));
+
+ UserVO creditor = getCreditorForQuotaCredits(result);
+ return createQuotaCreditsResponse(result, creditor);
+ }
+
+ protected QuotaCreditsVO persistQuotaCredits(QuotaCreditsCmd cmd, Double
value, Date depositedOn, AccountVO account, boolean lockAccountEnforcement) {
+ Long accountId = account.getId();
+ Long domainId = account.getDomainId();
+ long callingUserId = CallContext.current().getCallingUserId();
+ QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, new
BigDecimal(value), callingUserId);
credits.setUpdatedOn(depositedOn);
QuotaCreditsVO result = quotaCreditsDao.saveCredits(credits);
- if (result == null) {
- logger.error("Unable to add credits to account ID [{}].",
accountId);
- throw new CloudRuntimeException("Unable to add credits to
account.");
- }
- final AccountVO account = _accountDao.findById(accountId);
- if (account == null) {
- throw new InvalidParameterValueException("Account does not exist
with account id " + accountId);
- }
- final boolean lockAccountEnforcement =
"true".equalsIgnoreCase(QuotaConfig.QuotaEnableEnforcement.value());
- final BigDecimal currentAccountBalance =
_quotaBalanceDao.getLastQuotaBalance(accountId, domainId);
- logger.debug("Depositing [{}] credits on adjusted date [{}]; current
balance is [{}].", amount,
+ BigDecimal currentAccountBalance =
_quotaBalanceDao.getLastQuotaBalance(accountId, domainId);
Review Comment:
This is false.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]