|
5 | 5 | import java.util.List; |
6 | 6 | import java.util.Objects; |
7 | 7 | import java.util.Optional; |
| 8 | +import java.util.stream.Collectors; |
8 | 9 | import java.util.stream.Stream; |
9 | 10 |
|
10 | 11 | import javax.ws.rs.core.Form; |
@@ -1306,9 +1307,24 @@ public void deleteGpgKey(final Integer userId, final Integer keyId) throws GitLa |
1306 | 1307 | * @throws GitLabApiException if any exception occurs |
1307 | 1308 | * @since GitLab 12.8 |
1308 | 1309 | */ |
1309 | | - public List<Membership> getMemberships(Integer userId) throws GitLabApiException { |
| 1310 | + public List<Membership> getMemberships(int userId) throws GitLabApiException { |
| 1311 | + return getMembershipsPager(userId).stream().collect(Collectors.toList()); |
| 1312 | + } |
| 1313 | + |
| 1314 | + /** |
| 1315 | + * Returns a Pager that lists all projects and groups a user is a member of. (admin only) |
| 1316 | + * |
| 1317 | + * This allows lazy-fetching of huge numbers of memberships. |
| 1318 | + * |
| 1319 | + * <pre><code>GitLab Endpoint: GET /users/:id/memberships</code></pre> |
| 1320 | + * |
| 1321 | + * @param userId the ID of the user to get the memberships for |
| 1322 | + * @return the list of memberships of the given user |
| 1323 | + * @throws GitLabApiException if any exception occurs |
| 1324 | + * @since GitLab 12.8 |
| 1325 | + */ |
| 1326 | + public Pager<Membership> getMembershipsPager(int userId) throws GitLabApiException { |
1310 | 1327 | GitLabApiForm formData = new GitLabApiForm(); |
1311 | | - Response response = get(Response.Status.OK, formData.asMap(), "users", userId, "memberships"); |
1312 | | - return (response.readEntity(new GenericType<List<Membership>>() {})); |
| 1328 | + return (new Pager<>(this, Membership.class, 100, formData.asMap(), "users", userId, "memberships")); |
1313 | 1329 | } |
1314 | 1330 | } |
0 commit comments