Search in sources :

Example 11 with UserResponse

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;
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) AccountResponse(org.apache.cloudstack.api.response.AccountResponse)

Example 12 with UserResponse

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");
    }
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserAccount(com.cloud.user.UserAccount)

Example 13 with UserResponse

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");
    }
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserAccount(com.cloud.user.UserAccount)

Example 14 with UserResponse

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;
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) Role(org.apache.cloudstack.acl.Role)

Example 15 with UserResponse

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;
}
Also used : UserResponse(org.apache.cloudstack.api.response.UserResponse) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) AccountResponse(org.apache.cloudstack.api.response.AccountResponse)

Aggregations

UserResponse (org.apache.cloudstack.api.response.UserResponse)20 LdapUserResponse (org.apache.cloudstack.api.response.LdapUserResponse)8 UserAccount (com.cloud.user.UserAccount)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)5 UserAccountJoinVO (com.cloud.api.query.vo.UserAccountJoinVO)3 ArrayList (java.util.ArrayList)3 AccountResponse (org.apache.cloudstack.api.response.AccountResponse)2 ListResponse (org.apache.cloudstack.api.response.ListResponse)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 ResourceIcon (com.cloud.server.ResourceIcon)1 Account (com.cloud.user.Account)1 User (com.cloud.user.User)1 List (java.util.List)1 Role (org.apache.cloudstack.acl.Role)1 ResourceIconResponse (org.apache.cloudstack.api.response.ResourceIconResponse)1 LdapUser (org.apache.cloudstack.ldap.LdapUser)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1