CLOUDSTACK-3080: listVirtualMachines tag search refinement no longer

working.
This commit is contained in:
Min Chen 2013-06-20 15:26:07 -07:00
parent bbfd123a26
commit d3c181efa7
1 changed files with 21 additions and 52 deletions

View File

@ -702,14 +702,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ);
}
if (tags != null && !tags.isEmpty()) {
for (int count=0; count < tags.size(); count++) {
sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ);
sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ);
sb.cp();
}
}
if (networkId != null) {
sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
}
@ -729,12 +721,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (tags != null && !tags.isEmpty()) {
int count = 0;
SearchCriteria<UserVmJoinVO> tagSc = _userVmJoinDao.createSearchCriteria();
for (String key : tags.keySet()) {
sc.setParameters("key" + String.valueOf(count), key);
sc.setParameters("value" + String.valueOf(count), tags.get(key));
count++;
SearchCriteria<UserVmJoinVO> tsc = _userVmJoinDao.createSearchCriteria();
tsc.addAnd("tagKey", SearchCriteria.Op.EQ, key);
tsc.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key));
tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc);
}
sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc);
}
if (groupId != null && (Long)groupId != -1) {
@ -878,13 +872,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
if (tags != null && !tags.isEmpty()) {
for (int count=0; count < tags.size(); count++) {
sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ);
sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ);
sb.cp();
}
}
SearchCriteria<SecurityGroupJoinVO> sc = sb.create();
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
@ -894,14 +881,16 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
SearchCriteria<SecurityGroupJoinVO> tagSc = _securityGroupJoinDao.createSearchCriteria();
for (String key : tags.keySet()) {
sc.setParameters("key" + String.valueOf(count), key);
sc.setParameters("value" + String.valueOf(count), tags.get(key));
count++;
SearchCriteria<SecurityGroupJoinVO> tsc = _securityGroupJoinDao.createSearchCriteria();
tsc.addAnd("tagKey", SearchCriteria.Op.EQ, key);
tsc.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key));
tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc);
}
sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc);
}
if (securityGroup != null) {
sc.setParameters("name", securityGroup);
}
@ -1159,13 +1148,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
}
if (tags != null && !tags.isEmpty()) {
for (int count = 0; count < tags.size(); count++) {
sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ);
sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ);
sb.cp();
}
}
SearchCriteria<ProjectJoinVO> sc = sb.create();
@ -1204,14 +1187,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sc.setParameters("domainPath", path);
}
if (tags != null && !tags.isEmpty()) {
int count = 0;
for (String key : tags.keySet()) {
sc.setParameters("key" + String.valueOf(count), key);
sc.setParameters("value" + String.valueOf(count), tags.get(key));
count++;
}
}
// search distinct projects to get count
Pair<List<ProjectJoinVO>, Integer> uniquePrjPair = _projectJoinDao.searchAndCount(sc, searchFilter);
@ -1529,15 +1505,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sb.or("nulltype", sb.entity().getVmType(), SearchCriteria.Op.NULL);
sb.cp();
if (tags != null && !tags.isEmpty()) {
for (int count=0; count < tags.size(); count++) {
sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ);
sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ);
sb.cp();
}
}
// now set the SC criteria...
SearchCriteria<VolumeJoinVO> sc = sb.create();
@ -1558,12 +1525,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sc.setParameters("systemUse", 1);
if (tags != null && !tags.isEmpty()) {
int count = 0;
SearchCriteria<VolumeJoinVO> tagSc = _volumeJoinDao.createSearchCriteria();
for (String key : tags.keySet()) {
sc.setParameters("key" + String.valueOf(count), key);
sc.setParameters("value" + String.valueOf(count), tags.get(key));
count++;
SearchCriteria<VolumeJoinVO> tsc = _volumeJoinDao.createSearchCriteria();
tsc.addAnd("tagKey", SearchCriteria.Op.EQ, key);
tsc.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key));
tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc);
}
sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc);
}
if (id != null) {