Search in sources :

Example 81 with Domain

use of com.cloud.domain.Domain in project cloudstack by apache.

the class DomainManagerImpl method searchForDomains.

@Override
public Pair<List<? extends Domain>, Integer> searchForDomains(ListDomainsCmd cmd) {
    Account caller = getCaller();
    Long domainId = cmd.getId();
    boolean listAll = cmd.listAll();
    boolean isRecursive = false;
    if (domainId != null) {
        Domain domain = getDomain(domainId);
        if (domain == null) {
            throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
        }
        _accountMgr.checkAccess(caller, domain);
    } else {
        if (!_accountMgr.isRootAdmin(caller.getId())) {
            domainId = caller.getDomainId();
        }
        if (listAll) {
            isRecursive = true;
        }
    }
    Filter searchFilter = new Filter(DomainVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    String domainName = cmd.getDomainName();
    Integer level = cmd.getLevel();
    Object keyword = cmd.getKeyword();
    SearchBuilder<DomainVO> sb = _domainDao.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<DomainVO> sc = sb.create();
    if (keyword != null) {
        SearchCriteria<DomainVO> ssc = _domainDao.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", getDomain(domainId).getPath() + "%");
        } else {
            sc.setParameters("id", domainId);
        }
    }
    // return only Active domains to the API
    sc.setParameters("state", Domain.State.Active);
    Pair<List<DomainVO>, Integer> result = _domainDao.searchAndCount(sc, searchFilter);
    return new Pair<List<? extends Domain>, Integer>(result.first(), result.second());
}
Also used : DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Filter(com.cloud.utils.db.Filter) List(java.util.List) Domain(com.cloud.domain.Domain) Pair(com.cloud.utils.Pair)

Aggregations

Domain (com.cloud.domain.Domain)81 Account (com.cloud.user.Account)42 ArrayList (java.util.ArrayList)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 Test (org.junit.Test)20 DeployDestination (com.cloud.deploy.DeployDestination)17 Network (com.cloud.network.Network)17 ReservationContext (com.cloud.vm.ReservationContext)17 DataCenter (com.cloud.dc.DataCenter)16 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)16 NetworkOffering (com.cloud.offering.NetworkOffering)16 HostVO (com.cloud.host.HostVO)15 NetworkVO (com.cloud.network.dao.NetworkVO)15 UserAccount (com.cloud.user.UserAccount)15 URI (java.net.URI)12 DomainVO (com.cloud.domain.DomainVO)11 ProjectAccount (com.cloud.projects.ProjectAccount)11 Project (com.cloud.projects.Project)10 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)8 DB (com.cloud.utils.db.DB)8