diff options
author | Anthony Chin <anthony.a.chin@ericsson.com> | 2014-04-10 11:14:41 -0400 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2014-04-16 21:20:02 +0900 |
commit | dc78329e347abed59247dd7e3846d5996bc5a1ee (patch) | |
tree | e9aad201cfd5ee3594f13fd56d06578a3bc66b47 | |
parent | e3ba9e44e69fdedf6bcea1725d6682fa9e599296 (diff) |
Add option 'n' and 'S' to groups REST API to limit group results.
List groups endpoint now has an option to limit the number of results
returned and a start to define nonzero offset in order to support
groups pagination.
Add and document 'n' and 'S' function to allow query group list from
a specified limit and start.
Both options will then be used to render group list with pagination
in web UI.
Change-Id: Ibf244b1cfe83c56dc1c23aabf70a55697b52c835
-rw-r--r-- | Documentation/rest-api-groups.txt | 18 | ||||
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/group/ListGroups.java | 22 |
2 files changed, 40 insertions, 0 deletions
diff --git a/Documentation/rest-api-groups.txt b/Documentation/rest-api-groups.txt index 6289e5a419..2f73fc7deb 100644 --- a/Documentation/rest-api-groups.txt +++ b/Documentation/rest-api-groups.txt @@ -165,6 +165,24 @@ returned. } ---- +[[group-limit]] +==== Group Limit +The `/groups/` URL also accepts a limit integer in the `n` parameter. +This limits the results to show `n` groups. + +Query the first 25 groups in group list. +---- + GET /groups/?n=25 HTTP/1.0 +---- + +The `/groups/` URL also accepts a start integer in the `S` parameter. +The results will skip `S` groups from group list. + +Query 25 groups starting from index 50. +---- + GET /groups/?n=25&S=50 HTTP/1.0 +---- + [[get-group]] Get Group ~~~~~~~~~ diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/group/ListGroups.java b/gerrit-server/src/main/java/com/google/gerrit/server/group/ListGroups.java index 03ec06722a..4764e41831 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/group/ListGroups.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/group/ListGroups.java @@ -93,6 +93,12 @@ public class ListGroups implements RestReadView<TopLevelResource> { groupsToInspect.add(id); } + @Option(name = "--limit", aliases = {"-n"}, metaVar = "CNT", usage = "maximum number of groups to list") + private int limit; + + @Option(name = "-S", metaVar = "CNT", usage = "number of groups to skip") + private int start; + @Option(name = "-m", metaVar = "MATCH", usage = "match group substring") private String matchSubstring; @@ -175,7 +181,15 @@ public class ListGroups implements RestReadView<TopLevelResource> { groupList = filterGroups(groupCache.all()); } groupInfos = Lists.newArrayListWithCapacity(groupList.size()); + int found = 0; + int foundIndex = 0; for (AccountGroup group : groupList) { + if (foundIndex++ < start) { + continue; + } + if (limit > 0 && ++found > limit) { + break; + } groupInfos.add(json.addOptions(options).format( GroupDescriptions.forAccountGroup(group))); } @@ -187,11 +201,19 @@ public class ListGroups implements RestReadView<TopLevelResource> { private List<GroupInfo> getGroupsOwnedBy(IdentifiedUser user) throws OrmException { List<GroupInfo> groups = Lists.newArrayList(); + int found = 0; + int foundIndex = 0; for (AccountGroup g : filterGroups(groupCache.all())) { GroupControl ctl = groupControlFactory.controlFor(g); try { if (genericGroupControlFactory.controlFor(user, g.getGroupUUID()) .isOwner()) { + if (foundIndex++ < start) { + continue; + } + if (limit > 0 && ++found > limit) { + break; + } groups.add(json.addOptions(options).format(ctl.getGroup())); } } catch (NoSuchGroupException e) { |