Skip to content

Commit c262345

Browse files
authored
Add getProjectGroups() methods in the projects api (gitlab4j#909)
1 parent 3f55ecf commit c262345

File tree

7 files changed

+310
-86
lines changed

7 files changed

+310
-86
lines changed

src/main/java/org/gitlab4j/api/ProjectApi.java

+87-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import org.gitlab4j.api.models.ProjectApprovalsConfig;
5555
import org.gitlab4j.api.models.ProjectFetches;
5656
import org.gitlab4j.api.models.ProjectFilter;
57+
import org.gitlab4j.api.models.ProjectGroupsFilter;
58+
import org.gitlab4j.api.models.ProjectGroup;
5759
import org.gitlab4j.api.models.ProjectHook;
5860
import org.gitlab4j.api.models.ProjectUser;
5961
import org.gitlab4j.api.models.PushRules;
@@ -1624,7 +1626,7 @@ public Stream<Member> getAllMembersStream(Object projectIdOrPath, String query,
16241626
* @throws GitLabApiException if any exception occurs
16251627
*/
16261628
public Member getMember(Object projectIdOrPath, Long userId) throws GitLabApiException {
1627-
return (getMember(projectIdOrPath, userId, false));
1629+
return (getMember(projectIdOrPath, userId, false));
16281630
}
16291631

16301632
/**
@@ -1926,6 +1928,90 @@ public Stream<ProjectUser> getProjectUsersStream(Object projectIdOrPath, String
19261928
return (getProjectUsers(projectIdOrPath, search, getDefaultPerPage()).stream());
19271929
}
19281930

1931+
/**
1932+
* Get a list of the ancestor groups for a given project.
1933+
*
1934+
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
1935+
*
1936+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
1937+
* @return the ancestor groups for a given project
1938+
* @throws GitLabApiException if any exception occurs
1939+
*/
1940+
public List<ProjectGroup> getProjectGroups(Object projectIdOrPath) throws GitLabApiException {
1941+
return (getProjectGroups(projectIdOrPath, new ProjectGroupsFilter(), getDefaultPerPage()).all());
1942+
}
1943+
1944+
/**
1945+
* Get a Pager of the ancestor groups for a given project.
1946+
*
1947+
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
1948+
*
1949+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
1950+
* @param itemsPerPage the number of Project instances that will be fetched per page
1951+
* @return a Pager of the ancestor groups for a given project
1952+
* @throws GitLabApiException if any exception occurs
1953+
*/
1954+
public Pager<ProjectGroup> getProjectGroups(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
1955+
return (getProjectGroups(projectIdOrPath, new ProjectGroupsFilter(), itemsPerPage));
1956+
}
1957+
1958+
/**
1959+
* Get a Stream of the ancestor groups for a given project.
1960+
*
1961+
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
1962+
*
1963+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
1964+
* @return a Stream of the ancestor groups for a given project
1965+
* @throws GitLabApiException if any exception occurs
1966+
*/
1967+
public Stream<ProjectGroup> getProjectGroupsStream(Object projectIdOrPath) throws GitLabApiException {
1968+
return (getProjectGroups(projectIdOrPath, new ProjectGroupsFilter(), getDefaultPerPage()).stream());
1969+
}
1970+
1971+
/**
1972+
* Get a list of the ancestor groups for a given project matching the specified filter.
1973+
*
1974+
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
1975+
*
1976+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
1977+
* @param filter the ProjectGroupsFilter to match against
1978+
* @return the ancestor groups for a given project
1979+
* @throws GitLabApiException if any exception occurs
1980+
*/
1981+
public List<ProjectGroup> getProjectGroups(Object projectIdOrPath, ProjectGroupsFilter filter) throws GitLabApiException {
1982+
return (getProjectGroups(projectIdOrPath, filter, getDefaultPerPage()).all());
1983+
}
1984+
1985+
/**
1986+
* Get a Pager of the ancestor groups for a given project matching the specified filter.
1987+
*
1988+
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
1989+
*
1990+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
1991+
* @param filter the ProjectGroupsFilter to match against
1992+
* @param itemsPerPage the number of Project instances that will be fetched per page
1993+
* @return a Pager of the ancestor groups for a given project
1994+
* @throws GitLabApiException if any exception occurs
1995+
*/
1996+
public Pager<ProjectGroup> getProjectGroups(Object projectIdOrPath, ProjectGroupsFilter filter, int itemsPerPage) throws GitLabApiException {
1997+
GitLabApiForm formData = filter.getQueryParams();
1998+
return (new Pager<ProjectGroup>(this, ProjectGroup.class, itemsPerPage, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "groups"));
1999+
}
2000+
2001+
/**
2002+
* Get a Stream of the ancestor groups for a given project matching the specified filter.
2003+
*
2004+
* <pre><code>GitLab Endpoint: GET /projects/:id/groups</code></pre>
2005+
*
2006+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
2007+
* @param filter the ProjectGroupsFilter to match against
2008+
* @return a Stream of the ancestor groups for a given project
2009+
* @throws GitLabApiException if any exception occurs
2010+
*/
2011+
public Stream<ProjectGroup> getProjectGroupsStream(Object projectIdOrPath, ProjectGroupsFilter filter) throws GitLabApiException {
2012+
return (getProjectGroups(projectIdOrPath, filter, getDefaultPerPage()).stream());
2013+
}
2014+
19292015
/**
19302016
* Get the project events for specific project. Sorted from newest to latest.
19312017
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
2+
package org.gitlab4j.api.models;
3+
4+
import org.gitlab4j.api.utils.JacksonJson;
5+
6+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
7+
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public abstract class AbstractGroup<G extends AbstractGroup<G>> {
10+
11+
private Long id;
12+
private String name;
13+
private String avatarUrl;
14+
private String webUrl;
15+
private String fullName;
16+
private String fullPath;
17+
18+
public Long getId() {
19+
return this.id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public String getName() {
27+
return this.name;
28+
}
29+
30+
public void setName(String name) {
31+
this.name = name;
32+
}
33+
34+
public String getAvatarUrl() {
35+
return avatarUrl;
36+
}
37+
38+
public void setAvatarUrl(String avatarUrl) {
39+
this.avatarUrl = avatarUrl;
40+
}
41+
42+
public String getWebUrl() {
43+
return webUrl;
44+
}
45+
46+
public void setWebUrl(String webUrl) {
47+
this.webUrl = webUrl;
48+
}
49+
50+
public String getFullName() {
51+
return fullName;
52+
}
53+
54+
public void setFullName(String fullName) {
55+
this.fullName = fullName;
56+
}
57+
58+
public String getFullPath() {
59+
return fullPath;
60+
}
61+
62+
public void setFullPath(String fullPath) {
63+
this.fullPath = fullPath;
64+
}
65+
66+
@SuppressWarnings("unchecked")
67+
public G withId(Long id) {
68+
this.id = id;
69+
return (G)this;
70+
}
71+
72+
@SuppressWarnings("unchecked")
73+
public G withName(String name) {
74+
this.name = name;
75+
return (G)this;
76+
}
77+
78+
@SuppressWarnings("unchecked")
79+
public G withAvatarUrl(String avatarUrl) {
80+
this.avatarUrl = avatarUrl;
81+
return (G)this;
82+
}
83+
84+
@SuppressWarnings("unchecked")
85+
public G withWebUrl(String url) {
86+
this.webUrl = url;
87+
return (G)this;
88+
}
89+
90+
@SuppressWarnings("unchecked")
91+
public G withFullName(String fullName) {
92+
this.fullName = fullName;
93+
return (G)this;
94+
}
95+
96+
@SuppressWarnings("unchecked")
97+
public G withFullPath(String fullPath) {
98+
this.fullPath = fullPath;
99+
return (G)this;
100+
}
101+
102+
@Override
103+
public String toString() {
104+
return (JacksonJson.toJsonString(this));
105+
}
106+
}

src/main/java/org/gitlab4j/api/models/Group.java

+1-85
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.Date;
88
import java.util.List;
99

10-
public class Group {
10+
public class Group extends AbstractGroup<Group> {
1111

1212
public class Statistics {
1313
private Long storageSize;
@@ -49,17 +49,11 @@ public void setJobArtifactsSize(Long jobArtifactsSize) {
4949
}
5050

5151

52-
private Long id;
53-
private String name;
5452
private String path;
5553
private String description;
5654
private Visibility visibility;
5755
private Boolean lfsEnabled;
58-
private String avatarUrl;
59-
private String webUrl;
6056
private Boolean requestAccessEnabled;
61-
private String fullName;
62-
private String fullPath;
6357
private Long parentId;
6458
private Integer sharedRunnersMinutesLimit;
6559
private Statistics statistics;
@@ -71,22 +65,6 @@ public void setJobArtifactsSize(Long jobArtifactsSize) {
7165
@JsonSerialize(using = JacksonJson.DateOnlySerializer.class)
7266
private Date markedForDeletionOn;
7367

74-
public Long getId() {
75-
return this.id;
76-
}
77-
78-
public void setId(Long id) {
79-
this.id = id;
80-
}
81-
82-
public String getName() {
83-
return this.name;
84-
}
85-
86-
public void setName(String name) {
87-
this.name = name;
88-
}
89-
9068
public String getPath() {
9169
return this.path;
9270
}
@@ -119,22 +97,6 @@ public void setLfsEnabled(Boolean lfsEnabled) {
11997
this.lfsEnabled = lfsEnabled;
12098
}
12199

122-
public String getAvatarUrl() {
123-
return avatarUrl;
124-
}
125-
126-
public void setAvatarUrl(String avatarUrl) {
127-
this.avatarUrl = avatarUrl;
128-
}
129-
130-
public String getWebUrl() {
131-
return webUrl;
132-
}
133-
134-
public void setWebUrl(String webUrl) {
135-
this.webUrl = webUrl;
136-
}
137-
138100
public Boolean getRequestAccessEnabled() {
139101
return requestAccessEnabled;
140102
}
@@ -143,22 +105,6 @@ public void setRequestAccessEnabled(Boolean requestAccessEnabled) {
143105
this.requestAccessEnabled = requestAccessEnabled;
144106
}
145107

146-
public String getFullName() {
147-
return fullName;
148-
}
149-
150-
public void setFullName(String fullName) {
151-
this.fullName = fullName;
152-
}
153-
154-
public String getFullPath() {
155-
return fullPath;
156-
}
157-
158-
public void setFullPath(String fullPath) {
159-
this.fullPath = fullPath;
160-
}
161-
162108
public Long getParentId() {
163109
return parentId;
164110
}
@@ -223,16 +169,6 @@ public void setRunnersToken(String runnersToken) {
223169
this.runnersToken = runnersToken;
224170
}
225171

226-
public Group withId(Long id) {
227-
this.id = id;
228-
return this;
229-
}
230-
231-
public Group withName(String name) {
232-
this.name = name;
233-
return this;
234-
}
235-
236172
public Group withPath(String path) {
237173
this.path = path;
238174
return this;
@@ -253,31 +189,11 @@ public Group withlfsEnabled(boolean lfsEnabled) {
253189
return this;
254190
}
255191

256-
public Group withAvatarUrl(String avatarUrl) {
257-
this.avatarUrl = avatarUrl;
258-
return this;
259-
}
260-
261-
public Group withWebUrl(String url) {
262-
this.webUrl = url;
263-
return this;
264-
}
265-
266192
public Group withRequestAccessEnabled(boolean requestAccessEnabled) {
267193
this.requestAccessEnabled = requestAccessEnabled;
268194
return this;
269195
}
270196

271-
public Group withFullName(String fullName) {
272-
this.fullName = fullName;
273-
return this;
274-
}
275-
276-
public Group withFullPath(String fullPath) {
277-
this.fullPath = fullPath;
278-
return this;
279-
}
280-
281197
public Group withParentId(Long parentId) {
282198
this.parentId = parentId;
283199
return this;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.gitlab4j.api.models;
2+
3+
public class ProjectGroup extends AbstractGroup<ProjectGroup> {
4+
}

0 commit comments

Comments
 (0)