Search in sources :

Example 1 with AccountJoinVO

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

the class ProjectJoinDaoImpl method newProjectResponse.

@Override
public ProjectResponse newProjectResponse(ProjectJoinVO proj) {
    ProjectResponse response = new ProjectResponse();
    response.setId(proj.getUuid());
    response.setName(proj.getName());
    response.setDisplaytext(proj.getDisplayText());
    if (proj.getState() != null) {
        response.setState(proj.getState().toString());
    }
    response.setDomainId(proj.getDomainUuid());
    response.setDomain(proj.getDomainName());
    response.setOwner(proj.getOwner());
    // update tag information
    Long tag_id = proj.getTagId();
    if (tag_id != null && tag_id.longValue() > 0) {
        ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    //set resource limit/count information for the project (by getting the info of the project's account)
    Account account = _accountDao.findByIdIncludingRemoved(proj.getProjectAccountId());
    AccountJoinVO accountJn = ApiDBUtils.newAccountView(account);
    _accountJoinDao.setResourceLimits(accountJn, false, response);
    response.setProjectAccountName(accountJn.getAccountName());
    response.setObjectName("project");
    return response;
}
Also used : Account(com.cloud.user.Account) ProjectResponse(org.apache.cloudstack.api.response.ProjectResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO)

Example 2 with AccountJoinVO

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

the class QueryManagerImpl method searchForAccounts.

@Override
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd) {
    Pair<List<AccountJoinVO>, Integer> result = searchForAccountsInternal(cmd);
    ListResponse<AccountResponse> response = new ListResponse<AccountResponse>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListAccountsCmdByAdmin) {
        respView = ResponseView.Full;
    }
    List<AccountResponse> accountResponses = ViewResponseHelper.createAccountResponse(respView, result.first().toArray(new AccountJoinVO[result.first().size()]));
    response.setResponses(accountResponses, result.second());
    return response;
}
Also used : ResponseView(org.apache.cloudstack.api.ResponseObject.ResponseView) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) ProjectAccountResponse(org.apache.cloudstack.api.response.ProjectAccountResponse) AccountResponse(org.apache.cloudstack.api.response.AccountResponse) ListAccountsCmdByAdmin(org.apache.cloudstack.api.command.admin.account.ListAccountsCmdByAdmin) ProjectAccountJoinVO(com.cloud.api.query.vo.ProjectAccountJoinVO) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO)

Example 3 with AccountJoinVO

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

the class QueryManagerImpl method searchForAccountsInternal.

private Pair<List<AccountJoinVO>, Integer> searchForAccountsInternal(ListAccountsCmd cmd) {
    Account caller = CallContext.current().getCallingAccount();
    Long domainId = cmd.getDomainId();
    Long accountId = cmd.getId();
    String accountName = cmd.getSearchName();
    boolean isRecursive = cmd.isRecursive();
    boolean listAll = cmd.listAll();
    Boolean listForDomain = false;
    if (accountId != null) {
        Account account = _accountDao.findById(accountId);
        if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
            throw new InvalidParameterValueException("Unable to find account by id " + accountId);
        }
        _accountMgr.checkAccess(caller, null, true, account);
    }
    if (domainId != null) {
        Domain domain = _domainDao.findById(domainId);
        if (domain == null) {
            throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
        }
        _accountMgr.checkAccess(caller, domain);
        if (accountName != null) {
            Account account = _accountDao.findActiveAccount(accountName, domainId);
            if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
                throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain " + domainId);
            }
            _accountMgr.checkAccess(caller, null, true, account);
        }
    }
    if (accountId == null) {
        if (_accountMgr.isAdmin(caller.getId()) && listAll && domainId == null) {
            listForDomain = true;
            isRecursive = true;
            if (domainId == null) {
                domainId = caller.getDomainId();
            }
        } else if (_accountMgr.isAdmin(caller.getId()) && domainId != null) {
            listForDomain = true;
        } else {
            accountId = caller.getAccountId();
        }
    }
    Filter searchFilter = new Filter(AccountJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    Object type = cmd.getAccountType();
    Object state = cmd.getState();
    Object isCleanupRequired = cmd.isCleanupRequired();
    Object keyword = cmd.getKeyword();
    SearchBuilder<AccountJoinVO> sb = _accountJoinDao.createSearchBuilder();
    sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.EQ);
    sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
    sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
    sb.and("needsCleanup", sb.entity().isNeedsCleanup(), SearchCriteria.Op.EQ);
    sb.and("typeNEQ", sb.entity().getType(), SearchCriteria.Op.NEQ);
    sb.and("idNEQ", sb.entity().getId(), SearchCriteria.Op.NEQ);
    if (listForDomain && isRecursive) {
        sb.and("path", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE);
    }
    SearchCriteria<AccountJoinVO> sc = sb.create();
    sc.setParameters("idNEQ", Account.ACCOUNT_ID_SYSTEM);
    if (keyword != null) {
        SearchCriteria<AccountJoinVO> ssc = _accountJoinDao.createSearchCriteria();
        ssc.addOr("accountName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("accountName", SearchCriteria.Op.SC, ssc);
    }
    if (type != null) {
        sc.setParameters("type", type);
    }
    if (state != null) {
        sc.setParameters("state", state);
    }
    if (isCleanupRequired != null) {
        sc.setParameters("needsCleanup", isCleanupRequired);
    }
    if (accountName != null) {
        sc.setParameters("accountName", accountName);
    }
    // don't return account of type project to the end user
    sc.setParameters("typeNEQ", 5);
    if (accountId != null) {
        sc.setParameters("id", accountId);
    }
    if (listForDomain) {
        if (isRecursive) {
            Domain domain = _domainDao.findById(domainId);
            sc.setParameters("path", domain.getPath() + "%");
        } else {
            sc.setParameters("domainId", domainId);
        }
    }
    return _accountJoinDao.searchAndCount(sc, searchFilter);
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) Domain(com.cloud.domain.Domain) ProjectAccountJoinVO(com.cloud.api.query.vo.ProjectAccountJoinVO) UserAccountJoinVO(com.cloud.api.query.vo.UserAccountJoinVO) AccountJoinVO(com.cloud.api.query.vo.AccountJoinVO)

Aggregations

AccountJoinVO (com.cloud.api.query.vo.AccountJoinVO)3 ProjectAccountJoinVO (com.cloud.api.query.vo.ProjectAccountJoinVO)2 UserAccountJoinVO (com.cloud.api.query.vo.UserAccountJoinVO)2 Account (com.cloud.user.Account)2 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)1 Domain (com.cloud.domain.Domain)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)1 Filter (com.cloud.utils.db.Filter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)1 ListAccountsCmdByAdmin (org.apache.cloudstack.api.command.admin.account.ListAccountsCmdByAdmin)1 AccountResponse (org.apache.cloudstack.api.response.AccountResponse)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 ProjectAccountResponse (org.apache.cloudstack.api.response.ProjectAccountResponse)1 ProjectResponse (org.apache.cloudstack.api.response.ProjectResponse)1