From 4123ef02bdce2b0cde675e07972c5c151964181f Mon Sep 17 00:00:00 2001 From: Greg Messner Date: Sat, 15 Dec 2018 13:19:31 -0800 Subject: [PATCH] Added getXxxxx() methods that return Java 8 Streams. --- src/main/java/org/gitlab4j/api/GroupApi.java | 381 ++++++++------ src/main/java/org/gitlab4j/api/IssuesApi.java | 321 ++++++------ src/main/java/org/gitlab4j/api/NotesApi.java | 247 +++++---- .../java/org/gitlab4j/api/ProjectApi.java | 16 +- .../java/org/gitlab4j/api/RepositoryApi.java | 98 +++- src/main/java/org/gitlab4j/api/TagsApi.java | 38 +- src/main/java/org/gitlab4j/api/UserApi.java | 473 ++++++++---------- 7 files changed, 869 insertions(+), 705 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/GroupApi.java b/src/main/java/org/gitlab4j/api/GroupApi.java index 507949ff..9a90e1b5 100644 --- a/src/main/java/org/gitlab4j/api/GroupApi.java +++ b/src/main/java/org/gitlab4j/api/GroupApi.java @@ -3,6 +3,7 @@ package org.gitlab4j.api; import java.util.Date; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import javax.ws.rs.core.Form; import javax.ws.rs.core.GenericType; @@ -28,20 +29,19 @@ public class GroupApi extends AbstractApi { /** * Get a list of groups. (As user: my groups, as admin: all groups) * - * GET /groups + *
GitLab Endpoint: GET /groups
* * @return the list of groups viewable by the authenticated user * @throws GitLabApiException if any exception occurs */ public List getGroups() throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), "groups"); - return (response.readEntity(new GenericType>() {})); + return (getGroups(getDefaultPerPage()).all()); } /** * Get a list of groups (As user: my groups, as admin: all groups) and in the specified page range. * - * GET /groups + *
GitLab Endpoint: GET /groups
* * @param page the page to get * @param perPage the number of Group instances per page @@ -56,7 +56,7 @@ public class GroupApi extends AbstractApi { /** * Get a Pager of groups. (As user: my groups, as admin: all groups) * - * GET /groups + *
GitLab Endpoint: GET /groups
* * @param itemsPerPage the number of Group instances that will be fetched per page * @return the list of groups viewable by the authenticated user @@ -66,6 +66,18 @@ public class GroupApi extends AbstractApi { return (new Pager(this, Group.class, itemsPerPage, null, "groups")); } + /** + * Get a Stream of groups. (As user: my groups, as admin: all groups) + * + *
GitLab Endpoint: GET /groups
+ * + * @return a Stream of groups viewable by the authenticated user + * @throws GitLabApiException if any exception occurs + */ + public Stream getGroupsStream() throws GitLabApiException { + return (getGroups(getDefaultPerPage()).stream()); + } + /** * Get all groups that match your string in their name or path. * @@ -74,9 +86,7 @@ public class GroupApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ public List getGroups(String search) throws GitLabApiException { - Form formData = new GitLabApiForm().withParam("search", search).withParam(PER_PAGE_PARAM, getDefaultPerPage()); - Response response = get(Response.Status.OK, formData.asMap(), "groups"); - return (response.readEntity(new GenericType>() {})); + return (getGroups(search, getDefaultPerPage()).all()); } /** @@ -107,10 +117,21 @@ public class GroupApi extends AbstractApi { return (new Pager(this, Group.class, itemsPerPage, formData.asMap(), "groups")); } + /** + * Get all groups that match your string in their name or path as a Stream. + * + * @param search the group name or path search criteria + * @return a Stream containing matching Group instances + * @throws GitLabApiException if any exception occurs + */ + public Stream getGroupsStream(String search) throws GitLabApiException { + return (getGroups(search, getDefaultPerPage()).stream()); + } + /** * Get a list of visible direct subgroups in this group. * - *

GET /groups/:id/subgroups

+ *
GitLab Endpoint: GET /groups/:id/subgroups
* * @param groupId the group ID to get the sub groups for * @return a List<Group> containing the group's sub-groups @@ -118,13 +139,42 @@ public class GroupApi extends AbstractApi { * @since GitLab 10.3.0 */ public List getSubGroups(Integer groupId) throws GitLabApiException { - return (getSubGroups(groupId, null, null, null, null, null, null, null, 1, getDefaultPerPage())); + return (getSubGroups(groupId, getDefaultPerPage()).all()); + } + + /** + * Get a Pager of visible direct subgroups in this group. + * + *
GitLab Endpoint: GET /groups/:id/subgroups
+ * + * @param groupId the group ID to get the sub groups for + * @param itemsPerPage the number of Group instances that will be fetched per page + * @return a Pager containing matching Group instances + * @throws GitLabApiException if any exception occurs + * @since GitLab 10.3.0 + */ + public Pager getSubGroups(Integer groupId, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, Group.class, itemsPerPage, null, "groups", groupId, "subgroups")); + } + + /** + * Get a Stream of visible direct subgroups in this group. + * + *
GitLab Endpoint: GET /groups/:id/subgroups
+ * + * @param groupId the group ID to get the sub groups for + * @return a Stream<Group> containing the group's sub-groups + * @throws GitLabApiException if any exception occurs + * @since GitLab 10.3.0 + */ + public Stream getSubGroupsStream(Integer groupId) throws GitLabApiException { + return (getSubGroups(groupId, getDefaultPerPage()).stream()); } /** * Get a list of visible direct subgroups in this group. * - *

GET /groups/:id/subgroups

+ *
GitLab Endpoint: GET /groups/:id/subgroups
* * @param groupId the group ID to get the sub groups for * @param skipGroups skip the group IDs passed @@ -140,13 +190,13 @@ public class GroupApi extends AbstractApi { */ public List getSubGroups(Integer groupId, List skipGroups, Boolean allAvailable, String search, GroupOrderBy orderBy, SortOrder sortOrder, Boolean statistics, Boolean owned) throws GitLabApiException { - return (getSubGroups(groupId, skipGroups, allAvailable, search, orderBy, sortOrder, statistics, owned, 1, getDefaultPerPage())); + return (getSubGroups(groupId, skipGroups, allAvailable, search, orderBy, sortOrder, statistics, owned, getDefaultPerPage()).all()); } /** * Get a list of visible direct subgroups in this group. * - *

GET /groups/:id/subgroups

+ *
GitLab Endpoint: GET /groups/:id/subgroups
* * @param groupId the group ID to get the sub groups for * @param skipGroups skip the group IDs passed @@ -182,22 +232,7 @@ public class GroupApi extends AbstractApi { /** * Get a Pager of visible direct subgroups in this group. * - *

GET /groups/:id/subgroups

- * - * @param groupId the group ID to get the sub groups for - * @param itemsPerPage the number of Group instances that will be fetched per page - * @return a Pager containing matching Group instances - * @throws GitLabApiException if any exception occurs - * @since GitLab 10.3.0 - */ - public Pager getSubGroups(Integer groupId, int itemsPerPage) throws GitLabApiException { - return (new Pager(this, Group.class, itemsPerPage, null, "groups", groupId, "subgroups")); - } - - /** - * Get a Pager of visible direct subgroups in this group. - * - *

GET /groups/:id/subgroups

+ *
GitLab Endpoint: GET /groups/:id/subgroups
* * @param groupId the group ID to get the sub groups for * @param skipGroups skip the group IDs passed @@ -225,10 +260,32 @@ public class GroupApi extends AbstractApi { return (new Pager(this, Group.class, itemsPerPage, formData.asMap(), "groups", groupId, "subgroups")); } + /** + * Get a Stream of visible direct subgroups in this group. + * + *
GitLab Endpoint: GET /groups/:id/subgroups
+ * + * @param groupId the group ID to get the sub groups for + * @param skipGroups skip the group IDs passed + * @param allAvailable show all the groups you have access to (defaults to false for authenticated users) + * @param search return the list of authorized groups matching the search criteria + * @param orderBy order groups by NAME or PATH. Default is NAME + * @param sortOrder order groups in ASC or DESC order. Default is ASC + * @param statistics include group statistics (admins only) + * @param owned limit to groups owned by the current user + * @return a Stream<Group> of the matching subgroups + * @throws GitLabApiException if any exception occurs + * @since GitLab 10.3.0 + */ + public Stream getSubGroupsStream(Integer groupId, List skipGroups, Boolean allAvailable, String search, + GroupOrderBy orderBy, SortOrder sortOrder, Boolean statistics, Boolean owned) throws GitLabApiException { + return (getSubGroups(groupId, skipGroups, allAvailable, search, orderBy, sortOrder, statistics, owned, getDefaultPerPage()).stream()); + } + /** * Get a list of projects belonging to the specified group ID and filter. * - * GET /groups/:id/projects + *
GitLab Endpoint: GET /groups/:id/projects
* * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param filter the GroupProjectsFilter instance holding the filter values for the query @@ -236,15 +293,13 @@ public class GroupApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ public List getProjects(Object groupIdOrPath, GroupProjectsFilter filter) throws GitLabApiException { - GitLabApiForm formData = filter.getQueryParams(); - Response response = get(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "projects"); - return (response.readEntity(new GenericType>() {})); + return (getProjects(groupIdOrPath, filter, getDefaultPerPage()).all()); } /** * Get a Pager of projects belonging to the specified group ID and filter. * - * GET /groups/:id/projects + *
GitLab Endpoint: GET /groups/:id/projects
* * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param filter the GroupProjectsFilter instance holding the filter values for the query @@ -257,100 +312,101 @@ public class GroupApi extends AbstractApi { return (new Pager(this, Project.class, itemsPerPage, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "projects")); } + /** + * Get a Stream of projects belonging to the specified group ID and filter. + * + *
GitLab Endpoint: GET /groups/:id/projects
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path + * @param filter the GroupProjectsFilter instance holding the filter values for the query + * @return a Stream containing Project instances that belong to the group and match the provided filter + * @throws GitLabApiException if any exception occurs + */ + public Stream getProjectsStream(Object groupIdOrPath, GroupProjectsFilter filter) throws GitLabApiException { + return (getProjects(groupIdOrPath, filter, getDefaultPerPage()).stream()); + } + /** * Get a list of projects belonging to the specified group ID. * - * GET /groups/:id/projects + *
GitLab Endpoint: GET /groups/:id/projects
* - * @param groupId the group ID to list the projects for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @return a list of projects belonging to the specified group ID * @throws GitLabApiException if any exception occurs */ - public List getProjects(int groupId) throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), "groups", groupId, "projects"); - return (response.readEntity(new GenericType>() {})); + public List getProjects(Object groupIdOrPath) throws GitLabApiException { + return (getProjects(groupIdOrPath, getDefaultPerPage()).all()); } /** * Get a list of projects belonging to the specified group ID in the specified page range. * - * GET /groups/:id/projects + *
GitLab Endpoint: GET /groups/:id/projects
* - * @param groupId the group ID to list the projects for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param page the page to get * @param perPage the number of Project instances per page * @return a list of projects belonging to the specified group ID in the specified page range * @throws GitLabApiException if any exception occurs */ - public List getProjects(int groupId, int page, int perPage) throws GitLabApiException { - Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "groups", groupId, "projects"); + public List getProjects(Object groupIdOrPath, int page, int perPage) throws GitLabApiException { + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "groups", getGroupIdOrPath(groupIdOrPath), "projects"); return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of projects belonging to the specified group ID. * - * GET /groups/:id/projects + *
GitLab Endpoint: GET /groups/:id/projects
* - * @param groupId the group ID to list the projects for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param itemsPerPage the number of Project instances that will be fetched per page * @return a Pager of projects belonging to the specified group ID * @throws GitLabApiException if any exception occurs */ - public Pager getProjects(int groupId, int itemsPerPage) throws GitLabApiException { - return (new Pager(this, Project.class, itemsPerPage, null, "groups", groupId, "projects")); + public Pager getProjects(Object groupIdOrPath, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, Project.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "projects")); } /** - * Get all details of a group. + * Get a Stream of projects belonging to the specified group ID. * - * GET /groups/:id + *
GitLab Endpoint: GET /groups/:id/projects
* - * @param groupId the group ID to get - * @return the Group instance for the specified group ID + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path + * @return a Stream of projects belonging to the specified group ID * @throws GitLabApiException if any exception occurs */ - public Group getGroup(Integer groupId) throws GitLabApiException { - return getGroup(groupId.toString()); - } - - /** - * Get all details of a group as an Optional instance. - * - * GET /groups/:id - * - * @param groupId the group ID to get - * @return the Group for the specified group ID as an Optional instance - */ - public Optional getOptionalGroup(Integer groupId) { - return (getOptionalGroup(groupId.toString())); + public Stream getProjectsStream(Object groupIdOrPath) throws GitLabApiException { + return (getProjects(groupIdOrPath, getDefaultPerPage()).stream()); } /** * Get all details of a group. * - * GET /groups/:id + *
GitLab Endpoint: GET /groups/:id
* - * @param groupPath the path of the group to get details for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @return the Group instance for the specified group path * @throws GitLabApiException if any exception occurs */ - public Group getGroup(String groupPath) throws GitLabApiException { - Response response = get(Response.Status.OK, null, "groups", urlEncode(groupPath)); + public Group getGroup(Object groupIdOrPath) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath)); return (response.readEntity(Group.class)); } /** * Get all details of a group as an Optional instance. * - * GET /groups/:id + *
GitLab Endpoint: GET /groups/:id
* - * @param groupPath the path of the group to get details for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @return the Group for the specified group path as an Optional instance */ - public Optional getOptionalGroup(String groupPath) { + public Optional getOptionalGroup(Object groupIdOrPath) { try { - return (Optional.ofNullable(getGroup(groupPath))); + return (Optional.ofNullable(getGroup(groupIdOrPath))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } @@ -359,7 +415,7 @@ public class GroupApi extends AbstractApi { /** * Creates a new project group. Available only for users who can create groups. * - * POST /groups + *
GitLab Endpoint: POST /groups
* * @param name the name of the group to add * @param path the path for the group @@ -391,7 +447,7 @@ public class GroupApi extends AbstractApi { /** * Creates a new project group. Available only for users who can create groups. * - * POST /groups + *
GitLab Endpoint: POST /groups
* * @param name the name of the group to add * @param path the path for the group @@ -421,7 +477,7 @@ public class GroupApi extends AbstractApi { /** * Updates a project group. Available only for users who can create groups. * - * PUT /groups + *
GitLab Endpoint: PUT /groups
* * @param group to update * @return updated group instance @@ -441,11 +497,11 @@ public class GroupApi extends AbstractApi { } /** - * Updates a project group. Available only for users who can create groups. + * Updates a project group. Available only for users who can create groups. * - * PUT /groups + *
GitLab Endpoint: PUT /groups
* - * @param groupId the ID of the group to update + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param name the name of the group to add * @param path the path for the group * @param description (optional) - The group's description @@ -456,7 +512,7 @@ public class GroupApi extends AbstractApi { * @return the updated Group instance * @throws GitLabApiException if any exception occurs */ - public Group updateGroup(Integer groupId, String name, String path, String description, Visibility visibility, + public Group updateGroup(Object groupIdOrPath, String name, String path, String description, Visibility visibility, Boolean lfsEnabled, Boolean requestAccessEnabled, Integer parentId) throws GitLabApiException { Form formData = new GitLabApiForm() @@ -467,14 +523,14 @@ public class GroupApi extends AbstractApi { .withParam("lfs_enabled", lfsEnabled) .withParam("request_access_enabled", requestAccessEnabled) .withParam("parent_id", isApiVersion(ApiVersion.V3) ? null : parentId); - Response response = put(Response.Status.OK, formData.asMap(), "groups", groupId); + Response response = put(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath)); return (response.readEntity(Group.class)); } /** * Creates a new project group. Available only for users who can create groups. * - * POST /groups + *
GitLab Endpoint: POST /groups
* * @param name the name of the group to add * @param path the path for the group @@ -513,9 +569,9 @@ public class GroupApi extends AbstractApi { /** * Updates a project group. Available only for users who can create groups. * - * PUT /groups + *
GitLab Endpoint: PUT /groups
* - * @param groupId the ID of the group to update + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param name the name of the group to add * @param path the path for the group * @param description (optional) - The group's description @@ -528,10 +584,10 @@ public class GroupApi extends AbstractApi { * @param sharedRunnersMinutesLimit (optional) - (admin-only) Pipeline minutes quota for this group * @return the updated Group instance * @throws GitLabApiException if any exception occurs - * @deprecated Will be removed in version 5.0, replaced by {@link #updateGroup(Integer, String, String, String, + * @deprecated Will be removed in version 5.0, replaced by {@link #updateGroup(Object, String, String, String, * Visibility, Boolean, Boolean, Integer)} */ - public Group updateGroup(Integer groupId, String name, String path, String description, Boolean membershipLock, + public Group updateGroup(Object groupIdOrPath, String name, String path, String description, Boolean membershipLock, Boolean shareWithGroupLock, Visibility visibility, Boolean lfsEnabled, Boolean requestAccessEnabled, Integer parentId, Integer sharedRunnersMinutesLimit) throws GitLabApiException { @@ -546,111 +602,106 @@ public class GroupApi extends AbstractApi { .withParam("request_access_enabled", requestAccessEnabled) .withParam("parent_id", parentId) .withParam("shared_runners_minutes_limit", sharedRunnersMinutesLimit); - Response response = put(Response.Status.OK, formData.asMap(), "groups", groupId); + Response response = put(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath)); return (response.readEntity(Group.class)); } /** * Removes group with all projects inside. * - * DELETE /groups/:id + *
GitLab Endpoint: DELETE /groups/:id
* - * @param groupId the group ID to delete + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @throws GitLabApiException if any exception occurs */ - public void deleteGroup(Integer groupId) throws GitLabApiException { - - if (groupId == null) { - throw new RuntimeException("groupId cannot be null"); - } - + public void deleteGroup(Object groupIdOrPath) throws GitLabApiException { Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, null, "groups", groupId); - } - - /** - * Removes group with all projects inside. - * - * DELETE /groups/:id - * - * @param group the Group instance to delete - * @throws GitLabApiException if any exception occurs - */ - public void deleteGroup(Group group) throws GitLabApiException { - deleteGroup(group.getId()); + delete(expectedStatus, null, "groups", getGroupIdOrPath(groupIdOrPath)); } /** * Get a list of group members viewable by the authenticated user. * - * GET /groups/:id/members + *
GitLab Endpoint: GET /groups/:id/members
* - * @param groupId the group ID to list the members for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @return a list of group members viewable by the authenticated user * @throws GitLabApiException if any exception occurs */ - public List getMembers(int groupId) throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), "groups", groupId, "members"); - return (response.readEntity(new GenericType>() {})); + public List getMembers(Object groupIdOrPath) throws GitLabApiException { + return (getMembers(groupIdOrPath, getDefaultPerPage()).all()); } /** * Get a list of group members viewable by the authenticated user in the specified page range. * - * GET /groups/:id/members + *
GitLab Endpoint: GET /groups/:id/members
* - * @param groupId the group ID to list the members for + *@param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param page the page to get * @param perPage the number of Member instances per page * @return a list of group members viewable by the authenticated user in the specified page range * @throws GitLabApiException if any exception occurs */ - public List getMembers(int groupId, int page, int perPage) throws GitLabApiException { - Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "groups", groupId, "members"); + public List getMembers(Object groupIdOrPath, int page, int perPage) throws GitLabApiException { + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "groups", getGroupIdOrPath(groupIdOrPath), "members"); return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of group members viewable by the authenticated user. * - * GET /groups/:id/members + *
GitLab Endpoint: GET /groups/:id/members
* - * @param groupId the group ID to list the members for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param itemsPerPage the number of Member instances that will be fetched per page * @return a list of group members viewable by the authenticated user * @throws GitLabApiException if any exception occurs */ - public Pager getMembers(int groupId, int itemsPerPage) throws GitLabApiException { - return (new Pager(this, Member.class, itemsPerPage, null, "groups", groupId, "members")); + public Pager getMembers(Object groupIdOrPath, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, Member.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "members")); + } + + /** + * Get a Stream of group members viewable by the authenticated user. + * + *
GitLab Endpoint: GET /groups/:id/members
+ * + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path + * @return a Stream of group members viewable by the authenticated user + * @throws GitLabApiException if any exception occurs + */ + public Stream getMembersStream(Object groupIdOrPath) throws GitLabApiException { + return (getMembers(groupIdOrPath, getDefaultPerPage()).stream()); } /** * Get a group member viewable by the authenticated user. * - * GET /groups/:id/members/:id + *
GitLab Endpoint: GET /groups/:id/members/:id
* - * @param groupId the group ID to get the member for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param userId the member ID of the member to get * @return a member viewable by the authenticated user * @throws GitLabApiException if any exception occurs */ - public Member getMember(int groupId, int userId) throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), "groups", groupId, "members", userId); + public Member getMember(Object groupIdOrPath, int userId) throws GitLabApiException { + Response response = get(Response.Status.OK, getDefaultPerPageParam(), "groups", getGroupIdOrPath(groupIdOrPath), "members", userId); return (response.readEntity(new GenericType() {})); } /** * Get a group member viewable by the authenticated user as an Optional instance. * - * GET /groups/:id/members/:id + *
GitLab Endpoint: GET /groups/:id/members/:id
* - * @param groupId the group ID to get the member for + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param userId the member ID of the member to get * @return a member viewable by the authenticated user as an Optional instance */ - public Optional getOptionalMember(int groupId, int userId) { + public Optional getOptionalMember(Object groupIdOrPath, int userId) { try { - return (Optional.ofNullable(getMember(groupId, userId))); + return (Optional.ofNullable(getMember(groupIdOrPath, userId))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } @@ -659,149 +710,149 @@ public class GroupApi extends AbstractApi { /** * Adds a user to the list of group members. * - * POST /groups/:id/members + *
GitLab Endpoint: POST /groups/:id/members
* - * @param groupId the project ID to add the member to, required + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param userId the user ID of the member to add, required * @param accessLevel the access level for the new member, required * @return a Member instance for the added user * @throws GitLabApiException if any exception occurs */ - public Member addMember(Integer groupId, Integer userId, Integer accessLevel) throws GitLabApiException { - return (addMember(groupId, userId, accessLevel, null)); + public Member addMember(Object groupIdOrPath, Integer userId, Integer accessLevel) throws GitLabApiException { + return (addMember(groupIdOrPath, userId, accessLevel, null)); } /** * Adds a user to the list of group members. * - * POST /groups/:id/members + *
GitLab Endpoint: POST /groups/:id/members
* - * @param groupId the project ID to add the member to, required + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param userId the user ID of the member to add, required * @param accessLevel the access level for the new member, required * @return a Member instance for the added user * @throws GitLabApiException if any exception occurs */ - public Member addMember(Integer groupId, Integer userId, AccessLevel accessLevel) throws GitLabApiException { - return (addMember(groupId, userId, accessLevel.toValue(), null)); + public Member addMember(Object groupIdOrPath, Integer userId, AccessLevel accessLevel) throws GitLabApiException { + return (addMember(groupIdOrPath, userId, accessLevel.toValue(), null)); } /** * Adds a user to the list of group members. * - * POST /groups/:id/members + *
GitLab Endpoint: POST /groups/:id/members
* - * @param groupId the project ID to add the member to, required + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param userId the user ID of the member to add, required * @param accessLevel the access level for the new member, required * @param expiresAt the date the membership in the group will expire, optional * @return a Member instance for the added user * @throws GitLabApiException if any exception occurs */ - public Member addMember(Integer groupId, Integer userId, AccessLevel accessLevel, Date expiresAt) throws GitLabApiException { - return (addMember(groupId, userId, accessLevel.toValue(), expiresAt)); + public Member addMember(Object groupIdOrPath, Integer userId, AccessLevel accessLevel, Date expiresAt) throws GitLabApiException { + return (addMember(groupIdOrPath, userId, accessLevel.toValue(), expiresAt)); } /** * Adds a user to the list of group members. * - * POST /groups/:id/members + *
GitLab Endpoint: POST /groups/:id/members
* - * @param groupId the project ID to add the member to, required + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param userId the user ID of the member to add, required * @param accessLevel the access level for the new member, required * @param expiresAt the date the membership in the group will expire, optional * @return a Member instance for the added user * @throws GitLabApiException if any exception occurs */ - public Member addMember(Integer groupId, Integer userId, Integer accessLevel, Date expiresAt) throws GitLabApiException { + public Member addMember(Object groupIdOrPath, Integer userId, Integer accessLevel, Date expiresAt) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() .withParam("user_id", userId, true) .withParam("access_level", accessLevel, true) .withParam("expires_at", expiresAt, false); - Response response = post(Response.Status.CREATED, formData, "groups", groupId, "members"); + Response response = post(Response.Status.CREATED, formData, "groups", getGroupIdOrPath(groupIdOrPath), "members"); return (response.readEntity(Member.class)); } /** * Updates a member of a group. * - * PUT /groups/:groupId/members/:userId + *
GitLab Endpoint: PUT /groups/:groupId/members/:userId
* - * @param groupId the group ID the member belongs to, required + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param userId the user ID of the member to update, required * @param accessLevel the new access level for the member, required * @return the updated member * @throws GitLabApiException if any exception occurs */ - public Member updateMember(Integer groupId, Integer userId, Integer accessLevel) throws GitLabApiException { - return (updateMember(groupId, userId, accessLevel, null)); + public Member updateMember(Object groupIdOrPath, Integer userId, Integer accessLevel) throws GitLabApiException { + return (updateMember(groupIdOrPath, userId, accessLevel, null)); } /** * Updates a member of a group. * - * PUT /groups/:groupId/members/:userId + *
GitLab Endpoint: PUT /groups/:groupId/members/:userId
* - * @param groupId the group ID the member belongs to, required + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param userId the user ID of the member to update, required * @param accessLevel the new access level for the member, required * @return the updated member * @throws GitLabApiException if any exception occurs */ - public Member updateMember(Integer groupId, Integer userId, AccessLevel accessLevel) throws GitLabApiException { - return (updateMember(groupId, userId, accessLevel.toValue(), null)); + public Member updateMember(Object groupIdOrPath, Integer userId, AccessLevel accessLevel) throws GitLabApiException { + return (updateMember(groupIdOrPath, userId, accessLevel.toValue(), null)); } /** * Updates a member of a group. * - * PUT /groups/:groupId/members/:userId + *
GitLab Endpoint: PUT /groups/:groupId/members/:userId
* - * @param groupId the group ID the member belongs to, required + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param userId the user ID of the member to update, required * @param accessLevel the new access level for the member, required * @param expiresAt the date the membership in the group will expire, optional * @return the updated member * @throws GitLabApiException if any exception occurs */ - public Member updateMember(Integer groupId, Integer userId, AccessLevel accessLevel, Date expiresAt) throws GitLabApiException { - return (updateMember(groupId, userId, accessLevel.toValue(), expiresAt)); + public Member updateMember(Object groupIdOrPath, Integer userId, AccessLevel accessLevel, Date expiresAt) throws GitLabApiException { + return (updateMember(groupIdOrPath, userId, accessLevel.toValue(), expiresAt)); } /** * Updates a member of a group. * - * PUT /groups/:groupId/members/:userId + *
GitLab Endpoint: PUT /groups/:groupId/members/:userId
* - * @param groupId the group ID the member belongs to, required + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param userId the user ID of the member to update, required * @param accessLevel the new access level for the member, required * @param expiresAt the date the membership in the group will expire, optional * @return the updated member * @throws GitLabApiException if any exception occurs */ - public Member updateMember(Integer groupId, Integer userId, Integer accessLevel, Date expiresAt) throws GitLabApiException { + public Member updateMember(Object groupIdOrPath, Integer userId, Integer accessLevel, Date expiresAt) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() .withParam("access_level", accessLevel, true) .withParam("expires_at", expiresAt, false); - Response response = put(Response.Status.OK, formData.asMap(), "groups", groupId, "members", userId); + Response response = put(Response.Status.OK, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "members", userId); return (response.readEntity(Member.class)); } /** * Removes member from the group. * - * DELETE /groups/:id/members/:user_id + *
GitLab Endpoint: DELETE /groups/:id/members/:user_id
* - * @param groupId the group ID to remove the member from + * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path, required * @param userId the user ID of the member to remove * @throws GitLabApiException if any exception occurs */ - public void removeMember(Integer groupId, Integer userId) throws GitLabApiException { + public void removeMember(Object groupIdOrPath, Integer userId) throws GitLabApiException { Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, null, "groups", groupId, "members", userId); + delete(expectedStatus, null, "groups", getGroupIdOrPath(groupIdOrPath), "members", userId); } /** diff --git a/src/main/java/org/gitlab4j/api/IssuesApi.java b/src/main/java/org/gitlab4j/api/IssuesApi.java index f4478192..1ca5ad2e 100644 --- a/src/main/java/org/gitlab4j/api/IssuesApi.java +++ b/src/main/java/org/gitlab4j/api/IssuesApi.java @@ -26,6 +26,7 @@ package org.gitlab4j.api; import java.util.Date; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.Response; @@ -48,21 +49,21 @@ public class IssuesApi extends AbstractApi implements Constants { } /** - * Get all issues the authenticated user has access to. Only returns issues created by the current user. Only returns the first page + * Get all issues the authenticated user has access to. Only returns issues created by the current user. * - * GET /issues + *
GitLab Endpoint: GET /issues
* * @return a list of user's issues * @throws GitLabApiException if any exception occurs */ public List getIssues() throws GitLabApiException { - return (getIssues(1, getDefaultPerPage())); + return (getIssues(getDefaultPerPage()).all()); } /** * Get all issues the authenticated user has access to using the specified page and per page setting. Only returns issues created by the current user. * - * GET /issues + *
GitLab Endpoint: GET /issues
* * @param page the page to get * @param perPage the number of issues per page @@ -77,7 +78,7 @@ public class IssuesApi extends AbstractApi implements Constants { /** * Get a Pager of all issues the authenticated user has access to. Only returns issues created by the current user. * - * GET /issues + *
GitLab Endpoint: GET /issues
*r * @param itemsPerPage the number of issues per page * @return the list of issues in the specified range @@ -87,69 +88,94 @@ public class IssuesApi extends AbstractApi implements Constants { return (new Pager(this, Issue.class, itemsPerPage, null, "issues")); } + /** + * Get all issues the authenticated user has access to as a Stream. Only returns issues created by the current user. + * + *
GitLab Endpoint: GET /issues
+ * + * @return a Stream of user's issues + * @throws GitLabApiException if any exception occurs + */ + public Stream getIssuesStream() throws GitLabApiException { + return (getIssues(getDefaultPerPage()).stream()); + } + /** * Get a list of project's issues. Only returns the first page * - * GET /projects/:id/issues + *
GitLab Endpoint: GET /projects/:id/issues
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @return a list of project's issues * @throws GitLabApiException if any exception occurs */ - public List getIssues(Integer projectId) throws GitLabApiException { - return (getIssues(projectId, 1, getDefaultPerPage())); + public List getIssues(Object projectIdOrPath) throws GitLabApiException { + return (getIssues(projectIdOrPath, getDefaultPerPage()).all()); } /** * Get a list of project's issues using the specified page and per page settings. * - * GET /projects/:id/issues + *
GitLab Endpoint: GET /projects/:id/issues
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param page the page to get * @param perPage the number of issues per page * @return the list of issues in the specified range * @throws GitLabApiException if any exception occurs */ - public List getIssues(Integer projectId, int page, int perPage) throws GitLabApiException { - Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "issues"); + public List getIssues(Object projectIdOrPath, int page, int perPage) throws GitLabApiException { + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", getProjectIdOrPath(projectIdOrPath), "issues"); return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of project's issues. * - * GET /projects/:id/issues + *
GitLab Endpoint: GET /projects/:id/issues
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param itemsPerPage the number of issues per page * @return the list of issues in the specified range * @throws GitLabApiException if any exception occurs */ - public Pager getIssues(Integer projectId, int itemsPerPage) throws GitLabApiException { - return (new Pager(this, Issue.class, itemsPerPage, null, "projects", projectId, "issues")); + public Pager getIssues(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, Issue.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "issues")); } /** - * Get a list of project's issues. Only returns the first page with default 100 items. + * Get a Stream of project's issues. Only returns the first page * - * GET /projects/:id/issues + *
GitLab Endpoint: GET /projects/:id/issues
* - * @param projectIdOrPath The ID or URL-encoded path of the project owned by the authenticated user. + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @return a Stream of project's issues + * @throws GitLabApiException if any exception occurs + */ + public Stream getIssuesStream(Object projectIdOrPath) throws GitLabApiException { + return (getIssues(projectIdOrPath, getDefaultPerPage()).stream()); + } + + /** + * Get a list of project's issues. + * + *
GitLab Endpoint: GET /projects/:id/issues
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings * @return the list of issues in the specified range. * @throws GitLabApiException if any exception occurs */ public List getIssues(Object projectIdOrPath, IssueFilter filter) throws GitLabApiException { - return (getIssues(projectIdOrPath, filter, 1, getDefaultPerPage())); + return (getIssues(projectIdOrPath, filter, getDefaultPerPage()).all()); } /** * Get a list of project's issues. * - * GET /projects/:id/issues + *
GitLab Endpoint: GET /projects/:id/issues
* - * @param projectIdOrPath The ID or URL-encoded path of the project owned by the authenticated user. + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings. * @param page the page to get. * @param perPage the number of projects per page. @@ -157,7 +183,6 @@ public class IssuesApi extends AbstractApi implements Constants { * @throws GitLabApiException if any exception occurs */ public List getIssues(Object projectIdOrPath, IssueFilter filter, int page, int perPage) throws GitLabApiException { - GitLabApiForm formData = filter.getQueryParams(page, perPage); Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues"); return (response.readEntity(new GenericType>() {})); @@ -166,40 +191,52 @@ public class IssuesApi extends AbstractApi implements Constants { /** * Get a list of project's issues. * - * GET /projects/:id/issues + *
GitLab Endpoint: GET /projects/:id/issues
* - * @param projectIdOrPath The ID or URL-encoded path of the project owned by the authenticated user. + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings. * @param itemsPerPage the number of Project instances that will be fetched per page. * @return the list of issues in the specified range. * @throws GitLabApiException if any exception occurs */ public Pager getIssues(Object projectIdOrPath, IssueFilter filter, int itemsPerPage) throws GitLabApiException { - GitLabApiForm formData = filter.getQueryParams(); return (new Pager(this, Issue.class, itemsPerPage, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues")); } + /** + * Get a Stream of project's issues. + * + *
GitLab Endpoint: GET /projects/:id/issues
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings + * @return a Stream of issues in the specified range. + * @throws GitLabApiException if any exception occurs + */ + public Stream getIssuesStream(Object projectIdOrPath, IssueFilter filter) throws GitLabApiException { + return (getIssues(projectIdOrPath, filter, getDefaultPerPage()).stream()); + } + /** * Get all issues the authenticated user has access to. * By default it returns only issues created by the current user. - * Only returns the first page with default 100 items. * - * GET /issues + *
GitLab Endpoint: GET /issues
* * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings * @return the list of issues in the specified range. * @throws GitLabApiException if any exception occurs */ public List getIssues(IssueFilter filter) throws GitLabApiException { - return (getIssues(filter, 1, getDefaultPerPage())); + return (getIssues(filter, getDefaultPerPage()).all()); } /** * Get all issues the authenticated user has access to. * By default it returns only issues created by the current user. * - * GET /issues + *
GitLab Endpoint: GET /issues
* * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings. * @param page the page to get. @@ -208,7 +245,6 @@ public class IssuesApi extends AbstractApi implements Constants { * @throws GitLabApiException if any exception occurs */ public List getIssues(IssueFilter filter, int page, int perPage) throws GitLabApiException { - GitLabApiForm formData = filter.getQueryParams(page, perPage); Response response = get(Response.Status.OK, formData.asMap(), "issues"); return (response.readEntity(new GenericType>() {})); @@ -218,7 +254,7 @@ public class IssuesApi extends AbstractApi implements Constants { * Get all issues the authenticated user has access to. * By default it returns only issues created by the current user. * - * GET /issues + *
GitLab Endpoint: GET /issues
* * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings. * @param itemsPerPage the number of Project instances that will be fetched per page. @@ -226,43 +262,51 @@ public class IssuesApi extends AbstractApi implements Constants { * @throws GitLabApiException if any exception occurs */ public Pager getIssues(IssueFilter filter, int itemsPerPage) throws GitLabApiException { - GitLabApiForm formData = filter.getQueryParams(); return (new Pager(this, Issue.class, itemsPerPage, formData.asMap(), "issues")); } + /** + * Get all issues the authenticated user has access to. + * By default it returns only issues created by the current user. + * + *
GitLab Endpoint: GET /issues
+ * + * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings + * @return the list of issues in the specified range. + * @throws GitLabApiException if any exception occurs + */ + public Stream getIssuesStream(IssueFilter filter) throws GitLabApiException { + return (getIssues(filter, getDefaultPerPage()).stream()); + } + /** * Get a single project issue. * - * GET /projects/:id/issues/:issue_iid + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid
* - * @param projectId the project ID to get the issue for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueId the internal ID of a project's issue * @return the specified Issue instance * @throws GitLabApiException if any exception occurs */ - public Issue getIssue(Integer projectId, Integer issueId) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } - - Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "issues", issueId); + public Issue getIssue(Object projectIdOrPath, Integer issueId) throws GitLabApiException { + Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueId); return (response.readEntity(Issue.class)); } /** * Get a single project issue as an Optional instance. * - * GET /projects/:id/issues/:issue_iid + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid
* - * @param projectId the project ID to get the issue for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueId the internal ID of a project's issue * @return the specified Issue as an Optional instance */ - public Optional getOptionalIssue(Integer projectId, Integer issueId) { + public Optional getOptionalIssue(Object projectIdOrPath, Integer issueId) { try { - return (Optional.ofNullable(getIssue(projectId, issueId))); + return (Optional.ofNullable(getIssue(projectIdOrPath, issueId))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } @@ -271,24 +315,24 @@ public class IssuesApi extends AbstractApi implements Constants { /** * Create an issue for the project. * - * POST /projects/:id/issues + *
GitLab Endpoint: POST /projects/:id/issues
* - * @param projectId the ID of the project owned by the authenticated user, required + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param title the title of an issue, required * @param description the description of an issue, optional * @return an instance of Issue * @throws GitLabApiException if any exception occurs */ - public Issue createIssue(Integer projectId, String title, String description) throws GitLabApiException { - return (createIssue(projectId, title, description, null, null, null, null, null, null, null, null)); + public Issue createIssue(Object projectIdOrPath, String title, String description) throws GitLabApiException { + return (createIssue(projectIdOrPath, title, description, null, null, null, null, null, null, null, null)); } /** * Create an issue for the project. * - * POST /projects/:id/issues + *
GitLab Endpoint: POST /projects/:id/issues
* - * @param projectId the ID of the project owned by the authenticated user, required + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param title the issue title of an issue, required * @param description the description of an issue, optional * @param confidential set the issue to be confidential, default is false, optional @@ -304,13 +348,9 @@ public class IssuesApi extends AbstractApi implements Constants { * @return an instance of Issue * @throws GitLabApiException if any exception occurs */ - public Issue createIssue(Integer projectId, String title, String description, Boolean confidential, List assigneeIds, Integer milestoneId, String labels, + public Issue createIssue(Object projectIdOrPath, String title, String description, Boolean confidential, List assigneeIds, Integer milestoneId, String labels, Date createdAt, Date dueDate, Integer mergeRequestToResolveId, Integer discussionToResolveId) throws GitLabApiException { - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } - GitLabApiForm formData = new GitLabApiForm() .withParam("title", title, true) .withParam("description", description) @@ -322,41 +362,37 @@ public class IssuesApi extends AbstractApi implements Constants { .withParam("due_date", dueDate) .withParam("merge_request_to_resolve_discussions_of", mergeRequestToResolveId) .withParam("discussion_to_resolve", discussionToResolveId); - Response response = post(Response.Status.CREATED, formData, "projects", projectId, "issues"); + Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "issues"); return (response.readEntity(Issue.class)); } /** * Closes an existing project issue. * - * PUT /projects/:id/issues/:issue_iid + *
GitLab Endpoint: PUT /projects/:id/issues/:issue_iid
* - * @param projectId the ID of the project owned by the authenticated user, required + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required * @param issueIid the issue IID to update, required * @return an instance of the updated Issue * @throws GitLabApiException if any exception occurs */ - public Issue closeIssue(Integer projectId, Integer issueIid) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("project ID cannot be null"); - } + public Issue closeIssue(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { if (issueIid == null) { throw new RuntimeException("issue IID cannot be null"); } GitLabApiForm formData = new GitLabApiForm().withParam("state_event", StateEvent.CLOSE); - Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "issues", issueIid); + Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid); return (response.readEntity(Issue.class)); } /** * Updates an existing project issue. This call can also be used to mark an issue as closed. * - * PUT /projects/:id/issues/:issue_iid + *
GitLab Endpoint: PUT /projects/:id/issues/:issue_iid
* - * @param projectId the ID of the project owned by the authenticated user, required + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required * @param issueIid the issue IID to update, required * @param title the title of an issue, optional * @param description the description of an issue, optional @@ -370,13 +406,9 @@ public class IssuesApi extends AbstractApi implements Constants { * @return an instance of the updated Issue * @throws GitLabApiException if any exception occurs */ - public Issue updateIssue(Integer projectId, Integer issueIid, String title, String description, Boolean confidential, List assigneeIds, + public Issue updateIssue(Object projectIdOrPath, Integer issueIid, String title, String description, Boolean confidential, List assigneeIds, Integer milestoneId, String labels, StateEvent stateEvent, Date updatedAt, Date dueDate) throws GitLabApiException { - if (projectId == null) { - throw new RuntimeException("project ID cannot be null"); - } - if (issueIid == null) { throw new RuntimeException("issue IID cannot be null"); } @@ -391,79 +423,71 @@ public class IssuesApi extends AbstractApi implements Constants { .withParam("state_event", stateEvent) .withParam("updated_at", updatedAt) .withParam("due_date", dueDate); - Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "issues", issueIid); + Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid); return (response.readEntity(Issue.class)); } /** * Delete an issue. * - * DELETE /projects/:id/issues/:issue_iid + *
GitLab Endpoint: DELETE /projects/:id/issues/:issue_iid
* - * @param projectId the project ID to delete the issue from + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required * @param issueIid the internal ID of a project's issue * @throws GitLabApiException if any exception occurs */ - public void deleteIssue(Integer projectId, Integer issueIid) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public void deleteIssue(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { if (issueIid == null) { throw new RuntimeException("issue IID cannot be null"); } Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, getDefaultPerPageParam(), "projects", projectId, "issues", issueIid); + delete(expectedStatus, getDefaultPerPageParam(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid); } /** * Sets an estimated time of work in this issue * - * POST /projects/:id/issues/:issue_iid/time_estimate + *
GitLab Endpoint: POST /projects/:id/issues/:issue_iid/time_estimate
* - * @param projectId the project ID that owns the issue + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required * @param issueIid the internal ID of a project's issue * @param duration estimated time in seconds * @return a TimeSTats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats estimateTime(Integer projectId, Integer issueIid, int duration) throws GitLabApiException { - return (estimateTime(projectId, issueIid, new Duration(duration))); + public TimeStats estimateTime(Object projectIdOrPath, Integer issueIid, int duration) throws GitLabApiException { + return (estimateTime(projectIdOrPath, issueIid, new Duration(duration))); } /** * Sets an estimated time of work in this issue * - * POST /projects/:id/issues/:issue_iid/time_estimate + *
GitLab Endpoint: POST /projects/:id/issues/:issue_iid/time_estimate
* - * @param projectId the project ID that owns the issue + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required * @param issueIid the internal ID of a project's issue * @param duration Human readable format, e.g. 3h30m * @return a TimeSTats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats estimateTime(Integer projectId, Integer issueIid, String duration) throws GitLabApiException { - return (estimateTime(projectId, issueIid, new Duration(duration))); + public TimeStats estimateTime(Object projectIdOrPath, Integer issueIid, String duration) throws GitLabApiException { + return (estimateTime(projectIdOrPath, issueIid, new Duration(duration))); } /** * Sets an estimated time of work in this issue * - * POST /projects/:id/issues/:issue_iid/time_estimate + *
GitLab Endpoint: POST /projects/:id/issues/:issue_iid/time_estimate
* - * @param projectId the project ID that owns the issue + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the internal ID of a project's issue * @param duration set the estimate of time to this duration * @return a TimeSTats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats estimateTime(Integer projectId, Integer issueIid, Duration duration) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public TimeStats estimateTime(Object projectIdOrPath, Integer issueIid, Duration duration) throws GitLabApiException { if (issueIid == null) { throw new RuntimeException("issue IID cannot be null"); @@ -472,80 +496,74 @@ public class IssuesApi extends AbstractApi implements Constants { String durationString = (duration != null ? DurationUtils.toString(duration.getSeconds(), false) : null); GitLabApiForm formData = new GitLabApiForm().withParam("duration", durationString, true); - Response response = post(Response.Status.OK, formData.asMap(), "projects", projectId, "issues", issueIid, "time_estimate"); + Response response = post(Response.Status.OK, formData.asMap(), + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "time_estimate"); return (response.readEntity(TimeStats.class)); } /** * Resets the estimated time for this issue to 0 seconds. * - * POST /projects/:id/issues/:issue_iid/reset_time_estimate + *
GitLab Endpoint: POST /projects/:id/issues/:issue_iid/reset_time_estimate
* - * @param projectId the project ID that owns the issue + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the internal ID of a project's issue * @return a TimeSTats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats resetEstimatedTime(Integer projectId, Integer issueIid) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public TimeStats resetEstimatedTime(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { if (issueIid == null) { throw new RuntimeException("issue IID cannot be null"); } - Response response = post(Response.Status.OK, new GitLabApiForm().asMap(), "projects", projectId, "issues", issueIid, "reset_time_estimate"); + Response response = post(Response.Status.OK, new GitLabApiForm().asMap(), "projects", + getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "reset_time_estimate"); return (response.readEntity(TimeStats.class)); } /** * Adds spent time for this issue * - * POST /projects/:id/issues/:issue_iid/add_spent_time + *
GitLab Endpoint: POST /projects/:id/issues/:issue_iid/add_spent_time
* - * @param projectId the project ID that owns the issue + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the internal ID of a project's issue * @param duration the duration in seconds * @return a TimeSTats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats addSpentTime(Integer projectId, Integer issueIid, int duration) throws GitLabApiException { - return (addSpentTime(projectId, issueIid, new Duration(duration))); + public TimeStats addSpentTime(Object projectIdOrPath, Integer issueIid, int duration) throws GitLabApiException { + return (addSpentTime(projectIdOrPath, issueIid, new Duration(duration))); } /** * Adds spent time for this issue * - * POST /projects/:id/issues/:issue_iid/add_spent_time + *
GitLab Endpoint: POST /projects/:id/issues/:issue_iid/add_spent_time
* - * @param projectId the project ID to delete the issue from + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the internal ID of a project's issue * @param duration Human readable format, e.g. 3h30m * @return a TimeSTats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats addSpentTime(Integer projectId, Integer issueIid, String duration) throws GitLabApiException { - return (addSpentTime(projectId, issueIid, new Duration(duration))); + public TimeStats addSpentTime(Object projectIdOrPath, Integer issueIid, String duration) throws GitLabApiException { + return (addSpentTime(projectIdOrPath, issueIid, new Duration(duration))); } /** * Adds spent time for this issue * - * POST /projects/:id/issues/:issue_iid/add_spent_time + *
GitLab Endpoint: POST /projects/:id/issues/:issue_iid/add_spent_time
* - * @param projectId the project ID to delete the issue from + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the internal ID of a project's issue * @param duration the duration of time spent * @return a TimeSTats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats addSpentTime(Integer projectId, Integer issueIid, Duration duration) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public TimeStats addSpentTime(Object projectIdOrPath, Integer issueIid, Duration duration) throws GitLabApiException { if (issueIid == null) { throw new RuntimeException("issue IID cannot be null"); @@ -554,70 +572,65 @@ public class IssuesApi extends AbstractApi implements Constants { String durationString = (duration != null ? DurationUtils.toString(duration.getSeconds(), false) : null); GitLabApiForm formData = new GitLabApiForm().withParam("duration", durationString, true); - Response response = post(Response.Status.CREATED, formData.asMap(), "projects", projectId, "issues", issueIid, "add_spent_time"); + Response response = post(Response.Status.CREATED, formData.asMap(), + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "add_spent_time"); return (response.readEntity(TimeStats.class)); } /** * Resets the total spent time for this issue to 0 seconds. * - * POST /projects/:id/issues/:issue_iid/reset_spent_time + *
GitLab Endpoint: POST /projects/:id/issues/:issue_iid/reset_spent_time
* - * @param projectId the project ID that owns the issue + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the internal ID of a project's issue * @return a TimeSTats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats resetSpentTime(Integer projectId, Integer issueIid) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public TimeStats resetSpentTime(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { if (issueIid == null) { throw new RuntimeException("issue IID cannot be null"); } - Response response = post(Response.Status.OK, new GitLabApiForm().asMap(), "projects", projectId, "issues", issueIid, "reset_spent_time"); + Response response = post(Response.Status.OK, new GitLabApiForm().asMap(), + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "reset_spent_time"); return (response.readEntity(TimeStats.class)); } /** * Get time tracking stats. * - * GET /projects/:id/issues/:issue_iid/time_stats + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/time_stats
* - * @param projectId the project ID that owns the issue + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the internal ID of a project's issue * @return a TimeStats instance * @throws GitLabApiException if any exception occurs */ - public TimeStats getTimeTrackingStats(Integer projectId, Integer issueIid) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public TimeStats getTimeTrackingStats(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { if (issueIid == null) { throw new RuntimeException("issue IID cannot be null"); } - Response response = get(Response.Status.OK, new GitLabApiForm().asMap(), "projects", projectId, "issues", issueIid, "time_stats"); + Response response = get(Response.Status.OK, new GitLabApiForm().asMap(), + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "time_stats"); return (response.readEntity(TimeStats.class)); } /** * Get time tracking stats as an Optional instance * - * GET /projects/:id/issues/:issue_iid/time_stats + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/time_stats
* - * @param projectId the project ID that owns the issue + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the internal ID of a project's issue * @return a TimeStats as an Optional instance */ - public Optional getOptionalTimeTrackingStats(Integer projectId, Integer issueIid) { + public Optional getOptionalTimeTrackingStats(Object projectIdOrPath, Integer issueIid) { try { - return (Optional.ofNullable(getTimeTrackingStats(projectId, issueIid))); + return (Optional.ofNullable(getTimeTrackingStats(projectIdOrPath, issueIid))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } @@ -626,7 +639,7 @@ public class IssuesApi extends AbstractApi implements Constants { /** * Get list containing all the merge requests that will close issue when merged. * - * GET /projects/:id/issues/:issue_iid/closed_by + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/closed_by
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param issueIid the internal ID of a project's issue @@ -634,13 +647,13 @@ public class IssuesApi extends AbstractApi implements Constants { * @throws GitLabApiException if any exception occurs */ public List getClosedByMergeRequests(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { - return (getClosedByMergeRequests(projectIdOrPath, issueIid, 1, getDefaultPerPage())); + return (getClosedByMergeRequests(projectIdOrPath, issueIid, getDefaultPerPage()).all()); } /** * Get list containing all the merge requests that will close issue when merged. * - * GET /projects/:id/issues/:issue_iid/closed_by + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/closed_by
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param issueIid the internal ID of a project's issue @@ -658,7 +671,7 @@ public class IssuesApi extends AbstractApi implements Constants { /** * Get a Pager containing all the merge requests that will close issue when merged. * - * GET /projects/:id/issues/:issue_iid/closed_by + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/closed_by
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param issueIid the internal ID of a project's issue @@ -670,4 +683,18 @@ public class IssuesApi extends AbstractApi implements Constants { return new Pager(this, MergeRequest.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "closed_by"); } + + /** + * Get list containing all the merge requests that will close issue when merged. + * + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/closed_by
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @param issueIid the internal ID of a project's issue + * @return a List containing all the merge requests what will close the issue when merged. + * @throws GitLabApiException if any exception occurs + */ + public Stream getClosedByMergeRequestsStream(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { + return (getClosedByMergeRequests(projectIdOrPath, issueIid, getDefaultPerPage()).stream()); + } } diff --git a/src/main/java/org/gitlab4j/api/NotesApi.java b/src/main/java/org/gitlab4j/api/NotesApi.java index cefcf03c..d01a6e15 100644 --- a/src/main/java/org/gitlab4j/api/NotesApi.java +++ b/src/main/java/org/gitlab4j/api/NotesApi.java @@ -2,6 +2,7 @@ package org.gitlab4j.api; import java.util.Date; import java.util.List; +import java.util.stream.Stream; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.Response; @@ -15,184 +16,192 @@ public class NotesApi extends AbstractApi { } /** - * Get a list of the issues's notes. Only returns the first page + * Get a list of the issues's notes. * - * GET /projects/:id/issues/:issue_iid/notes + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue ID to get the notes for * @return a list of the issues's notes * @throws GitLabApiException if any exception occurs - * @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Integer, Integer)} + * @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Integer)} */ - public List getNotes(Integer projectId, Integer issueIid) throws GitLabApiException { - return (getIssueNotes(projectId, issueIid)); + @Deprecated + public List getNotes(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { + return (getIssueNotes(projectIdOrPath, issueIid)); } /** * Get a list of the issue's notes using the specified page and per page settings. * - * GET /projects/:id/issues/:issue_iid/notes + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue IID to get the notes for * @param page the page to get * @param perPage the number of notes per page * @return the list of notes in the specified range * @throws GitLabApiException if any exception occurs - * @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Integer, Integer, int, int)} + * @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Integer, int, int)} */ - public List getNotes(Integer projectId, Integer issueIid, int page, int perPage) throws GitLabApiException { - return (getIssueNotes(projectId, issueIid, page, perPage)); + @Deprecated + public List getNotes(Object projectIdOrPath, Integer issueIid, int page, int perPage) throws GitLabApiException { + return (getIssueNotes(projectIdOrPath, issueIid, page, perPage)); } /** * Get a Pager of issues's notes. * - * GET /projects/:id/issues/:issue_iid/notes + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue IID to get the notes for * @param itemsPerPage the number of notes per page * @return the list of notes in the specified range * @throws GitLabApiException if any exception occurs - * @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Integer, Integer, int)} + * @deprecated As of release 4.7.0, replaced by {@link #getIssueNotes(Object, Integer, int)} */ - public Pager getNotes(Integer projectId, Integer issueIid, int itemsPerPage) throws GitLabApiException { - return (getIssueNotes(projectId, issueIid, itemsPerPage)); + @Deprecated + public Pager getNotes(Object projectIdOrPath, Integer issueIid, int itemsPerPage) throws GitLabApiException { + return (getIssueNotes(projectIdOrPath, issueIid, itemsPerPage)); } /** - * Get a list of the issues's notes. Only returns the first page + * Get a list of the issues's notes. * - * GET /projects/:id/issues/:issue_iid/notes + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue ID to get the notes for * @return a list of the issues's notes * @throws GitLabApiException if any exception occurs */ - public List getIssueNotes(Integer projectId, Integer issueIid) throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "issues", issueIid, "notes"); - return (response.readEntity(new GenericType>() {})); + public List getIssueNotes(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { + return (getIssueNotes(projectIdOrPath, issueIid, getDefaultPerPage()).all()); } /** * Get a list of the issue's notes using the specified page and per page settings. * - * GET /projects/:id/issues/:issue_iid/notes + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue IID to get the notes for * @param page the page to get * @param perPage the number of notes per page * @return the list of notes in the specified range * @throws GitLabApiException if any exception occurs */ - public List getIssueNotes(Integer projectId, Integer issueIid, int page, int perPage) throws GitLabApiException { - Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "issues", issueIid, "notes"); + public List getIssueNotes(Object projectIdOrPath, Integer issueIid, int page, int perPage) throws GitLabApiException { + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),"projects", + getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "notes"); return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of issues's notes. * - * GET /projects/:id/issues/:issue_iid/notes + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue IID to get the notes for * @param itemsPerPage the number of notes per page * @return the list of notes in the specified range * @throws GitLabApiException if any exception occurs */ - public Pager getIssueNotes(Integer projectId, Integer issueIid, int itemsPerPage) throws GitLabApiException { - return (new Pager(this, Note.class, itemsPerPage, null, "projects", projectId, "issues", issueIid, "notes")); + public Pager getIssueNotes(Object projectIdOrPath, Integer issueIid, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, Note.class, itemsPerPage, null, + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "notes")); + } + + /** + * Get a Stream of the issues's notes. + * + *
GitLab Endpoint: GET /projects/:id/issues/:issue_iid/notes
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param issueIid the issue ID to get the notes for + * @return a Stream of the issues's notes + * @throws GitLabApiException if any exception occurs + */ + public Stream getIssueNotesStream(Object projectIdOrPath, Integer issueIid) throws GitLabApiException { + return (getIssueNotes(projectIdOrPath, issueIid, getDefaultPerPage()).stream()); } /** * Get the specified issues's note. * - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue IID to get the notes for * @param noteId the ID of the Note to get * @return a Note instance for the specified IDs * @throws GitLabApiException if any exception occurs */ - public Note getIssueNote(Integer projectId, Integer issueIid, Integer noteId) throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "issues", issueIid, "notes", noteId); + public Note getIssueNote(Object projectIdOrPath, Integer issueIid, Integer noteId) throws GitLabApiException { + Response response = get(Response.Status.OK, getDefaultPerPageParam(), + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "notes", noteId); return (response.readEntity(Note.class)); } /** * Create a issues's note. - * - * @param projectId the project ID to create the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance @param projectIdOrPath the project ID to create the issues for * @param issueIid the issue IID to create the notes for * @param body the content of note * @return the created Note instance * @throws GitLabApiException if any exception occurs */ - public Note createIssueNote(Integer projectId, Integer issueIid, String body) throws GitLabApiException { - return (createIssueNote(projectId, issueIid, body, null)); + public Note createIssueNote(Object projectIdOrPath, Integer issueIid, String body) throws GitLabApiException { + return (createIssueNote(projectIdOrPath, issueIid, body, null)); } /** * Create a issues's note. * - * @param projectId the project ID to create the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue IID to create the notes for * @param body the content of note * @param createdAt the created time of note * @return the created Note instance * @throws GitLabApiException if any exception occurs */ - public Note createIssueNote(Integer projectId, Integer issueIid, String body, Date createdAt) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public Note createIssueNote(Object projectIdOrPath, Integer issueIid, String body, Date createdAt) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() .withParam("body", body, true) .withParam("created_at", createdAt); - Response response = post(Response.Status.CREATED, formData, "projects", projectId, "issues", issueIid, "notes"); + Response response = post(Response.Status.CREATED, formData, + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "notes"); return (response.readEntity(Note.class)); } /** * Update the specified issues's note. * - * @param projectId the project ID to update the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue IID to update the notes for * @param noteId the ID of the node to update * @param body the update content for the Note * @return the modified Note instance * @throws GitLabApiException if any exception occurs */ - public Note updateIssueNote(Integer projectId, Integer issueIid, Integer noteId, String body) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public Note updateIssueNote(Object projectIdOrPath, Integer issueIid, Integer noteId, String body) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm().withParam("body", body, true); - Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "issues", issueIid, "notes", noteId); + Response response = put(Response.Status.OK, formData.asMap(), + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "notes", noteId); return (response.readEntity(Note.class)); } /** * Delete the specified issues's note. * - * @param projectId the project ID to delete the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param issueIid the issue IID to delete the notes for * @param noteId the ID of the node to delete * @throws GitLabApiException if any exception occurs */ - public void deleteIssueNote(Integer projectId, Integer issueIid, Integer noteId) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public void deleteIssueNote(Object projectIdOrPath, Integer issueIid, Integer noteId) throws GitLabApiException { if (issueIid == null) { throw new RuntimeException("issueIid cannot be null"); @@ -203,61 +212,62 @@ public class NotesApi extends AbstractApi { } Response.Status expectedStatus = (isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, getDefaultPerPageParam(), "projects", projectId, "issues", issueIid, "notes", noteId); + delete(expectedStatus, getDefaultPerPageParam(), + "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid, "notes", noteId); } /** - * Gets a list of all notes for a single merge request. Only returns the first page + * Gets a list of all notes for a single merge request * - * GET /projects/:id/merge_requests/:merge_request_iid/notes + *
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the issue ID to get the notes for * @return a list of the merge request's notes * @throws GitLabApiException if any exception occurs */ - public List getMergeRequestNotes(Integer projectId, Integer mergeRequestIid) throws GitLabApiException { - return (getMergeRequestNotes(projectId, mergeRequestIid, null, null, 1, getDefaultPerPage())); + public List getMergeRequestNotes(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException { + return (getMergeRequestNotes(projectIdOrPath, mergeRequestIid, null, null, getDefaultPerPage()).all()); } /** - * Gets a list of all notes for a single merge request. Only returns the first page + * Gets a list of all notes for a single merge request. * - * GET /projects/:id/merge_requests/:merge_request_iid/notes + *
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the issue ID to get the notes for * @param sortOrder return merge request notes sorted in the specified sort order, default is DESC * @param orderBy return merge request notes ordered by CREATED_AT or UPDATED_AT, default is CREATED_AT * @return a list of the merge request's notes * @throws GitLabApiException if any exception occurs */ - public List getMergeRequestNotes(Integer projectId, Integer mergeRequestIid, SortOrder sortOrder, Note.OrderBy orderBy) throws GitLabApiException { - return (getMergeRequestNotes(projectId, mergeRequestIid, sortOrder, orderBy, 1, getDefaultPerPage())); + public List getMergeRequestNotes(Object projectIdOrPath, Integer mergeRequestIid, SortOrder sortOrder, Note.OrderBy orderBy) throws GitLabApiException { + return (getMergeRequestNotes(projectIdOrPath, mergeRequestIid, sortOrder, orderBy, getDefaultPerPage()).all()); } /** * Gets a list of all notes for a single merge request using the specified page and per page settings. * - * GET /projects/:id/merge_requests/:merge_request_iid/notes + *
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to get the notes for * @param page the page to get * @param perPage the number of notes per page * @return the list of notes in the specified range * @throws GitLabApiException if any exception occurs */ - public List getMergeRequestNotes(Integer projectId, Integer mergeRequestIid, int page, int perPage) throws GitLabApiException { - return (getMergeRequestNotes(projectId, mergeRequestIid, null, null, page, perPage)); + public List getMergeRequestNotes(Object projectIdOrPath, Integer mergeRequestIid, int page, int perPage) throws GitLabApiException { + return (getMergeRequestNotes(projectIdOrPath, mergeRequestIid, null, null, page, perPage)); } /** * Gets a list of all notes for a single merge request using the specified page and per page settings. * - * GET /projects/:id/merge_requests/:merge_request_iid/notes + *
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to get the notes for * @param sortOrder return merge request notes sorted in the specified sort order, default is DESC * @param orderBy return merge request notes ordered by CREATED_AT or UPDATED_AT, default is CREATED_AT @@ -266,7 +276,7 @@ public class NotesApi extends AbstractApi { * @return the list of notes in the specified range * @throws GitLabApiException if any exception occurs */ - public List getMergeRequestNotes(Integer projectId, Integer mergeRequestIid, + public List getMergeRequestNotes(Object projectIdOrPath, Integer mergeRequestIid, SortOrder sortOrder, Note.OrderBy orderBy, int page, int perPage) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() @@ -274,31 +284,46 @@ public class NotesApi extends AbstractApi { .withParam("order_by", orderBy) .withParam(PAGE_PARAM, page) .withParam(PER_PAGE_PARAM, perPage); - Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests", mergeRequestIid, "notes"); + Response response = get(Response.Status.OK, formData.asMap(), + "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "notes"); return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of all notes for a single merge request * - * GET /projects/:id/merge_requests/:merge_request_iid/notes + *
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to get the notes for * @param itemsPerPage the number of notes per page * @return the list of notes in the specified range * @throws GitLabApiException if any exception occurs */ - public Pager getMergeRequestNotes(Integer projectId, Integer mergeRequestIid, int itemsPerPage) throws GitLabApiException { - return (getMergeRequestNotes(projectId, mergeRequestIid, null, null, itemsPerPage)); + public Pager getMergeRequestNotes(Object projectIdOrPath, Integer mergeRequestIid, int itemsPerPage) throws GitLabApiException { + return (getMergeRequestNotes(projectIdOrPath, mergeRequestIid, null, null, itemsPerPage)); + } + + /** + * Gets a Stream of all notes for a single merge request + * + *
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/notes
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param mergeRequestIid the issue ID to get the notes for + * @return a Stream of the merge request's notes + * @throws GitLabApiException if any exception occurs + */ + public Stream getMergeRequestNotesStream(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException { + return (getMergeRequestNotes(projectIdOrPath, mergeRequestIid, null, null, getDefaultPerPage()).stream()); } /** * Get a Pager of all notes for a single merge request * - * GET /projects/:id/merge_requests/:merge_request_iid/notes + *
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/notes
* - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to get the notes for * @param sortOrder return merge request notes sorted in the specified sort order, default is DESC * @param orderBy return merge request notes ordered by CREATED_AT or UPDATED_AT, default is CREATED_AT @@ -306,7 +331,7 @@ public class NotesApi extends AbstractApi { * @return the list of notes in the specified range * @throws GitLabApiException if any exception occurs */ - public Pager getMergeRequestNotes(Integer projectId, Integer mergeRequestIid, + public Pager getMergeRequestNotes(Object projectIdOrPath, Integer mergeRequestIid, SortOrder sortOrder, Note.OrderBy orderBy, int itemsPerPage) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() @@ -315,80 +340,83 @@ public class NotesApi extends AbstractApi { .withParam(PAGE_PARAM, 1) .withParam(PER_PAGE_PARAM, itemsPerPage); return (new Pager(this, Note.class, itemsPerPage, formData.asMap(), - "projects", projectId, "merge_requests", mergeRequestIid, "notes")); + "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "notes")); + } + + /** + * Gets a Stream of all notes for a single merge request. + * + *
GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/notes
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param mergeRequestIid the issue ID to get the notes for + * @param sortOrder return merge request notes sorted in the specified sort order, default is DESC + * @param orderBy return merge request notes ordered by CREATED_AT or UPDATED_AT, default is CREATED_AT + * @return a Stream of the merge request's notes + * @throws GitLabApiException if any exception occurs + */ + public Stream getMergeRequestNotesStream(Object projectIdOrPath, Integer mergeRequestIid, SortOrder sortOrder, Note.OrderBy orderBy) throws GitLabApiException { + return (getMergeRequestNotes(projectIdOrPath, mergeRequestIid, sortOrder, orderBy, getDefaultPerPage()).stream()); } /** * Get the specified merge request's note. * - * @param projectId the project ID to get the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to get the notes for * @param noteId the ID of the Note to get * @return a Note instance for the specified IDs * @throws GitLabApiException if any exception occurs */ - public Note getMergeRequestNote(Integer projectId, Integer mergeRequestIid, Integer noteId) throws GitLabApiException { + public Note getMergeRequestNote(Object projectIdOrPath, Integer mergeRequestIid, Integer noteId) throws GitLabApiException { Response response = get(Response.Status.OK, getDefaultPerPageParam(), - "projects", projectId, "merge_requests", mergeRequestIid, "notes", noteId); + "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "notes", noteId); return (response.readEntity(Note.class)); } /** * Create a merge request's note. * - * @param projectId the project ID to create the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to create the notes for * @param body the content of note * @return the created Note instance * @throws GitLabApiException if any exception occurs */ - public Note createMergeRequestNote(Integer projectId, Integer mergeRequestIid, String body) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } - + public Note createMergeRequestNote(Object projectIdOrPath, Integer mergeRequestIid, String body) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm().withParam("body", body, true); Response response = post(Response.Status.CREATED, formData, - "projects", projectId, "merge_requests", mergeRequestIid, "notes"); + "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "notes"); return (response.readEntity(Note.class)); } /** * Update the specified merge request's note. * - * @param projectId the project ID to update the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to update the notes for * @param noteId the ID of the node to update * @param body the update content for the Note * @return the modified Note instance * @throws GitLabApiException if any exception occurs */ - public Note updateMergeRequestNote(Integer projectId, Integer mergeRequestIid, Integer noteId, String body) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public Note updateMergeRequestNote(Object projectIdOrPath, Integer mergeRequestIid, Integer noteId, String body) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm().withParam("body", body, true); Response response = put(Response.Status.OK, formData.asMap(), - "projects", projectId, "merge_requests", mergeRequestIid, "notes", noteId); + "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "notes", noteId); return (response.readEntity(Note.class)); } /** * Delete the specified merge request's note. * - * @param projectId the project ID to delete the issues for + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to delete the notes for * @param noteId the ID of the node to delete * @throws GitLabApiException if any exception occurs */ - public void deleteMergeRequestNote(Integer projectId, Integer mergeRequestIid, Integer noteId) throws GitLabApiException { - - if (projectId == null) { - throw new RuntimeException("projectId cannot be null"); - } + public void deleteMergeRequestNote(Object projectIdOrPath, Integer mergeRequestIid, Integer noteId) throws GitLabApiException { if (mergeRequestIid == null) { throw new RuntimeException("mergeRequestIid cannot be null"); @@ -399,6 +427,7 @@ public class NotesApi extends AbstractApi { } Response.Status expectedStatus = (isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, getDefaultPerPageParam(), "projects", projectId, "merge_requests", mergeRequestIid, "notes", noteId); + delete(expectedStatus, getDefaultPerPageParam(), + "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "notes", noteId); } } diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index 2a3e7b70..61f2c873 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -1794,7 +1794,7 @@ public class ProjectApi extends AbstractApi implements Constants { * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required * @return a list of project's issues * @throws GitLabApiException if any exception occurs - * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Integer)} + * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Object)} */ @Deprecated public List getIssues(Object projectIdOrPath) throws GitLabApiException { @@ -1811,7 +1811,7 @@ public class ProjectApi extends AbstractApi implements Constants { * @param perPage the number of issues per page * @return the list of issues in the specified range * @throws GitLabApiException if any exception occurs - * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Integer, int, int)} + * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Object, int, int)} */ @Deprecated public List getIssues(Object projectIdOrPath, int page, int perPage) throws GitLabApiException { @@ -1828,7 +1828,7 @@ public class ProjectApi extends AbstractApi implements Constants { * @param itemsPerPage the number of issues per page * @return the list of issues in the specified range * @throws GitLabApiException if any exception occurs - * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Integer, int)} + * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Object, int)} */ @Deprecated public Pager getIssues(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { @@ -1843,7 +1843,7 @@ public class ProjectApi extends AbstractApi implements Constants { * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required * @return a Stream of the project's issues * @throws GitLabApiException if any exception occurs - * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Integer)} + * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssues(Object)} */ @Deprecated public Stream getIssuesStream(Object projectIdOrPath) throws GitLabApiException { @@ -1859,7 +1859,7 @@ public class ProjectApi extends AbstractApi implements Constants { * @param issueId the internal ID of a project's issue * @return the specified Issue instance * @throws GitLabApiException if any exception occurs - * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssue(Integer, Integer)} + * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#getIssue(Object, Integer)} */ @Deprecated public Issue getIssue(Object projectIdOrPath, Integer issueId) throws GitLabApiException { @@ -1875,7 +1875,7 @@ public class ProjectApi extends AbstractApi implements Constants { * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance, required * @param issueId the internal ID of a project's issue * @throws GitLabApiException if any exception occurs - * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#deleteIssue(Integer, Integer)} + * @deprecated Will be removed in version 5.0, replaced by {@link IssuesApi#deleteIssue(Object, Integer)} */ @Deprecated public void deleteIssue(Object projectIdOrPath, Integer issueId) throws GitLabApiException { @@ -2398,8 +2398,8 @@ public class ProjectApi extends AbstractApi implements Constants { * @return the updated Project instance * @throws GitLabApiException if any exception occurs */ - public Project setProjectAvatar(Object projectIdOrPath, File fileToUpload) throws GitLabApiException { - return (setProjectAvatar(projectIdOrPath, fileToUpload, null)); + public Project setProjectAvatar(Object projectIdOrPath, File avatarFile) throws GitLabApiException { + return (setProjectAvatar(projectIdOrPath, avatarFile, null)); } /** diff --git a/src/main/java/org/gitlab4j/api/RepositoryApi.java b/src/main/java/org/gitlab4j/api/RepositoryApi.java index 6a8795da..a2259d5b 100644 --- a/src/main/java/org/gitlab4j/api/RepositoryApi.java +++ b/src/main/java/org/gitlab4j/api/RepositoryApi.java @@ -7,6 +7,7 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import javax.ws.rs.core.Form; import javax.ws.rs.core.GenericType; @@ -40,9 +41,7 @@ public class RepositoryApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ public List getBranches(Object projectIdOrPath) throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), - "projects", getProjectIdOrPath(projectIdOrPath), "repository", "branches"); - return (response.readEntity(new GenericType>() {})); + return (getBranches(projectIdOrPath, getDefaultPerPage()).all()); } /** @@ -78,6 +77,19 @@ public class RepositoryApi extends AbstractApi { getProjectIdOrPath(projectIdOrPath), "repository", "branches")); } + /** + * Get a Stream of repository branches from a project, sorted by name alphabetically. + * + * GET /projects/:id/repository/branches + * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @return a Stream of repository branches for the specified project + * @throws GitLabApiException if any exception occurs + */ + public Stream getBranchesStream(Object projectIdOrPath) throws GitLabApiException { + return (getBranches(projectIdOrPath, getDefaultPerPage()).stream()); + } + /** * Get a single project repository branch. * @@ -192,6 +204,7 @@ public class RepositoryApi extends AbstractApi { * @throws GitLabApiException if any exception occurs * @deprecated Replaced by TagsApi.getTags(Object) */ + @Deprecated public List getTags(Object projectIdOrPath) throws GitLabApiException { Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags"); @@ -210,6 +223,7 @@ public class RepositoryApi extends AbstractApi { * @throws GitLabApiException if any exception occurs * @deprecated Replaced by TagsApi.getTags(Object, int, int) */ + @Deprecated public List getTags(Object projectIdOrPath, int page, int perPage) throws GitLabApiException { Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags"); @@ -227,6 +241,7 @@ public class RepositoryApi extends AbstractApi { * @throws GitLabApiException if any exception occurs * @deprecated Replaced by TagsApi.getTags(Object, int) */ + @Deprecated public Pager getTags(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { return (new Pager(this, Tag.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags")); @@ -332,6 +347,19 @@ public class RepositoryApi extends AbstractApi { return (getTree(projectIdOrPath, "/", "master", false, itemsPerPage)); } + /** + * Get a list of repository files and directories in a project. + * + * GET /projects/:id/repository/tree + * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @return a Stream containing a tree with the root directories and files of a project + * @throws GitLabApiException if any exception occurs + */ + public Stream getTreeStream(Object projectIdOrPath) throws GitLabApiException { + return (getTreeStream(projectIdOrPath, "/", "master")); + } + /** * Get a list of repository files and directories in a project. * @@ -371,6 +399,25 @@ public class RepositoryApi extends AbstractApi { return (getTree(projectIdOrPath, filePath, refName, false, itemsPerPage)); } + /** + * Get a Stream of repository files and directories in a project. + * + * GET /projects/:id/repository/tree + * + * id (required) - The ID of a project + * path (optional) - The path inside repository. Used to get content of subdirectories + * ref_name (optional) - The name of a repository branch or tag or if not given the default branch + * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param filePath the path inside repository, used to get content of subdirectories + * @param refName the name of a repository branch or tag or if not given the default branch + * @return a Stream containing a tree with the directories and files of a project + * @throws GitLabApiException if any exception occurs + */ + public Stream getTreeStream(Object projectIdOrPath, String filePath, String refName) throws GitLabApiException { + return (getTreeStream(projectIdOrPath, filePath, refName, false)); + } + /** * Get a list of repository files and directories in a project. * @@ -389,14 +436,7 @@ public class RepositoryApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ public List getTree(Object projectIdOrPath, String filePath, String refName, Boolean recursive) throws GitLabApiException { - Form formData = new GitLabApiForm() - .withParam("id", getProjectIdOrPath(projectIdOrPath), true) - .withParam("path", filePath, false) - .withParam(isApiVersion(ApiVersion.V3) ? "ref_name" : "ref", refName, false) - .withParam("recursive", recursive, false) - .withParam(PER_PAGE_PARAM, getDefaultPerPage()); - Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tree"); - return (response.readEntity(new GenericType>() {})); + return (getTree(projectIdOrPath, filePath, refName, recursive, getDefaultPerPage()).all()); } /** @@ -427,6 +467,27 @@ public class RepositoryApi extends AbstractApi { getProjectIdOrPath(projectIdOrPath), "repository", "tree")); } + /** + * Get a Stream of repository files and directories in a project. + * + * GET /projects/:id/repository/tree + * + * id (required) - The ID of a project + * path (optional) - The path inside repository. Used to get contend of subdirectories + * ref_name (optional) - The name of a repository branch or tag or if not given the default branch + * recursive (optional) - Boolean value used to get a recursive tree (false by default) + * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param filePath the path inside repository, used to get content of subdirectories + * @param refName the name of a repository branch or tag or if not given the default branch + * @param recursive flag to get a recursive tree or not + * @return a Stream containing a tree with the directories and files of a project + * @throws GitLabApiException if any exception occurs + */ + public Stream getTreeStream(Object projectIdOrPath, String filePath, String refName, Boolean recursive) throws GitLabApiException { + return (getTree(projectIdOrPath, filePath, refName, recursive, getDefaultPerPage()).stream()); + } + /** * Get the raw file contents for a blob by blob SHA. * @@ -634,7 +695,7 @@ public class RepositoryApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ public List getContributors(Object projectIdOrPath) throws GitLabApiException { - return (getContributors(projectIdOrPath, 1, getDefaultPerPage())); + return (getContributors(projectIdOrPath, getDefaultPerPage()).all()); } /** @@ -668,4 +729,17 @@ public class RepositoryApi extends AbstractApi { return new Pager(this, Contributor.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "contributors"); } + + /** + * Get a list of contributors from a project. + * + * GET /projects/:id/repository/contributors + * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @return a List containing the contributors for the specified project ID + * @throws GitLabApiException if any exception occurs + */ + public Stream getContributorsStream(Object projectIdOrPath) throws GitLabApiException { + return (getContributors(projectIdOrPath, getDefaultPerPage()).stream()); + } } diff --git a/src/main/java/org/gitlab4j/api/TagsApi.java b/src/main/java/org/gitlab4j/api/TagsApi.java index 399bb7e7..de5c2a1f 100644 --- a/src/main/java/org/gitlab4j/api/TagsApi.java +++ b/src/main/java/org/gitlab4j/api/TagsApi.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.IOException; import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import javax.ws.rs.core.Form; import javax.ws.rs.core.GenericType; @@ -28,22 +29,20 @@ public class TagsApi extends AbstractApi { /** * Get a list of repository tags from a project, sorted by name in reverse alphabetical order. * - * GET /projects/:id/repository/tags + *
GitLab Endpoint: GET /projects/:id/repository/tags
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @return the list of tags for the specified project ID * @throws GitLabApiException if any exception occurs */ public List getTags(Object projectIdOrPath) throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(), - "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags"); - return (response.readEntity(new GenericType>() { })); + return (getTags(projectIdOrPath, getDefaultPerPage()).all()); } /** * Get a list of repository tags from a project, sorted by name in reverse alphabetical order and in the specified page range. * - * GET /projects/:id/repository/tags + *
GitLab Endpoint: GET /projects/:id/repository/tags
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param page the page to get @@ -60,7 +59,7 @@ public class TagsApi extends AbstractApi { /** * Get a list of repository tags from a project, sorted by name in reverse alphabetical order. * - * GET /projects/:id/repository/tags + *
GitLab Endpoint: GET /projects/:id/repository/tags
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param itemsPerPage the number of Project instances that will be fetched per page @@ -71,10 +70,23 @@ public class TagsApi extends AbstractApi { return (new Pager(this, Tag.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "tags")); } + /** + * Get a Stream of repository tags from a project, sorted by name in reverse alphabetical order. + * + *
GitLab Endpoint: GET /projects/:id/repository/tags
+ * + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path + * @return a Stream of tags for the specified project ID + * @throws GitLabApiException if any exception occurs + */ + public Stream getTagsStream(Object projectIdOrPath) throws GitLabApiException { + return (getTags(projectIdOrPath, getDefaultPerPage()).stream()); + } + /** * Get a specific repository tag determined by its name. * - * GET /projects/:id/repository/tags/:tagName + *
GitLab Endpoint: GET /projects/:id/repository/tags/:tagName
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param tagName the name of the tag to fetch the info for @@ -89,7 +101,7 @@ public class TagsApi extends AbstractApi { /** * Get an Optional instance holding a Tag instance of a specific repository tag determined by its name. * - * GET /projects/:id/repository/tags/:tagName + *
GitLab Endpoint: GET /projects/:id/repository/tags/:tagName
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param tagName the name of the tag to fetch the info for @@ -107,7 +119,7 @@ public class TagsApi extends AbstractApi { /** * Creates a tag on a particular ref of the given project. A message and release notes are optional. * - * POST /projects/:id/repository/tags + *
GitLab Endpoint: POST /projects/:id/repository/tags
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param tagName The name of the tag Must be unique for the project @@ -134,7 +146,7 @@ public class TagsApi extends AbstractApi { * release notes are optional. This method is the same as {@link #createTag(Object, String, String, String, String)}, * but instead allows the release notes to be supplied in a file. * - * POST /projects/:id/repository/tags + *
GitLab Endpoint: POST /projects/:id/repository/tags
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param tagName the name of the tag, must be unique for the project @@ -163,7 +175,7 @@ public class TagsApi extends AbstractApi { /** * Deletes the tag from a project with the specified tag name. * - * DELETE /projects/:id/repository/tags/:tag_name + *
GitLab Endpoint: DELETE /projects/:id/repository/tags/:tag_name
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param tagName The name of the tag to delete @@ -177,7 +189,7 @@ public class TagsApi extends AbstractApi { /** * Add release notes to the existing git tag. * - * POST /projects/:id/repository/tags/:tagName/release + *
GitLab Endpoint: POST /projects/:id/repository/tags/:tagName/release
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param tagName the name of a tag @@ -195,7 +207,7 @@ public class TagsApi extends AbstractApi { /** * Updates the release notes of a given release. * - * PUT /projects/:id/repository/tags/:tagName/release + *
GitLab Endpoint: PUT /projects/:id/repository/tags/:tagName/release
* * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path * @param tagName the name of a tag diff --git a/src/main/java/org/gitlab4j/api/UserApi.java b/src/main/java/org/gitlab4j/api/UserApi.java index e366ed09..01dbeded 100644 --- a/src/main/java/org/gitlab4j/api/UserApi.java +++ b/src/main/java/org/gitlab4j/api/UserApi.java @@ -14,6 +14,7 @@ import java.util.Date; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; /** * This class provides an entry point to all the GitLab API users calls. @@ -41,23 +42,21 @@ public class UserApi extends AbstractApi { } /** - * Get a list of users. Only returns the first page - *

- * GET /users + * Get a list of users. * - * @return a list of Users, this list will only contain the first 100 users in the system. + *

GitLab Endpoint: GET /users
+ * + * @return a list of Users * @throws GitLabApiException if any exception occurs */ public List getUsers() throws GitLabApiException { - Response response = get(Response.Status.OK, getDefaultPerPageParam(customAttributesEnabled), "users"); - return (response.readEntity(new GenericType>() { - })); + return (getUsers(getDefaultPerPage()).all()); } /** * Get a list of users using the specified page and per page settings. - *

- * GET /users + * + *

GitLab Endpoint: GET /users
* * @param page the page to get * @param perPage the number of users per page @@ -66,14 +65,13 @@ public class UserApi extends AbstractApi { */ public List getUsers(int page, int perPage) throws GitLabApiException { Response response = get(Response.Status.OK, getPageQueryParams(page, perPage, customAttributesEnabled), "users"); - return (response.readEntity(new GenericType>() { - })); + return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of users. - *

- * GET /users + * + *

GitLab Endpoint: GET /users
* * @param itemsPerPage the number of User instances that will be fetched per page * @return a Pager of User @@ -84,28 +82,35 @@ public class UserApi extends AbstractApi { } /** - * Get a list of active users. Only returns the first page - *

- * GET /users?active=true + * Get a Stream of users. + * + *

GitLab Endpoint: GET /users
+ * + * @return a Stream of Users. + * @throws GitLabApiException if any exception occurs + */ + public Stream getUsersStream() throws GitLabApiException { + return (getUsers(getDefaultPerPage()).stream()); + } + + /** + * Get a list of active users + * + *
GitLab Endpoint: GET /users?active=true
* - * @return a list of active Users, this list will only contain the first 100 users in the system. + * @return a list of active Users * @throws GitLabApiException if any exception occurs */ public List getActiveUsers() throws GitLabApiException { - GitLabApiForm formData = createGitLabApiForm() - .withParam("active", true) - .withParam(PER_PAGE_PARAM, getDefaultPerPage()); - Response response = get(Response.Status.OK, formData.asMap(), "users"); - return (response.readEntity(new GenericType>() { - })); + return (getActiveUsers(getDefaultPerPage()).all()); } /** * Get a list of active users using the specified page and per page settings. - *

- * GET /users?active=true * - * @param page the page to get + *

GitLab Endpoint: GET /users?active=true
+ * + * @param page the page to get * @param perPage the number of users per page * @return the list of active Users in the specified range * @throws GitLabApiException if any exception occurs @@ -116,14 +121,13 @@ public class UserApi extends AbstractApi { .withParam(PAGE_PARAM, page) .withParam(PER_PAGE_PARAM, perPage); Response response = get(Response.Status.OK, formData.asMap(), "users"); - return (response.readEntity(new GenericType>() { - })); + return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of active users. - *

- * GET /users?active=true + * + *

GitLab Endpoint: GET /users?active=true
* * @param itemsPerPage the number of active User instances that will be fetched per page * @return a Pager of active User @@ -134,10 +138,22 @@ public class UserApi extends AbstractApi { return (new Pager(this, User.class, itemsPerPage, formData.asMap(), "users")); } + /** + * Get a Stream of active users + * + *
GitLab Endpoint: GET /users?active=true
+ * + * @return a Stream of active Users + * @throws GitLabApiException if any exception occurs + */ + public Stream getActiveUsersStream() throws GitLabApiException { + return (getActiveUsers(getDefaultPerPage()).stream()); + } + /** * Blocks the specified user. Available only for admin. - *

- * POST /users/:id/block + * + *

GitLab Endpoint: POST /users/:id/block
* * @param userId the ID of the user to block * @throws GitLabApiException if any exception occurs @@ -156,8 +172,8 @@ public class UserApi extends AbstractApi { /** * Unblocks the specified user. Available only for admin. - *

- * POST /users/:id/unblock + * + *

GitLab Endpoint: POST /users/:id/unblock
* * @param userId the ID of the user to unblock * @throws GitLabApiException if any exception occurs @@ -176,26 +192,21 @@ public class UserApi extends AbstractApi { } /** - * Get a list of blocked users. Only returns the first page - *

- * GET /users?blocked=true + * Get a list of blocked users. * - * @return a list of blocked Users, this list will only contain the first 100 users in the system. + *

GitLab Endpoint: GET /users?blocked=true
+ * + * @return a list of blocked Users * @throws GitLabApiException if any exception occurs */ public List getBlockedUsers() throws GitLabApiException { - GitLabApiForm formData = createGitLabApiForm() - .withParam("blocked", true) - .withParam(PER_PAGE_PARAM, getDefaultPerPage()); - Response response = get(Response.Status.OK, formData.asMap(), "users"); - return (response.readEntity(new GenericType>() { - })); + return (getBlockedUsers(getDefaultPerPage()).all()); } /** * Get a list of blocked users using the specified page and per page settings. - *

- * GET /users?blocked=true + * + *

GitLab Endpoint: GET /users?blocked=true
* * @param page the page to get * @param perPage the number of users per page @@ -208,14 +219,13 @@ public class UserApi extends AbstractApi { .withParam(PAGE_PARAM, page) .withParam(PER_PAGE_PARAM, perPage); Response response = get(Response.Status.OK, formData.asMap(), "users"); - return (response.readEntity(new GenericType>() { - })); + return (response.readEntity(new GenericType>() {})); } /** * Get a Pager of blocked users. - *

- * GET /users?blocked=true + * + *

GitLab Endpoint: GET /users?blocked=true
* * @param itemsPerPage the number of blocked User instances that will be fetched per page * @return a Pager of blocked User @@ -226,10 +236,22 @@ public class UserApi extends AbstractApi { return (new Pager(this, User.class, itemsPerPage, formData.asMap(), "users")); } + /** + * Get a Stream of blocked users. + * + *
GitLab Endpoint: GET /users?blocked=true
+ * + * @return a Stream of blocked Users + * @throws GitLabApiException if any exception occurs + */ + public Stream getBlockedUsersStream() throws GitLabApiException { + return (getBlockedUsers(getDefaultPerPage()).stream()); + } + /** * Get a single user. - *

- * GET /users/:id + * + *

GitLab Endpoint: GET /users/:id
* * @param userId the ID of the user to get * @return the User instance for the specified user ID @@ -243,8 +265,8 @@ public class UserApi extends AbstractApi { /** * Get a single user as an Optional instance. - *

- * GET /users/:id + * + *

GitLab Endpoint: GET /users/:id
* * @param userId the ID of the user to get * @return the User for the specified user ID as an Optional instance @@ -259,10 +281,10 @@ public class UserApi extends AbstractApi { /** * Lookup a user by username. - *

- * NOTE: This is for admin users only. - *

- * GET /users?username=:username + * + *

NOTE: This is for admin users only.

+ * + *
GitLab Endpoint: GET /users?username=:username
* * @param username the username of the user to get * @return the User instance for the specified username @@ -271,17 +293,16 @@ public class UserApi extends AbstractApi { public User getUser(String username) throws GitLabApiException { GitLabApiForm formData = createGitLabApiForm().withParam("username", username, true); Response response = get(Response.Status.OK, formData.asMap(), "users"); - List users = response.readEntity(new GenericType>() { - }); + List users = response.readEntity(new GenericType>() {}); return (users.isEmpty() ? null : users.get(0)); } /** * Lookup a user by username and return an Optional instance. - *

- * NOTE: This is for admin users only. - *

- * GET /users?username=:username + * + *

NOTE: This is for admin users only.

+ * + *
GitLab Endpoint: GET /users?username=:username
* * @param username the username of the user to get * @return the User for the specified username as an Optional instance @@ -296,26 +317,21 @@ public class UserApi extends AbstractApi { /** * Search users by Email or username - *

- * GET /users?search=:email_or_username + * + *

GitLab Endpoint: GET /users?search=:email_or_username
* * @param emailOrUsername the email or username to search for * @return the User List with the email or username like emailOrUsername * @throws GitLabApiException if any exception occurs */ public List findUsers(String emailOrUsername) throws GitLabApiException { - GitLabApiForm formData = createGitLabApiForm() - .withParam("search", emailOrUsername, true) - .withParam(PER_PAGE_PARAM, getDefaultPerPage()); - Response response = get(Response.Status.OK, formData.asMap(), "users"); - return (response.readEntity(new GenericType>() { - })); + return (findUsers(emailOrUsername, getDefaultPerPage()).all()); } /** * Search users by Email or username in the specified page range. - *

- * GET /users?search=:email_or_username + * + *

GitLab Endpoint: GET /users?search=:email_or_username
* * @param emailOrUsername the email or username to search for * @param page the page to get @@ -335,8 +351,8 @@ public class UserApi extends AbstractApi { /** * Search users by Email or username and return a Pager - *

- * GET /users?search=:email_or_username + * + *

GitLab Endpoint: GET /users?search=:email_or_username
* * @param emailOrUsername the email or username to search for * @param itemsPerPage the number of Project instances that will be fetched per page @@ -348,16 +364,29 @@ public class UserApi extends AbstractApi { return (new Pager(this, User.class, itemsPerPage, formData.asMap(), "users")); } + /** + * Search users by Email or username. + * + *
GitLab Endpoint: GET /users?search=:email_or_username
+ * + * @param emailOrUsername the email or username to search for + * @return a Stream of User instances with the email or username like emailOrUsername + * @throws GitLabApiException if any exception occurs + */ + public Stream findUsersStream(String emailOrUsername) throws GitLabApiException { + return (findUsers(emailOrUsername, getDefaultPerPage()).stream()); + } + /** *

Creates a new user. Note only administrators can create new users. - * Either password or reset_password should be specified (reset_password takes priority). - *

- * If both the User object's projectsLimit and the parameter projectsLimit is specified + * Either password or reset_password should be specified (reset_password takes priority).

+ * + *

If both the User object's projectsLimit and the parameter projectsLimit is specified * the parameter will take precedence.

* - *
POST /users
- *

- * The following properties of the provided User instance can be set during creation:

 email (required) - Email
+     * 
GitLab Endpoint: POST /users
+ * + *

The following properties of the provided User instance can be set during creation:

 email (required) - Email
      * username (required) - Username
      * name (required) - Name
      * skype (optional) - Skype ID
@@ -394,9 +423,9 @@ public class UserApi extends AbstractApi {
      * 

Creates a new user. Note only administrators can create new users. * Either password or resetPassword should be specified (resetPassword takes priority).

* - *
POST /users
- *

- * The following properties of the provided User instance can be set during creation:

 email (required) - Email
+     * 
GitLab Endpoint: POST /users
+ * + *

The following properties of the provided User instance can be set during creation:

 email (required) - Email
      * username (required) - Username
      * name (required) - Name
      * skype (optional) - Skype ID
@@ -431,9 +460,9 @@ public class UserApi extends AbstractApi {
     /**
      * 

Modifies an existing user. Only administrators can change attributes of a user.

* - *
PUT /users
- *

- * The following properties of the provided User instance can be set during update:

 email (required) - Email
+     * 
GitLab Endpoint: PUT /users
+ * + *

The following properties of the provided User instance can be set during update:

 email (required) - Email
      * username (required) - Username
      * name (required) - Name
      * skype (optional) - Skype ID
@@ -467,9 +496,9 @@ public class UserApi extends AbstractApi {
     /**
      * Modifies an existing user. Only administrators can change attributes of a user.
      *
-     * 
PUT /users/:id
- *

- * The following properties of the provided User instance can be set during update:

 email (required) - Email
+     * 
GitLab Endpoint: PUT /users/:id
+ * + *

The following properties of the provided User instance can be set during update:

 email (required) - Email
      * username (required) - Username
      * name (required) - Name
      * skype (optional) - Skype ID
@@ -505,67 +534,36 @@ public class UserApi extends AbstractApi {
 
     /**
      * Deletes a user. Available only for administrators.
-     * 

- * DELETE /users/:id * - * @param userId the user ID to delete - * @throws GitLabApiException if any exception occurs - */ - public void deleteUser(Integer userId) throws GitLabApiException { - deleteUser(userId, null); - } - - /** - * Deletes a user. Available only for administrators. - *

- * DELETE /users/:id + *

GitLab Endpoint: DELETE /users/:id
* - * @param userId the user ID to delete - * @param hardDelete If true, contributions that would usually be moved to the - * ghost user will be deleted instead, as well as groups owned solely by this user + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @throws GitLabApiException if any exception occurs */ - public void deleteUser(Integer userId, Boolean hardDelete) throws GitLabApiException { - - if (userId == null) { - throw new RuntimeException("userId cannot be null"); - } - - GitLabApiForm formData = new GitLabApiForm().withParam("hard_delete ", hardDelete); - Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, formData.asMap(), "users", userId); + public void deleteUser(Object userIdOrUsername) throws GitLabApiException { + deleteUser(userIdOrUsername, null); } /** * Deletes a user. Available only for administrators. - *

- * DELETE /users/:id * - * @param user the User instance to delete - * @throws GitLabApiException if any exception occurs - */ - public void deleteUser(User user) throws GitLabApiException { - deleteUser(user.getId(), null); - } - - /** - * Deletes a user. Available only for administrators. - *

- * DELETE /users/:id + *

GitLab Endpoint: DELETE /users/:id
* - * @param user the User instance to delete + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param hardDelete If true, contributions that would usually be moved to the * ghost user will be deleted instead, as well as groups owned solely by this user * @throws GitLabApiException if any exception occurs */ - public void deleteUser(User user, Boolean hardDelete) throws GitLabApiException { - deleteUser(user.getId(), hardDelete); + public void deleteUser(Object userIdOrUsername, Boolean hardDelete) throws GitLabApiException { + GitLabApiForm formData = new GitLabApiForm().withParam("hard_delete ", hardDelete); + Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); + delete(expectedStatus, formData.asMap(), "users", getUserIdOrUsername(userIdOrUsername)); } /** * Get currently authenticated user. - *

- * GET /user + * + *

GitLab Endpoint: GET /user
* * @return the User instance for the currently authenticated user * @throws GitLabApiException if any exception occurs @@ -577,24 +575,23 @@ public class UserApi extends AbstractApi { /** * Get a list of currently authenticated user's SSH keys. - *

- * GET /user/keys + * + *

GitLab Endpoint: GET /user/keys
* * @return a list of currently authenticated user's SSH keys * @throws GitLabApiException if any exception occurs */ public List getSshKeys() throws GitLabApiException { Response response = get(Response.Status.OK, getDefaultPerPageParam(), "user", "keys"); - return (response.readEntity(new GenericType>() { - })); + return (response.readEntity(new GenericType>() {})); } /** * Get a list of a specified user's SSH keys. Available only for admin users. - *

- * GET /users/:id/keys * - * @param userId the ID of the user to get SSH keys for + *

GitLab Endpoint: GET /users/:id/keys
+ * + * @param userId the user ID to get the SSH keys for * @return a list of a specified user's SSH keys * @throws GitLabApiException if any exception occurs */ @@ -605,14 +602,10 @@ public class UserApi extends AbstractApi { } Response response = get(Response.Status.OK, getDefaultPerPageParam(), "users", userId, "keys"); - List keys = response.readEntity(new GenericType>() { - }); - if (keys == null) { - return (keys); - } + List keys = response.readEntity(new GenericType>() {}); - for (SshKey key : keys) { - key.setUserId(userId); + if (keys != null) { + keys.forEach(key -> key.setUserId(userId)); } return (keys); @@ -620,8 +613,8 @@ public class UserApi extends AbstractApi { /** * Get a single SSH Key. - *

- * GET /user/keys/:key_id + * + *

GitLab Endpoint: GET /user/keys/:key_id
* * @param keyId the ID of the SSH key. * @return an SshKey instance holding the info on the SSH key specified by keyId @@ -634,8 +627,8 @@ public class UserApi extends AbstractApi { /** * Get a single SSH Key as an Optional instance. - *

- * GET /user/keys/:key_id + * + *

GitLab Endpoint: GET /user/keys/:key_id
* * @param keyId the ID of the SSH key * @return an SshKey as an Optional instance holding the info on the SSH key specified by keyId @@ -650,8 +643,8 @@ public class UserApi extends AbstractApi { /** * Creates a new key owned by the currently authenticated user. - *

- * POST /user/keys + * + *

GitLab Endpoint: POST /user/keys
* * @param title the new SSH Key's title * @param key the new SSH key @@ -666,8 +659,8 @@ public class UserApi extends AbstractApi { /** * Create new key owned by specified user. Available only for admin users. - *

- * POST /users/:id/keys + * + *

GitLab Endpoint: POST /users/:id/keys
* * @param userId the ID of the user to add the SSH key for * @param title the new SSH Key's title @@ -694,8 +687,8 @@ public class UserApi extends AbstractApi { /** * Deletes key owned by currently authenticated user. This is an idempotent function and calling it * on a key that is already deleted or not available results in success. - *

- * DELETE /user/keys/:key_id + * + *

GitLab Endpoint: DELETE /user/keys/:key_id
* * @param keyId the key ID to delete * @throws GitLabApiException if any exception occurs @@ -712,100 +705,86 @@ public class UserApi extends AbstractApi { /** * Deletes key owned by a specified user. Available only for admin users. - *

- * DELETE /users/:id/keys/:key_id * - * @param userId the user ID of the user to delete the key for + *

GitLab Endpoint: DELETE /users/:id/keys/:key_id
+ * + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param keyId the key ID to delete * @throws GitLabApiException if any exception occurs */ - public void deleteSshKey(Integer userId, Integer keyId) throws GitLabApiException { - - if (userId == null) { - throw new RuntimeException("userId cannot be null"); - } + public void deleteSshKey(Object userIdOrUsername, Integer keyId) throws GitLabApiException { if (keyId == null) { throw new RuntimeException("keyId cannot be null"); } Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, null, "users", userId, "keys", keyId); + delete(expectedStatus, null, "users", getUserIdOrUsername(userIdOrUsername), "keys", keyId); } /** * Get a list of a specified user's impersonation tokens. Available only for admin users. - *

- * GET /users/:id/impersonation_tokens * - * @param userId the ID of the user to get impersonation tokens for + *

GitLab Endpoint: GET /users/:id/impersonation_tokens
+ * + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @return a list of a specified user's impersonation tokens * @throws GitLabApiException if any exception occurs */ - public List getImpersonationTokens(Integer userId) throws GitLabApiException { - return (getImpersonationTokens(userId, null)); + public List getImpersonationTokens(Object userIdOrUsername) throws GitLabApiException { + return (getImpersonationTokens(userIdOrUsername, null)); } /** * Get a list of a specified user's impersonation tokens. Available only for admin users. - *

- * GET /users/:id/impersonation_tokens * - * @param userId the ID of the user to get impersonation tokens for + *

GitLab Endpoint: GET /users/:id/impersonation_tokens
+ * + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param state the state of impersonation tokens to list (ALL, ACTIVE, INACTIVE) * @return a list of a specified user's impersonation tokens * @throws GitLabApiException if any exception occurs */ - public List getImpersonationTokens(Integer userId, ImpersonationState state) throws GitLabApiException { - - if (userId == null) { - throw new RuntimeException("userId cannot be null"); - } - + public List getImpersonationTokens(Object userIdOrUsername, ImpersonationState state) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() .withParam("state", state) .withParam(PER_PAGE_PARAM, getDefaultPerPage()); - Response response = get(Response.Status.OK, formData.asMap(), "users", userId, "impersonation_tokens"); - return (response.readEntity(new GenericType>() { - })); + Response response = get(Response.Status.OK, formData.asMap(), "users", getUserIdOrUsername(userIdOrUsername), "impersonation_tokens"); + return (response.readEntity(new GenericType>() {})); } /** * Get an impersonation token of a user. Available only for admin users. - *

- * GET /users/:user_id/impersonation_tokens/:impersonation_token_id * - * @param userId the ID of the user to get SSH keys for + *

GitLab Endpoint: GET /users/:user_id/impersonation_tokens/:impersonation_token_id
+ * + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param tokenId the impersonation token ID to get * @return the specified impersonation token * @throws GitLabApiException if any exception occurs */ - public ImpersonationToken getImpersonationToken(Integer userId, Integer tokenId) throws GitLabApiException { - - if (userId == null) { - throw new RuntimeException("userId cannot be null"); - } + public ImpersonationToken getImpersonationToken(Object userIdOrUsername, Integer tokenId) throws GitLabApiException { if (tokenId == null) { throw new RuntimeException("tokenId cannot be null"); } - Response response = get(Response.Status.OK, null, "users", userId, "impersonation_tokens", tokenId); + Response response = get(Response.Status.OK, null, "users", getUserIdOrUsername(userIdOrUsername), "impersonation_tokens", tokenId); return (response.readEntity(ImpersonationToken.class)); } /** * Get an impersonation token of a user as an Optional instance. Available only for admin users. - *

- * GET /users/:user_id/impersonation_tokens/:impersonation_token_id * - * @param userId the ID of the user to get SSH keys for + *

GitLab Endpoint: GET /users/:user_id/impersonation_tokens/:impersonation_token_id
+ * + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param tokenId the impersonation token ID to get * @return the specified impersonation token as an Optional instance */ - public Optional getOptionalImpersonationToken(Integer userId, Integer tokenId) { + public Optional getOptionalImpersonationToken(Object userIdOrUsername, Integer tokenId) { try { - return (Optional.ofNullable(getImpersonationToken(userId, tokenId))); + return (Optional.ofNullable(getImpersonationToken(userIdOrUsername, tokenId))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } @@ -813,21 +792,17 @@ public class UserApi extends AbstractApi { /** * Create an impersonation token. Available only for admin users. - *

- * POST /users/:user_id/impersonation_tokens * - * @param userId the ID of the user to get SSH keys for - * @param name the name of the impersonation token, required + *

GitLab Endpoint: POST /users/:user_id/impersonation_tokens
+ * + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance + * @param name the name of the impersonation token, required * @param expiresAt the expiration date of the impersonation token, optional - * @param scopes an array of scopes of the impersonation token + * @param scopes an array of scopes of the impersonation token * @return the created ImpersonationToken instance * @throws GitLabApiException if any exception occurs */ - public ImpersonationToken createImpersonationToken(Integer userId, String name, Date expiresAt, Scope[] scopes) throws GitLabApiException { - - if (userId == null) { - throw new RuntimeException("userId cannot be null"); - } + public ImpersonationToken createImpersonationToken(Object userIdOrUsername, String name, Date expiresAt, Scope[] scopes) throws GitLabApiException { if (scopes == null || scopes.length == 0) { throw new RuntimeException("scopes cannot be null or empty"); @@ -841,31 +816,27 @@ public class UserApi extends AbstractApi { formData.withParam("scopes[]", scope.toString()); } - Response response = post(Response.Status.CREATED, formData, "users", userId, "impersonation_tokens"); + Response response = post(Response.Status.CREATED, formData, "users", getUserIdOrUsername(userIdOrUsername), "impersonation_tokens"); return (response.readEntity(ImpersonationToken.class)); } /** * Revokes an impersonation token. Available only for admin users. - *

- * DELETE /users/:user_id/impersonation_tokens/:impersonation_token_id * - * @param userId the user ID of the user to revoke the impersonation token for + *

GitLab Endpoint: DELETE /users/:user_id/impersonation_tokens/:impersonation_token_id
+ * + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param tokenId the impersonation token ID to revoke * @throws GitLabApiException if any exception occurs */ - public void revokeImpersonationToken(Integer userId, Integer tokenId) throws GitLabApiException { - - if (userId == null) { - throw new RuntimeException("userId cannot be null"); - } + public void revokeImpersonationToken(Object userIdOrUsername, Integer tokenId) throws GitLabApiException { if (tokenId == null) { throw new RuntimeException("tokenId cannot be null"); } Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT); - delete(expectedStatus, null, "users", userId, "impersonation_tokens", tokenId); + delete(expectedStatus, null, "users", getUserIdOrUsername(userIdOrUsername), "impersonation_tokens", tokenId); } /** @@ -878,11 +849,13 @@ public class UserApi extends AbstractApi { * @return the populated Form instance */ Form userToForm(User user, Integer projectsLimit, CharSequence password, Boolean resetPassword, boolean create) { + if (create) { if ((password == null || password.toString().trim().isEmpty()) && !resetPassword) { throw new IllegalArgumentException("either password or reset_password must be set"); } } + projectsLimit = (projectsLimit == null) ? user.getProjectsLimit() : projectsLimit; String skipConfirmationFeildName = create ? "skip_confirmation" : "skip_reconfirmation"; @@ -912,31 +885,29 @@ public class UserApi extends AbstractApi { /** * Creates custom attribute for the given user * - * @param userId to set the customAttributes for - * @param customAttribute to set - * @return createdCustomAttribute + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance + * @param customAttribute the custom attribute to set + * @return the created CustomAttribute * @throws GitLabApiException on failure while setting customAttributes */ - public CustomAttribute createCustomAttribute(final Integer userId, final CustomAttribute customAttribute) throws GitLabApiException { + public CustomAttribute createCustomAttribute(final Object userIdOrUsername, final CustomAttribute customAttribute) throws GitLabApiException { if (Objects.isNull(customAttribute)) { throw new IllegalArgumentException("CustomAttributes can't be null"); } - return createCustomAttribute(userId, customAttribute.getKey(), customAttribute.getValue()); + return createCustomAttribute(userIdOrUsername, customAttribute.getKey(), customAttribute.getValue()); } /** * Creates custom attribute for the given user * - * @param userId to set the customAttributes for - * @param key for the customAttribute - * @param value for the customAttribute - * @return createdCustomAttribute + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance + * @param key for the customAttribute + * @param value or the customAttribute + * @return the created CustomAttribute * @throws GitLabApiException on failure while setting customAttributes */ - public CustomAttribute createCustomAttribute(final Integer userId, final String key, final String value) throws GitLabApiException { - if (Objects.isNull(userId)) { - throw new IllegalArgumentException("UserId can't be null."); - } + public CustomAttribute createCustomAttribute(final Object userIdOrUsername, final String key, final String value) throws GitLabApiException { + if (Objects.isNull(key) || key.trim().isEmpty()) { throw new IllegalArgumentException("Key can't be null or empty"); } @@ -944,73 +915,73 @@ public class UserApi extends AbstractApi { throw new IllegalArgumentException("Value can't be null or empty"); } - GitLabApiForm formData = new GitLabApiForm() - .withParam("value", value); - Response response = put(Response.Status.OK, formData.asMap(), "users", userId, "custom_attributes", key); + GitLabApiForm formData = new GitLabApiForm().withParam("value", value); + Response response = put(Response.Status.OK, formData.asMap(), + "users", getUserIdOrUsername(userIdOrUsername), "custom_attributes", key); return (response.readEntity(CustomAttribute.class)); } /** * Change custom attribute for the given user * - * @param userId to change the customAttributes for - * @param customAttribute to change - * @return changedCustomAttribute + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance + * @param customAttribute the custome attribute to change + * @return the changed CustomAttribute * @throws GitLabApiException on failure while changing customAttributes */ - public CustomAttribute changeCustomAttribute(final Integer userId, final CustomAttribute customAttribute) throws GitLabApiException { + public CustomAttribute changeCustomAttribute(final Object userIdOrUsername, final CustomAttribute customAttribute) throws GitLabApiException { + if (Objects.isNull(customAttribute)) { throw new IllegalArgumentException("CustomAttributes can't be null"); } //changing & creating custom attributes is the same call in gitlab api // -> https://docs.gitlab.com/ce/api/custom_attributes.html#set-custom-attribute - return createCustomAttribute(userId, customAttribute.getKey(), customAttribute.getValue()); + return createCustomAttribute(userIdOrUsername, customAttribute.getKey(), customAttribute.getValue()); } /** * Changes custom attribute for the given user * - * @param userId to change the customAttribute for + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param key for the customAttribute * @param value for the customAttribute * @return changedCustomAttribute * @throws GitLabApiException on failure while changing customAttributes */ - public CustomAttribute changeCustomAttribute(final Integer userId, final String key, final String value) throws GitLabApiException { - return createCustomAttribute(userId, key, value); + public CustomAttribute changeCustomAttribute(final Object userIdOrUsername, final String key, final String value) throws GitLabApiException { + return createCustomAttribute(userIdOrUsername, key, value); } /** * Delete a custom attribute for the given user * - * @param userId to delete the customAttribute for + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param customAttribute to remove * @throws GitLabApiException on failure while deleting customAttributes */ - public void deleteCustomAttribute(final Integer userId, final CustomAttribute customAttribute) throws GitLabApiException { + public void deleteCustomAttribute(final Object userIdOrUsername, final CustomAttribute customAttribute) throws GitLabApiException { if (Objects.isNull(customAttribute)) { throw new IllegalArgumentException("customAttributes can't be null"); } - deleteCustomAttribute(userId, customAttribute.getKey()); + deleteCustomAttribute(userIdOrUsername, customAttribute.getKey()); } /** * Delete a custom attribute for the given user * - * @param userId to delete the customAttribute for + * @param userIdOrUsername the user in the form of an Integer(ID), String(username), or User instance * @param key of the customAttribute to remove * @throws GitLabApiException on failure while deleting customAttributes */ - public void deleteCustomAttribute(final Integer userId, final String key) throws GitLabApiException { - if (Objects.isNull(userId)) { - throw new IllegalArgumentException("UserId can't be null"); - } + public void deleteCustomAttribute(final Object userIdOrUsername, final String key) throws GitLabApiException { + if (Objects.isNull(key) || key.trim().isEmpty()) { throw new IllegalArgumentException("Key can't be null or empty"); } - delete(Response.Status.OK, null, "users", userId, "custom_attributes", key); + + delete(Response.Status.OK, null, "users", getUserIdOrUsername(userIdOrUsername), "custom_attributes", key); } /** -- GitLab