Skip to content

Commit f79dc4e

Browse files
author
Pearl Dsilva
committed
Review comments
1 parent ffc6e7b commit f79dc4e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import javax.inject.Inject;
2828
import javax.naming.ConfigurationException;
2929

30+
import org.apache.cloudstack.api.ApiConstants;
31+
import org.apache.commons.collections.MapUtils;
3032
import org.apache.log4j.Logger;
3133
import org.springframework.stereotype.Component;
3234
import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd;
@@ -237,27 +239,27 @@ public Pair<List<? extends VMSnapshot>, Integer> listVMSnapshots(ListVMSnapshotC
237239
sb.and("display_name", sb.entity().getDisplayName(), SearchCriteria.Op.EQ);
238240
sb.and("account_id", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
239241

240-
if (tags != null && !tags.isEmpty()) {
242+
if (MapUtils.isNotEmpty(tags)) {
241243
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
242244
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);
245247
tagSearch.cp();
246248
}
247-
tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
249+
tagSearch.and(ApiConstants.RESOURCE_TYPE, tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
248250
sb.groupBy(sb.entity().getId());
249251
sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
250252
}
251253

252254
SearchCriteria<VMSnapshotVO> sc = sb.create();
253255
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
254256

255-
if (tags != null && !tags.isEmpty()) {
257+
if (MapUtils.isNotEmpty(tags)) {
256258
int count = 0;
257-
sc.setJoinParameters("tagSearch", "resourceType", ResourceTag.ResourceObjectType.VMSnapshot.toString());
259+
sc.setJoinParameters("tagSearch", ApiConstants.RESOURCE_TYPE, ResourceTag.ResourceObjectType.VMSnapshot.toString());
258260
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));
261263
count++;
262264
}
263265
}

0 commit comments

Comments
 (0)