// check the parent, if not null, add zones for that parent to
// list
// find all domain Id up to root domain for this account
List<Long> domainIds = new ArrayList<Long>();
DomainVO domainRecord = _domainDao.findById(account.getDomainId());
if (domainRecord == null) {
s_logger.error("Could not find the domainId for account:" + account.getAccountName());
throw new CloudAuthenticationException("Could not find the domainId for account:"
+ account.getAccountName());
}
domainIds.add(domainRecord.getId());
while (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
domainIds.add(domainRecord.getId());
}
// domainId == null (public zones) or domainId IN [all domain id
// up to root domain]
SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();
sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds.toArray());
sdc.addOr("domainId", SearchCriteria.Op.NULL);
sc.addAnd("domain", SearchCriteria.Op.SC, sdc);
// remove disabled zones
sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled);
// accountId == null (zones dedicated to a domain) or
// accountId = caller
SearchCriteria<DataCenterJoinVO> sdc2 = _dcJoinDao.createSearchCriteria();
sdc2.addOr("accountId", SearchCriteria.Op.EQ, account.getId());
sdc2.addOr("accountId", SearchCriteria.Op.NULL);
sc.addAnd("account", SearchCriteria.Op.SC, sdc2);
// remove Dedicated zones not dedicated to this domainId or
// subdomainId
List<Long> dedicatedZoneIds = removeDedicatedZoneNotSuitabe(domainIds);
if (!dedicatedZoneIds.isEmpty()) {
sdc.addAnd("id", SearchCriteria.Op.NIN,
dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()]));
}
} else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN
|| account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
// it was decided to return all zones for the domain admin, and
// everything above till root, as well as zones till the domain
// leaf
List<Long> domainIds = new ArrayList<Long>();
DomainVO domainRecord = _domainDao.findById(account.getDomainId());
if (domainRecord == null) {
s_logger.error("Could not find the domainId for account:" + account.getAccountName());
throw new CloudAuthenticationException("Could not find the domainId for account:"
+ account.getAccountName());
}
domainIds.add(domainRecord.getId());
// find all domain Ids till leaf
List<DomainVO> allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(),
domainRecord.getId());
for (DomainVO domain : allChildDomains) {
domainIds.add(domain.getId());
}
// then find all domain Id up to root domain for this account
while (domainRecord.getParent() != null) {
domainRecord = _domainDao.findById(domainRecord.getParent());
domainIds.add(domainRecord.getId());
}
// domainId == null (public zones) or domainId IN [all domain id
// up to root domain]
SearchCriteria<DataCenterJoinVO> sdc = _dcJoinDao.createSearchCriteria();