Skip to content

Commit 09c324f

Browse files
Added tags support to listDomains API
1 parent 0f9fb0d commit 09c324f

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.apache.cloudstack.api.APICommand;
2424
import org.apache.cloudstack.api.ApiConstants;
2525
import org.apache.cloudstack.api.ApiConstants.DomainDetails;
26-
import org.apache.cloudstack.api.BaseListCmd;
26+
import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
2727
import org.apache.cloudstack.api.Parameter;
2828
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2929
import org.apache.cloudstack.api.command.user.UserCmd;
@@ -39,7 +39,7 @@
3939

4040
@APICommand(name = "listDomains", description = "Lists domains and provides detailed information for listed domains", responseObject = DomainResponse.class, responseView = ResponseView.Restricted, entityType = {Domain.class},
4141
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
42-
public class ListDomainsCmd extends BaseListCmd implements UserCmd {
42+
public class ListDomainsCmd extends BaseListTaggedResourcesCmd implements UserCmd {
4343

4444
private static final String s_name = "listdomainsresponse";
4545

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,6 +2860,7 @@ private Pair<List<Long>, Integer> searchForDomainIdsAndCount(ListDomainsCmd cmd)
28602860
boolean listAll = cmd.listAll();
28612861
boolean isRecursive = false;
28622862
Domain domain = null;
2863+
Map<String, String> tags = cmd.getTags();
28632864

28642865
if (domainId != null) {
28652866
domain = _domainDao.findById(domainId);
@@ -2889,6 +2890,24 @@ private Pair<List<Long>, Integer> searchForDomainIdsAndCount(ListDomainsCmd cmd)
28892890
domainSearchBuilder.and("path", domainSearchBuilder.entity().getPath(), SearchCriteria.Op.LIKE);
28902891
domainSearchBuilder.and("state", domainSearchBuilder.entity().getState(), SearchCriteria.Op.EQ);
28912892

2893+
if (MapUtils.isNotEmpty(tags)) {
2894+
SearchBuilder<ResourceTagVO> resourceTagSearch = resourceTagDao.createSearchBuilder();
2895+
resourceTagSearch.and("resourceType", resourceTagSearch.entity().getResourceType(), Op.EQ);
2896+
resourceTagSearch.and().op();
2897+
for (int count = 0; count < tags.size(); count++) {
2898+
if (count == 0) {
2899+
resourceTagSearch.op("tagKey" + count, resourceTagSearch.entity().getKey(), Op.EQ);
2900+
} else {
2901+
resourceTagSearch.or().op("tagKey" + count, resourceTagSearch.entity().getKey(), Op.EQ);
2902+
}
2903+
resourceTagSearch.and("tagValue" + count, resourceTagSearch.entity().getValue(), Op.EQ);
2904+
resourceTagSearch.cp();
2905+
}
2906+
resourceTagSearch.cp();
2907+
2908+
domainSearchBuilder.join("tags", resourceTagSearch, resourceTagSearch.entity().getResourceId(), domainSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
2909+
}
2910+
28922911
if (keyword != null) {
28932912
domainSearchBuilder.and("keywordName", domainSearchBuilder.entity().getName(), SearchCriteria.Op.LIKE);
28942913
}
@@ -2918,6 +2937,16 @@ private Pair<List<Long>, Integer> searchForDomainIdsAndCount(ListDomainsCmd cmd)
29182937
}
29192938
}
29202939

2940+
if (MapUtils.isNotEmpty(tags)) {
2941+
int count = 0;
2942+
sc.setJoinParameters("tags", "resourceType", ResourceObjectType.Domain);
2943+
for (Map.Entry<String, String> entry : tags.entrySet()) {
2944+
sc.setJoinParameters("tags", "tagKey" + count, entry.getKey());
2945+
sc.setJoinParameters("tags", "tagValue" + count, entry.getValue());
2946+
count++;
2947+
}
2948+
}
2949+
29212950
// return only Active domains to the API
29222951
sc.setParameters("state", Domain.State.Active);
29232952

0 commit comments

Comments
 (0)