diff --git a/src/main/java/org/gitlab4j/api/GroupApi.java b/src/main/java/org/gitlab4j/api/GroupApi.java index 82d05b905becb64b3bb615fef7ac4e54317dae2b..5ef3c960d9ebd9f3b9c2d29bd051be3819c584bd 100644 --- a/src/main/java/org/gitlab4j/api/GroupApi.java +++ b/src/main/java/org/gitlab4j/api/GroupApi.java @@ -778,9 +778,7 @@ public class GroupApi extends AbstractApi { * @throws GitLabApiException if any exception occurs */ 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() {})); + return (getMember(groupIdOrPath, userId, false)); } /** @@ -794,7 +792,46 @@ public class GroupApi extends AbstractApi { */ public Optional getOptionalMember(Object groupIdOrPath, int userId) { try { - return (Optional.ofNullable(getMember(groupIdOrPath, userId))); + return (Optional.ofNullable(getMember(groupIdOrPath, userId, false))); + } catch (GitLabApiException glae) { + return (GitLabApi.createOptionalFromException(glae)); + } + } + + /** + * Gets a group team member, optionally including inherited member. + * + *
GitLab Endpoint: GET /projects/:id/members/all/:user_id
+ * + * @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 + * @param includeInherited if true will the member even if inherited thru an ancestor group + * @return the member specified by the project ID/user ID pair + * @throws GitLabApiException if any exception occurs + */ + public Member getMember(Object groupIdOrPath, Integer userId, Boolean includeInherited) throws GitLabApiException { + Response response; + if (includeInherited) { + response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "members", "all", userId); + } else { + response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "members", userId); + } + return (response.readEntity(Member.class)); + } + + /** + * Gets a group team member, optionally including inherited member. + * + *
GitLab Endpoint: GET /projects/:id/members/:user_id
+ * + * @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 + * @param includeInherited if true will the member even if inherited thru an ancestor group + * @return the member specified by the group ID/user ID pair as the value of an Optional + */ + public Optional getOptionalMember(Object groupIdOrPath, Integer userId, Boolean includeInherited) { + try { + return (Optional.ofNullable(getMember(groupIdOrPath, userId, includeInherited))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } diff --git a/src/main/java/org/gitlab4j/api/ProjectApi.java b/src/main/java/org/gitlab4j/api/ProjectApi.java index 88ddab1ed97870d5bd03cad6f7d85814dba50fd7..a9ff3c20b53929a812c6d0bd1d7a6c32bd6f4cbd 100644 --- a/src/main/java/org/gitlab4j/api/ProjectApi.java +++ b/src/main/java/org/gitlab4j/api/ProjectApi.java @@ -1540,8 +1540,7 @@ public class ProjectApi extends AbstractApi implements Constants { * @throws GitLabApiException if any exception occurs */ public Member getMember(Object projectIdOrPath, Integer userId) throws GitLabApiException { - Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "members", userId); - return (response.readEntity(Member.class)); + return (getMember(projectIdOrPath, userId, false)); } /** @@ -1555,7 +1554,46 @@ public class ProjectApi extends AbstractApi implements Constants { */ public Optional getOptionalMember(Object projectIdOrPath, Integer userId) { try { - return (Optional.ofNullable(getMember(projectIdOrPath, userId))); + return (Optional.ofNullable(getMember(projectIdOrPath, userId, false))); + } catch (GitLabApiException glae) { + return (GitLabApi.createOptionalFromException(glae)); + } + } + + /** + * Gets a project team member, optionally including inherited member. + * + *
GitLab Endpoint: GET /projects/:id/members/all/:user_id
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param userId the user ID of the member + * @param includeInherited if true will the member even if inherited thru an ancestor group + * @return the member specified by the project ID/user ID pair + * @throws GitLabApiException if any exception occurs + */ + public Member getMember(Object projectIdOrPath, Integer userId, Boolean includeInherited) throws GitLabApiException { + Response response; + if (includeInherited) { + response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "members", "all", userId); + } else { + response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "members", userId); + } + return (response.readEntity(Member.class)); + } + + /** + * Gets a project team member, optionally including inherited member. + * + *
GitLab Endpoint: GET /projects/:id/members/:user_id
+ * + * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance + * @param userId the user ID of the member + * @param includeInherited if true will the member even if inherited thru an ancestor group + * @return the member specified by the project ID/user ID pair as the value of an Optional + */ + public Optional getOptionalMember(Object projectIdOrPath, Integer userId, Boolean includeInherited) { + try { + return (Optional.ofNullable(getMember(projectIdOrPath, userId, includeInherited))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); }