Consider other conditions while listing templates with id (#4452)

This commit is contained in:
Rakesh 2020-11-17 20:03:49 +01:00 committed by GitHub
parent e24a7b13dc
commit 2f5ed9eee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3443,11 +3443,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
domain = _domainDao.findById(Domain.ROOT_DOMAIN); domain = _domainDao.findById(Domain.ROOT_DOMAIN);
} }
// List<HypervisorType> hypers = null;
// if (!isIso) {
// hypers = _resourceMgr.listAvailHypervisorInZone(null, null);
// }
setIdsListToSearchCriteria(sc, ids); setIdsListToSearchCriteria(sc, ids);
// add criteria for project or not // add criteria for project or not
@ -3495,17 +3490,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
} }
} }
if (!isIso) {
// add hypervisor criteria for template case
if (hypers != null && !hypers.isEmpty()) {
String[] relatedHypers = new String[hypers.size()];
for (int i = 0; i < hypers.size(); i++) {
relatedHypers[i] = hypers.get(i).toString();
}
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, relatedHypers);
}
}
// control different template filters // control different template filters
if (templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community) { if (templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community) {
sc.addAnd("publicTemplate", SearchCriteria.Op.EQ, true); sc.addAnd("publicTemplate", SearchCriteria.Op.EQ, true);
@ -3548,6 +3532,27 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
} }
sc.addAnd("publicTemplate", SearchCriteria.Op.SC, scc); sc.addAnd("publicTemplate", SearchCriteria.Op.SC, scc);
} }
}
return templateChecks(isIso, hypers, tags, name, keyword, hyperType, onlyReady, bootable, zoneId, showDomr,
showRemovedTmpl, parentTemplateId, showUnique, searchFilter, sc);
}
private Pair<List<TemplateJoinVO>, Integer> templateChecks(boolean isIso, List<HypervisorType> hypers, Map<String, String> tags, String name, String keyword,
HypervisorType hyperType, boolean onlyReady, Boolean bootable, Long zoneId, boolean showDomr,
boolean showRemovedTmpl, Long parentTemplateId, Boolean showUnique,
Filter searchFilter, SearchCriteria<TemplateJoinVO> sc) {
if (!isIso) {
// add hypervisor criteria for template case
if (hypers != null && !hypers.isEmpty()) {
String[] relatedHypers = new String[hypers.size()];
for (int i = 0; i < hypers.size(); i++) {
relatedHypers[i] = hypers.get(i).toString();
}
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, relatedHypers);
}
}
// add tags criteria // add tags criteria
if (tags != null && !tags.isEmpty()) { if (tags != null && !tags.isEmpty()) {
@ -3574,12 +3579,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sc.addAnd("name", SearchCriteria.Op.EQ, name); sc.addAnd("name", SearchCriteria.Op.EQ, name);
} }
if (isIso) { SearchCriteria.Op op = isIso ? Op.EQ : Op.NEQ;
sc.addAnd("format", SearchCriteria.Op.EQ, "ISO"); sc.addAnd("format", op, "ISO");
} else {
sc.addAnd("format", SearchCriteria.Op.NEQ, "ISO");
}
if (!hyperType.equals(HypervisorType.None)) { if (!hyperType.equals(HypervisorType.None)) {
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hyperType); sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hyperType);
@ -3604,7 +3605,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// excluding system template // excluding system template
sc.addAnd("templateType", SearchCriteria.Op.NEQ, Storage.TemplateType.SYSTEM); sc.addAnd("templateType", SearchCriteria.Op.NEQ, Storage.TemplateType.SYSTEM);
} }
}
if (zoneId != null) { if (zoneId != null) {
SearchCriteria<TemplateJoinVO> zoneSc = _templateJoinDao.createSearchCriteria(); SearchCriteria<TemplateJoinVO> zoneSc = _templateJoinDao.createSearchCriteria();
@ -3648,7 +3648,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// VMTemplateDaoImpl.searchForTemplates and understand why we need to // VMTemplateDaoImpl.searchForTemplates and understand why we need to
// specially handle ISO. The original logic is very twisted and no idea // specially handle ISO. The original logic is very twisted and no idea
// about what the code was doing. // about what the code was doing.
} }
// findTemplatesByIdOrTempZonePair returns the templates with the given ids if showUnique is true, or else by the TempZonePair // findTemplatesByIdOrTempZonePair returns the templates with the given ids if showUnique is true, or else by the TempZonePair