use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class AccountJoinDaoImpl method newAccountResponse.
@Override
public AccountResponse newAccountResponse(ResponseView view, 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 fullView = (view == ResponseView.Full && _acctMgr.isRootAdmin(account.getId()));
setResourceLimits(account, fullView, accountResponse);
//get resource limits for projects
long projectLimit = ApiDBUtils.findCorrectResourceLimit(account.getProjectLimit(), account.getId(), ResourceType.project);
String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
long projectTotal = (account.getProjectTotal() == null) ? 0 : account.getProjectTotal();
String projectAvail = (fullView || 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");
// add all the acl groups for an account
accountResponse.setGroups(_acctMgr.listAclGroupsByAccount(account.getId()));
return accountResponse;
}
use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class EnableUserCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("UserId: " + getId());
UserAccount user = _regionService.enableUser(this);
if (user != null) {
UserResponse response = _responseGenerator.createUserResponse(user);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable user");
}
}
use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class LockUserCmd method execute.
@Override
public void execute() {
UserAccount user = _accountService.lockUser(getId());
if (user != null) {
UserResponse response = _responseGenerator.createUserResponse(user);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to lock user");
}
}
use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class ApiDBUtils method newUserResponse.
public static UserResponse newUserResponse(UserAccountJoinVO usr, Long domainId) {
UserResponse response = s_userAccountJoinDao.newUserResponse(usr);
if (!AccountManager.UseSecretKeyInResponse.value()) {
response.setSecretKey(null);
}
// Populate user account role information
if (usr.getAccountRoleId() != null) {
Role role = s_roleService.findRole(usr.getAccountRoleId());
if (role != null) {
response.setRoleId(role.getUuid());
response.setRoleType(role.getRoleType());
response.setRoleName(role.getName());
}
}
if (domainId != null && usr.getDomainId() != domainId)
response.setIsCallerChildDomain(true);
else
response.setIsCallerChildDomain(false);
return response;
}
use of org.apache.cloudstack.api.response.UserResponse in project cloudstack by apache.
the class AccountJoinDaoImpl method newAccountResponse.
@Override
public AccountResponse newAccountResponse(ResponseView view, EnumSet<DomainDetails> details, 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());
StringBuilder domainPath = new StringBuilder("ROOT");
(domainPath.append(account.getDomainPath())).deleteCharAt(domainPath.length() - 1);
accountResponse.setDomainPath(domainPath.toString());
accountResponse.setState(account.getState().toString());
accountResponse.setCreated(account.getCreated());
accountResponse.setNetworkDomain(account.getNetworkDomain());
accountResponse.setDefaultZone(account.getDataCenterUuid());
accountResponse.setIsDefault(account.isDefault());
// get network stat
accountResponse.setBytesReceived(account.getBytesReceived());
accountResponse.setBytesSent(account.getBytesSent());
if (details.contains(DomainDetails.all) || details.contains(DomainDetails.resource)) {
boolean fullView = (view == ResponseView.Full && _acctMgr.isRootAdmin(account.getId()));
setResourceLimits(account, fullView, accountResponse);
// get resource limits for projects
long projectLimit = ApiDBUtils.findCorrectResourceLimit(account.getProjectLimit(), account.getId(), ResourceType.project);
String projectLimitDisplay = (fullView || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
long projectTotal = (account.getProjectTotal() == null) ? 0 : account.getProjectTotal();
String projectAvail = (fullView || 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");
// add all the acl groups for an account
accountResponse.setGroups(_acctMgr.listAclGroupsByAccount(account.getId()));
return accountResponse;
}
Aggregations