Search in sources :

Example 1 with AsyncJobJoinVO

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

the class QueryManagerImpl method searchForAsyncJobsInternal.

private Pair<List<AsyncJobJoinVO>, Integer> searchForAsyncJobsInternal(ListAsyncJobsCmd cmd) {
    Account caller = CallContext.current().getCallingAccount();
    List<Long> permittedAccounts = new ArrayList<Long>();
    Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
    _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), null, permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
    Long domainId = domainIdRecursiveListProject.first();
    Boolean isRecursive = domainIdRecursiveListProject.second();
    ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    Filter searchFilter = new Filter(AsyncJobJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    SearchBuilder<AsyncJobJoinVO> sb = _jobJoinDao.createSearchBuilder();
    sb.and("accountIdIN", sb.entity().getAccountId(), SearchCriteria.Op.IN);
    boolean accountJoinIsDone = false;
    if (permittedAccounts.isEmpty() && domainId != null) {
        sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
        sb.and("path", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE);
        accountJoinIsDone = true;
    }
    if (listProjectResourcesCriteria != null) {
        if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
            sb.and("type", sb.entity().getAccountType(), SearchCriteria.Op.EQ);
        } else if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
            sb.and("type", sb.entity().getAccountType(), SearchCriteria.Op.NEQ);
        }
        if (!accountJoinIsDone) {
            sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
            sb.and("path", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE);
        }
    }
    Object keyword = cmd.getKeyword();
    Object startDate = cmd.getStartDate();
    SearchCriteria<AsyncJobJoinVO> sc = sb.create();
    if (listProjectResourcesCriteria != null) {
        sc.setParameters("type", Account.ACCOUNT_TYPE_PROJECT);
    }
    if (!permittedAccounts.isEmpty()) {
        sc.setParameters("accountIdIN", permittedAccounts.toArray());
    } else if (domainId != null) {
        DomainVO domain = _domainDao.findById(domainId);
        if (isRecursive) {
            sc.setParameters("path", domain.getPath() + "%");
        } else {
            sc.setParameters("domainId", domainId);
        }
    }
    if (keyword != null) {
        sc.addAnd("cmd", SearchCriteria.Op.LIKE, "%" + keyword + "%");
    }
    if (startDate != null) {
        sc.addAnd("created", SearchCriteria.Op.GTEQ, startDate);
    }
    return _jobJoinDao.searchAndCount(sc, searchFilter);
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) DomainVO(com.cloud.domain.DomainVO) AsyncJobJoinVO(com.cloud.api.query.vo.AsyncJobJoinVO) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter)

Aggregations

AsyncJobJoinVO (com.cloud.api.query.vo.AsyncJobJoinVO)1 DomainVO (com.cloud.domain.DomainVO)1 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)1 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)1 Account (com.cloud.user.Account)1 Ternary (com.cloud.utils.Ternary)1 Filter (com.cloud.utils.db.Filter)1 ArrayList (java.util.ArrayList)1