_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal());
//Criteria c = new Criteria(null, Boolean.FALSE, cmd.getStartIndex(), cmd.getPageSizeVal()); //version without default sorting
c.addCriteria(Criteria.KEYWORD, cmd.getKeyword());
c.addCriteria(Criteria.ID, cmd.getId());
c.addCriteria(Criteria.NAME, cmd.getInstanceName());
c.addCriteria(Criteria.STATE, cmd.getState());
c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId());
c.addCriteria(Criteria.GROUPID, cmd.getGroupId());
c.addCriteria(Criteria.FOR_VIRTUAL_NETWORK, cmd.getForVirtualNetwork());
c.addCriteria(Criteria.NETWORKID, cmd.getNetworkId());
c.addCriteria(Criteria.TEMPLATE_ID, cmd.getTemplateId());
c.addCriteria(Criteria.ISO_ID, cmd.getIsoId());
c.addCriteria(Criteria.VPC_ID, cmd.getVpcId());
if (domainId != null) {
c.addCriteria(Criteria.DOMAINID, domainId);
}
if (HypervisorType.getType(hypervisor) != HypervisorType.None) {
c.addCriteria(Criteria.HYPERVISOR, hypervisor);
} else if (hypervisor != null) {
throw new InvalidParameterValueException("Invalid HypervisorType " + hypervisor);
}
// ignore these search requests if it's not an admin
if (_accountMgr.isAdmin(caller.getType())) {
c.addCriteria(Criteria.PODID, cmd.getPodId());
c.addCriteria(Criteria.HOSTID, cmd.getHostId());
c.addCriteria(Criteria.STORAGE_ID, cmd.getStorageId());
}
if (!permittedAccounts.isEmpty()) {
c.addCriteria(Criteria.ACCOUNTID, permittedAccounts.toArray());
}
c.addCriteria(Criteria.ISADMIN, _accountMgr.isAdmin(caller.getType()));
return searchForUserVMsByCriteria(c, caller, domainId, isRecursive,
permittedAccounts, listAll, listProjectResourcesCriteria, tags);
}