|
27 | 27 | import javax.inject.Inject; |
28 | 28 | import javax.naming.ConfigurationException; |
29 | 29 |
|
| 30 | +import org.apache.cloudstack.api.ApiConstants; |
| 31 | +import org.apache.commons.collections.MapUtils; |
30 | 32 | import org.apache.log4j.Logger; |
31 | 33 | import org.springframework.stereotype.Component; |
32 | 34 | import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd; |
@@ -237,27 +239,27 @@ public Pair<List<? extends VMSnapshot>, Integer> listVMSnapshots(ListVMSnapshotC |
237 | 239 | sb.and("display_name", sb.entity().getDisplayName(), SearchCriteria.Op.EQ); |
238 | 240 | sb.and("account_id", sb.entity().getAccountId(), SearchCriteria.Op.EQ); |
239 | 241 |
|
240 | | - if (tags != null && !tags.isEmpty()) { |
| 242 | + if (MapUtils.isNotEmpty(tags)) { |
241 | 243 | SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder(); |
242 | 244 | for (int count = 0; count < tags.size(); count++) { |
243 | | - tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ); |
244 | | - tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ); |
| 245 | + tagSearch.or().op(ApiConstants.KEY + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ); |
| 246 | + tagSearch.and(ApiConstants.VALUE + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ); |
245 | 247 | tagSearch.cp(); |
246 | 248 | } |
247 | | - tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); |
| 249 | + tagSearch.and(ApiConstants.RESOURCE_TYPE, tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); |
248 | 250 | sb.groupBy(sb.entity().getId()); |
249 | 251 | sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); |
250 | 252 | } |
251 | 253 |
|
252 | 254 | SearchCriteria<VMSnapshotVO> sc = sb.create(); |
253 | 255 | _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); |
254 | 256 |
|
255 | | - if (tags != null && !tags.isEmpty()) { |
| 257 | + if (MapUtils.isNotEmpty(tags)) { |
256 | 258 | int count = 0; |
257 | | - sc.setJoinParameters("tagSearch", "resourceType", ResourceTag.ResourceObjectType.VMSnapshot.toString()); |
| 259 | + sc.setJoinParameters("tagSearch", ApiConstants.RESOURCE_TYPE, ResourceTag.ResourceObjectType.VMSnapshot.toString()); |
258 | 260 | for (String key : tags.keySet()) { |
259 | | - sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key); |
260 | | - sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key)); |
| 261 | + sc.setJoinParameters("tagSearch", ApiConstants.KEY + String.valueOf(count), key); |
| 262 | + sc.setJoinParameters("tagSearch", ApiConstants.VALUE + String.valueOf(count), tags.get(key)); |
261 | 263 | count++; |
262 | 264 | } |
263 | 265 | } |
|
0 commit comments