Search in sources :

Example 1 with UserResponse

use of com.cloud.api.response.UserResponse in project CloudStack-archive by CloudStack-extras.

the class CreateUserCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("UserName: " + getUserName() + ", FirstName :" + getFirstName() + ", LastName: " + getLastName());
    User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId());
    if (user != null) {
        UserResponse response = _responseGenerator.createUserResponse(user);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a user");
    }
}
Also used : UserResponse(com.cloud.api.response.UserResponse) User(com.cloud.user.User) ServerApiException(com.cloud.api.ServerApiException)

Example 2 with UserResponse

use of com.cloud.api.response.UserResponse in project CloudStack-archive by CloudStack-extras.

the class UpdateUserCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("UserId: " + getId());
    UserAccount user = _accountService.updateUser(this);
    if (user != null) {
        UserResponse response = _responseGenerator.createUserResponse(user);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update user");
    }
}
Also used : UserResponse(com.cloud.api.response.UserResponse) ServerApiException(com.cloud.api.ServerApiException) UserAccount(com.cloud.user.UserAccount)

Example 3 with UserResponse

use of com.cloud.api.response.UserResponse in project CloudStack-archive by CloudStack-extras.

the class ListUsersCmd method execute.

@Override
public void execute() {
    List<? extends UserAccount> result = _accountService.searchForUsers(this);
    ListResponse<UserResponse> response = new ListResponse<UserResponse>();
    List<UserResponse> userResponses = new ArrayList<UserResponse>();
    for (UserAccount user : result) {
        UserResponse userResponse = _responseGenerator.createUserResponse(user);
        userResponses.add(userResponse);
    }
    response.setResponses(userResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : UserResponse(com.cloud.api.response.UserResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) UserAccount(com.cloud.user.UserAccount)

Example 4 with UserResponse

use of com.cloud.api.response.UserResponse in project cosmic by MissionCriticalCloud.

the class GetUserCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final UserAccount result = _accountService.getUserByApiKey(getApiKey());
    if (result != null) {
        final UserResponse response = _responseGenerator.createUserResponse(result);
        if (StringUtils.isNotBlank(response.getSecretKey())) {
            response.setSecretKey("SecretKey only visible when generating a new key");
        }
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new InvalidParameterValueException("User with specified API key does not exist");
    }
}
Also used : UserResponse(com.cloud.api.response.UserResponse) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) UserAccount(com.cloud.user.UserAccount)

Example 5 with UserResponse

use of com.cloud.api.response.UserResponse in project cosmic by MissionCriticalCloud.

the class ListUsersCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final ListResponse<UserResponse> response = _queryService.searchForUsers(this);
    response.setResponseName(getCommandName());
    List<UserResponse> responseList = response.getResponses();
    if (responseList != null && responseList.size() > 0) {
        for (UserResponse userResponse : responseList) {
            if (StringUtils.isNotBlank(userResponse.getSecretKey())) {
                userResponse.setSecretKey("SecretKey only visible when generating a new key");
            }
        }
    }
    this.setResponseObject(response);
}
Also used : UserResponse(com.cloud.api.response.UserResponse)

Aggregations

UserResponse (com.cloud.api.response.UserResponse)19 ServerApiException (com.cloud.api.ServerApiException)10 UserAccount (com.cloud.user.UserAccount)10 ListResponse (com.cloud.api.response.ListResponse)3 Test (org.junit.Test)3 User (com.cloud.user.User)2 ListUsersCmd (com.cloud.api.command.admin.user.ListUsersCmd)1 UserAccountJoinVO (com.cloud.api.query.vo.UserAccountJoinVO)1 AccountResponse (com.cloud.api.response.AccountResponse)1 LdapUserResponse (com.cloud.api.response.LdapUserResponse)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1 ArrayList (java.util.ArrayList)1