this._count = "select count(distinct id) from account_view WHERE ";
}
@Override
public AccountResponse newAccountResponse(AccountJoinVO account) {
AccountResponse accountResponse = new AccountResponse();
accountResponse.setId(account.getUuid());
accountResponse.setName(account.getAccountName());
accountResponse.setAccountType(account.getType());
accountResponse.setDomainId(account.getDomainUuid());
accountResponse.setDomainName(account.getDomainName());
accountResponse.setState(account.getState().toString());
accountResponse.setNetworkDomain(account.getNetworkDomain());
accountResponse.setDefaultZone(account.getDataCenterUuid());
accountResponse.setIsDefault(account.isDefault());
// get network stat
accountResponse.setBytesReceived(account.getBytesReceived());
accountResponse.setBytesSent(account.getBytesSent());
boolean accountIsAdmin = (account.getType() == Account.ACCOUNT_TYPE_ADMIN);
setResourceLimits(account, accountIsAdmin, accountResponse);
//get resource limits for projects
long projectLimit = ApiDBUtils.findCorrectResourceLimit(account.getProjectLimit(), account.getType(), ResourceType.project);
String projectLimitDisplay = (accountIsAdmin || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
long projectTotal = (account.getProjectTotal() == null) ? 0 : account.getProjectTotal();
String projectAvail = (accountIsAdmin || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
accountResponse.setProjectLimit(projectLimitDisplay);
accountResponse.setProjectTotal(projectTotal);
accountResponse.setProjectAvailable(projectAvail);
// set async job
if (account.getJobId() != null) {
accountResponse.setJobId(account.getJobUuid());
accountResponse.setJobStatus(account.getJobStatus());
}
// adding all the users for an account as part of the response obj
List<UserAccountJoinVO> usersForAccount = ApiDBUtils.findUserViewByAccountId(account.getId());
List<UserResponse> userResponses = ViewResponseHelper.createUserResponse(usersForAccount.toArray(new UserAccountJoinVO[usersForAccount.size()]));
accountResponse.setUsers(userResponses);
// set details
accountResponse.setDetails(ApiDBUtils.getAccountDetails(account.getId()));
accountResponse.setObjectName("account");
return accountResponse;
}