Search in sources :

Example 6 with AccountResponse

use of org.apache.cloudstack.api.response.AccountResponse in project cloudstack by apache.

the class ApiDBUtils method newAccountResponse.

public static AccountResponse newAccountResponse(ResponseView view, AccountJoinVO ve) {
    AccountResponse response = s_accountJoinDao.newAccountResponse(view, ve);
    // Populate account role information
    if (ve.getRoleId() != null) {
        Role role = s_roleService.findRole(ve.getRoleId());
        if (role != null) {
            response.setRoleId(role.getUuid());
            response.setRoleType(role.getRoleType());
            response.setRoleName(role.getName());
        }
    }
    return response;
}
Also used : Role(org.apache.cloudstack.acl.Role) ProjectAccountResponse(org.apache.cloudstack.api.response.ProjectAccountResponse) AccountResponse(org.apache.cloudstack.api.response.AccountResponse)

Example 7 with AccountResponse

use of org.apache.cloudstack.api.response.AccountResponse in project cloudstack by apache.

the class LdapCreateAccountCmd method execute.

@Override
public void execute() throws ServerApiException {
    if (getAccountType() == null && getRoleId() == null) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Both account type and role ID are not provided");
    }
    final CallContext callContext = getCurrentContext();
    String finalAccountName = getAccountName();
    Long finalDomainId = getDomainId();
    callContext.setEventDetails("Account Name: " + finalAccountName + ", Domain Id:" + finalDomainId);
    try {
        final LdapUser user = _ldapManager.getUser(username);
        validateUser(user);
        final UserAccount userAccount = createCloudstackUserAccount(user, finalAccountName, finalDomainId);
        if (userAccount != null) {
            final AccountResponse response = _responseGenerator.createUserAccountResponse(ResponseView.Full, userAccount);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a user account");
        }
    } catch (NoLdapUserMatchingQueryException e) {
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, "No LDAP user exists with the username of " + username);
    }
}
Also used : NoLdapUserMatchingQueryException(org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException) LdapUser(org.apache.cloudstack.ldap.LdapUser) ServerApiException(org.apache.cloudstack.api.ServerApiException) AccountResponse(org.apache.cloudstack.api.response.AccountResponse) CallContext(org.apache.cloudstack.context.CallContext) UserAccount(com.cloud.user.UserAccount)

Example 8 with AccountResponse

use of org.apache.cloudstack.api.response.AccountResponse in project cloudstack by apache.

the class DisableAccountCmd method execute.

@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.current().setEventDetails("Account Name: " + getAccountName() + ", Domain Id:" + getDomainId());
    Account result = _regionService.disableAccount(this);
    if (result != null) {
        AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, lockRequested == true ? "Failed to lock account" : "Failed to disable account");
    }
}
Also used : Account(com.cloud.user.Account) ServerApiException(org.apache.cloudstack.api.ServerApiException) AccountResponse(org.apache.cloudstack.api.response.AccountResponse)

Example 9 with AccountResponse

use of org.apache.cloudstack.api.response.AccountResponse in project cloudstack by apache.

the class EnableAccountCmd method execute.

@Override
public void execute() {
    Account result = _regionService.enableAccount(this);
    if (result != null) {
        AccountResponse response = _responseGenerator.createAccountResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable account");
    }
}
Also used : Account(com.cloud.user.Account) ServerApiException(org.apache.cloudstack.api.ServerApiException) AccountResponse(org.apache.cloudstack.api.response.AccountResponse)

Aggregations

AccountResponse (org.apache.cloudstack.api.response.AccountResponse)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)6 Account (com.cloud.user.Account)4 UserAccountJoinVO (com.cloud.api.query.vo.UserAccountJoinVO)2 UserAccount (com.cloud.user.UserAccount)2 ProjectAccountResponse (org.apache.cloudstack.api.response.ProjectAccountResponse)2 AccountJoinVO (com.cloud.api.query.vo.AccountJoinVO)1 ProjectAccountJoinVO (com.cloud.api.query.vo.ProjectAccountJoinVO)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Role (org.apache.cloudstack.acl.Role)1 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)1 ListAccountsCmdByAdmin (org.apache.cloudstack.api.command.admin.account.ListAccountsCmdByAdmin)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 UserResponse (org.apache.cloudstack.api.response.UserResponse)1 CallContext (org.apache.cloudstack.context.CallContext)1 LdapUser (org.apache.cloudstack.ldap.LdapUser)1 NoLdapUserMatchingQueryException (org.apache.cloudstack.ldap.NoLdapUserMatchingQueryException)1