Search in sources :

Example 1 with DomainJoinVO

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

the class QueryManagerImpl method searchForDomainsInternal.

private Pair<List<DomainJoinVO>, Integer> searchForDomainsInternal(ListDomainsCmd cmd) {
    Account caller = CallContext.current().getCallingAccount();
    Long domainId = cmd.getId();
    boolean listAll = cmd.listAll();
    boolean isRecursive = false;
    if (domainId != null) {
        Domain domain = _domainDao.findById(domainId);
        if (domain == null) {
            throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
        }
        _accountMgr.checkAccess(caller, domain);
    } else {
        if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
            domainId = caller.getDomainId();
        }
        if (listAll) {
            isRecursive = true;
        }
    }
    Filter searchFilter = new Filter(DomainJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    String domainName = cmd.getDomainName();
    Integer level = cmd.getLevel();
    Object keyword = cmd.getKeyword();
    SearchBuilder<DomainJoinVO> sb = _domainJoinDao.createSearchBuilder();
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
    sb.and("level", sb.entity().getLevel(), SearchCriteria.Op.EQ);
    sb.and("path", sb.entity().getPath(), SearchCriteria.Op.LIKE);
    sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
    SearchCriteria<DomainJoinVO> sc = sb.create();
    if (keyword != null) {
        SearchCriteria<DomainJoinVO> ssc = _domainJoinDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (domainName != null) {
        sc.setParameters("name", domainName);
    }
    if (level != null) {
        sc.setParameters("level", level);
    }
    if (domainId != null) {
        if (isRecursive) {
            sc.setParameters("path", _domainDao.findById(domainId).getPath() + "%");
        } else {
            sc.setParameters("id", domainId);
        }
    }
    // return only Active domains to the API
    sc.setParameters("state", Domain.State.Active);
    return _domainJoinDao.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) DomainJoinVO(com.cloud.api.query.vo.DomainJoinVO)

Example 2 with DomainJoinVO

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

the class QueryManagerImpl method searchForDomains.

@Override
public ListResponse<DomainResponse> searchForDomains(ListDomainsCmd cmd) {
    Pair<List<DomainJoinVO>, Integer> result = searchForDomainsInternal(cmd);
    ListResponse<DomainResponse> response = new ListResponse<DomainResponse>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListDomainsCmdByAdmin) {
        respView = ResponseView.Full;
    }
    List<DomainResponse> domainResponses = ViewResponseHelper.createDomainResponse(respView, result.first().toArray(new DomainJoinVO[result.first().size()]));
    response.setResponses(domainResponses, result.second());
    return response;
}
Also used : ResponseView(org.apache.cloudstack.api.ResponseObject.ResponseView) ListResponse(org.apache.cloudstack.api.response.ListResponse) ListDomainsCmdByAdmin(org.apache.cloudstack.api.command.admin.domain.ListDomainsCmdByAdmin) DomainResponse(org.apache.cloudstack.api.response.DomainResponse) ArrayList(java.util.ArrayList) List(java.util.List) DomainJoinVO(com.cloud.api.query.vo.DomainJoinVO)

Aggregations

DomainJoinVO (com.cloud.api.query.vo.DomainJoinVO)2 Domain (com.cloud.domain.Domain)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)1 Account (com.cloud.user.Account)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 ListDomainsCmdByAdmin (org.apache.cloudstack.api.command.admin.domain.ListDomainsCmdByAdmin)1 DomainResponse (org.apache.cloudstack.api.response.DomainResponse)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1