You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/01/14 15:00:21 UTC
[GitHub] [cloudstack] joseflauzino commented on a change in pull request #5866: Filter usage for project
joseflauzino commented on a change in pull request #5866:
URL: https://github.com/apache/cloudstack/pull/5866#discussion_r784911319
##########
File path: server/src/main/java/com/cloud/usage/UsageServiceImpl.java
##########
@@ -166,46 +167,27 @@ public boolean generateUsageRecords(GenerateUsageRecordsCmd cmd) {
Long accountId = cmd.getAccountId();
Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName();
- Account userAccount = null;
Account caller = CallContext.current().getCallingAccount();
Long usageType = cmd.getUsageType();
Long projectId = cmd.getProjectId();
String usageId = cmd.getUsageId();
+ boolean projectRequested = false;
if (projectId != null) {
if (accountId != null) {
throw new InvalidParameterValueException("Projectid and accountId can't be specified together");
}
- Project project = _projectMgr.getProject(projectId);
- if (project == null) {
- throw new InvalidParameterValueException("Unable to find project by id " + projectId);
- }
- accountId = project.getProjectAccountId();
- }
-
- //if accountId is not specified, use accountName and domainId
- if ((accountId == null) && (accountName != null) && (domainId != null)) {
- if (_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
- Filter filter = new Filter(AccountVO.class, "id", Boolean.FALSE, null, null);
- List<AccountVO> accounts = _accountDao.listAccounts(accountName, domainId, filter);
- if (accounts.size() > 0) {
- userAccount = accounts.get(0);
- }
- if (userAccount != null) {
- accountId = userAccount.getId();
- } else {
- throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
- }
- } else {
- throw new PermissionDeniedException("Invalid Domain Id or Account");
- }
+ accountId = GetAccountIdFromProject(projectId);
+ projectRequested = true;
+ } else if ((accountId == null) && (accountName != null) && (domainId != null)) {
Review comment:
@DaanHoogland
Since `accountName` is a String, wouldn't it be better to use StringUtils to also check for `""`, `" "`?
```suggestion
} else if ((accountId == null) && (StringUtils.isNotBlank(accountName)) && (domainId != null)) {
```
--
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: commits-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org