Search in sources :

Example 1 with ProjectAccountJoinVO

use of com.cloud.api.query.vo.ProjectAccountJoinVO in project cloudstack by apache.

the class ApiResponseHelper method createProjectAccountResponse.

@Override
public ProjectAccountResponse createProjectAccountResponse(ProjectAccount projectAccount) {
    ProjectAccountJoinVO vProj = ApiDBUtils.newProjectAccountView(projectAccount);
    List<ProjectAccountResponse> listProjs = ViewResponseHelper.createProjectAccountResponse(vProj);
    assert listProjs != null && listProjs.size() == 1 : "There should be one project account returned";
    return listProjs.get(0);
}
Also used : ProjectAccountJoinVO(com.cloud.api.query.vo.ProjectAccountJoinVO) ProjectAccountResponse(org.apache.cloudstack.api.response.ProjectAccountResponse)

Example 2 with ProjectAccountJoinVO

use of com.cloud.api.query.vo.ProjectAccountJoinVO in project cloudstack by apache.

the class QueryManagerImpl method listProjectAccountsInternal.

public Pair<List<ProjectAccountJoinVO>, Integer> listProjectAccountsInternal(ListProjectAccountsCmd cmd) {
    long projectId = cmd.getProjectId();
    String accountName = cmd.getAccountName();
    String role = cmd.getRole();
    Long startIndex = cmd.getStartIndex();
    Long pageSizeVal = cmd.getPageSizeVal();
    // long projectId, String accountName, String role, Long startIndex,
    // Long pageSizeVal) {
    Account caller = CallContext.current().getCallingAccount();
    // check that the project exists
    Project project = _projectDao.findById(projectId);
    if (project == null) {
        throw new InvalidParameterValueException("Unable to find the project id=" + projectId);
    }
    // project's account
    if (!_accountMgr.isAdmin(caller.getId()) && _projectAccountDao.findByProjectIdAccountId(projectId, caller.getAccountId()) == null) {
        throw new PermissionDeniedException("Account " + caller + " is not authorized to list users of the project id=" + projectId);
    }
    Filter searchFilter = new Filter(ProjectAccountJoinVO.class, "id", false, startIndex, pageSizeVal);
    SearchBuilder<ProjectAccountJoinVO> sb = _projectAccountJoinDao.createSearchBuilder();
    sb.and("accountRole", sb.entity().getAccountRole(), Op.EQ);
    sb.and("projectId", sb.entity().getProjectId(), Op.EQ);
    if (accountName != null) {
        sb.and("accountName", sb.entity().getAccountName(), Op.EQ);
    }
    SearchCriteria<ProjectAccountJoinVO> sc = sb.create();
    sc.setParameters("projectId", projectId);
    if (role != null) {
        sc.setParameters("accountRole", role);
    }
    if (accountName != null) {
        sc.setParameters("accountName", accountName);
    }
    return _projectAccountJoinDao.searchAndCount(sc, searchFilter);
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) ProjectAccountJoinVO(com.cloud.api.query.vo.ProjectAccountJoinVO) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 3 with ProjectAccountJoinVO

use of com.cloud.api.query.vo.ProjectAccountJoinVO in project cloudstack by apache.

the class ViewResponseHelper method createProjectAccountResponse.

public static List<ProjectAccountResponse> createProjectAccountResponse(ProjectAccountJoinVO... projectAccounts) {
    List<ProjectAccountResponse> responseList = new ArrayList<ProjectAccountResponse>();
    for (ProjectAccountJoinVO proj : projectAccounts) {
        ProjectAccountResponse resp = ApiDBUtils.newProjectAccountResponse(proj);
        // update user list
        Account caller = CallContext.current().getCallingAccount();
        if (ApiDBUtils.isAdmin(caller)) {
            List<UserAccountJoinVO> users = ApiDBUtils.findUserViewByAccountId(proj.getAccountId());
            resp.setUsers(ViewResponseHelper.createUserResponse(users.toArray(new UserAccountJoinVO[users.size()])));
        }
        responseList.add(resp);
    }
    return responseList;
}
Also used : Account(com.cloud.user.Account) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) ArrayList(java.util.ArrayList) ProjectAccountJoinVO(com.cloud.api.query.vo.ProjectAccountJoinVO) ProjectAccountResponse(org.apache.cloudstack.api.response.ProjectAccountResponse)

Aggregations

ProjectAccountJoinVO (com.cloud.api.query.vo.ProjectAccountJoinVO)3 Account (com.cloud.user.Account)2 ProjectAccountResponse (org.apache.cloudstack.api.response.ProjectAccountResponse)2 UserAccountJoinVO (com.cloud.api.query.vo.UserAccountJoinVO)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 Project (com.cloud.projects.Project)1 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)1 Filter (com.cloud.utils.db.Filter)1 ArrayList (java.util.ArrayList)1