Skip to content

Commit e5c79cd

Browse files
committed
Initial commit (gitlab4j#268).
1 parent cc7cc38 commit e5c79cd

File tree

1 file changed

+219
-0
lines changed

1 file changed

+219
-0
lines changed
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
package org.gitlab4j.api.models;
2+
3+
import org.gitlab4j.api.Constants.ProjectOrderBy;
4+
import org.gitlab4j.api.Constants.SortOrder;
5+
import org.gitlab4j.api.Constants;
6+
import org.gitlab4j.api.GitLabApiForm;
7+
8+
/**
9+
* This class is used to filter Projects when getting lists of projects for a specified user.
10+
*/
11+
public class ProjectFilter {
12+
13+
private Boolean archived;
14+
private Visibility visibility;
15+
private ProjectOrderBy orderBy;
16+
private SortOrder sort;
17+
private String search;
18+
private Boolean simple;
19+
private Boolean owned;
20+
private Boolean membership;
21+
private Boolean starred;
22+
private Boolean statistics;
23+
private Boolean withCustomAttributes;
24+
private Boolean withIssuesEnabled;
25+
private Boolean withMergeRequestsEnabled;
26+
private AccessLevel minAccessLevel;
27+
28+
/**
29+
* Limit by archived status.
30+
*
31+
* @param archived if true will only return archived projects
32+
* @return the reference to this ProjectFilter instance
33+
*/
34+
public ProjectFilter withArchived(Boolean archived) {
35+
this.archived = archived;
36+
return (this);
37+
}
38+
39+
/**
40+
* Limit by visibility public, internal, or private.
41+
*
42+
* @param visibility the visibility to match
43+
* @return the reference to this ProjectFilter instance
44+
*/
45+
public ProjectFilter withVisibility(Visibility visibility) {
46+
this.visibility = visibility;
47+
return (this);
48+
}
49+
50+
/**
51+
* Return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields. Default is created_at.
52+
*
53+
* @param orderBy specifies what field to order by
54+
* @return the reference to this ProjectFilter instance
55+
*/
56+
public ProjectFilter withOrderBy(ProjectOrderBy orderBy) {
57+
this.orderBy = orderBy;
58+
return (this);
59+
}
60+
61+
/**
62+
* Return projects sorted in asc or desc order. Default is desc.
63+
*
64+
* @param sort sort direction, ASC or DESC
65+
* @return the reference to this ProjectFilter instance
66+
*/
67+
public ProjectFilter withSortOder(SortOrder sort) {
68+
this.sort = sort;
69+
return (this);
70+
}
71+
72+
/**
73+
* Return list of projects matching the search criteria.
74+
*
75+
* @param search the search criteria
76+
* @return the reference to this ProjectFilter instance
77+
*/
78+
public ProjectFilter withSearch(String search) {
79+
this.search = search;
80+
return (this);
81+
}
82+
83+
/**
84+
* Return only limited fields for each project. This is a no-op without
85+
* authentication as then only simple fields are returned.
86+
*
87+
* @param simple if true, return only limited fields for each project
88+
* @return the reference to this ProjectFilter instance
89+
*/
90+
public ProjectFilter withSimple(Boolean simple) {
91+
this.simple = simple;
92+
return (this);
93+
}
94+
95+
/**
96+
* Limit by projects explicitly owned by the current user
97+
*
98+
* @param owned if true, limit to projects explicitly owned by the current user
99+
* @return the reference to this ProjectFilter instance
100+
*/
101+
public ProjectFilter withOwned(Boolean owned) {
102+
this.owned = owned;
103+
return (this);
104+
}
105+
106+
/**
107+
* Limit by projects that the current user is a member of
108+
*
109+
* @param membership if true, limit by projects that the current user is a member of
110+
* @return the reference to this ProjectFilter instance
111+
*/
112+
public ProjectFilter withMembership(Boolean membership) {
113+
this.membership = membership;
114+
return (this);
115+
}
116+
117+
/**
118+
* Limit by projects starred by the current user.
119+
*
120+
* @param starred if true, limit by projects starred by the current user
121+
* @return the reference to this ProjectFilter instance
122+
*/
123+
public ProjectFilter withStarred(Boolean starred) {
124+
this.starred = starred;
125+
return (this);
126+
}
127+
128+
/**
129+
* Include project statistics.
130+
*
131+
* @param statistics if true, include project statistics
132+
* @return the reference to this ProjectFilter instance
133+
*/
134+
public ProjectFilter withStatistics(Boolean statistics) {
135+
this.statistics = statistics;
136+
return (this);
137+
}
138+
139+
/**
140+
* Include custom attributes in response (admins only).
141+
*
142+
* @param withCustomAttributes if true, include custom attributes in the repsonse
143+
* @return the reference to this ProjectFilter instance
144+
*/
145+
public ProjectFilter withCustomAttributes(Boolean withCustomAttributes) {
146+
this.withCustomAttributes = withCustomAttributes;
147+
return (this);
148+
}
149+
150+
/**
151+
* Limit by enabled issues feature
152+
*
153+
* @param withIssuesEnabled if true, limit by enabled issues feature
154+
* @return the reference to this ProjectFilter instance
155+
*/
156+
public ProjectFilter withIssuesEnabled(Boolean withIssuesEnabled) {
157+
this.withIssuesEnabled = withIssuesEnabled;
158+
return (this);
159+
}
160+
161+
/**
162+
* Limit by enabled merge requests feature
163+
*
164+
* @param withMergeRequestsEnabled if true, imit by enabled merge requests feature
165+
* @return the reference to this ProjectFilter instance
166+
*/
167+
public ProjectFilter withMergeRequestsEnabled(Boolean withMergeRequestsEnabled) {
168+
this.withMergeRequestsEnabled = withMergeRequestsEnabled;
169+
return (this);
170+
}
171+
172+
/**
173+
* Limit by current user minimal access level
174+
*
175+
* @param minAccessLevel limit by current user minimal access level
176+
* @return the reference to this ProjectFilter instance
177+
*/
178+
public ProjectFilter minAccessLevel(AccessLevel minAccessLevel) {
179+
this.minAccessLevel = minAccessLevel;
180+
return (this);
181+
}
182+
183+
/**
184+
* Get the query params specified by this filter.
185+
*
186+
* @param page specifies the page number
187+
* @param perPage specifies the number of items per page
188+
* @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance
189+
*/
190+
public GitLabApiForm getQueryParams(int page, int perPage) {
191+
return (getQueryParams()
192+
.withParam(Constants.PAGE_PARAM, page)
193+
.withParam(Constants.PER_PAGE_PARAM, perPage));
194+
}
195+
196+
/**
197+
* Get the query params specified by this filter.
198+
*
199+
* @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance
200+
*/
201+
public GitLabApiForm getQueryParams() {
202+
return (new GitLabApiForm()
203+
.withParam("archived", archived)
204+
.withParam("visibility", visibility)
205+
.withParam("order_by", orderBy)
206+
.withParam("sort", sort)
207+
.withParam("search", search)
208+
.withParam("simple", simple)
209+
.withParam("owned", owned)
210+
.withParam("membership", membership)
211+
.withParam("starred", starred)
212+
.withParam("statistics", statistics)
213+
.withParam("with_custom_attributes", withCustomAttributes)
214+
.withParam("with_issues_enabled", withIssuesEnabled)
215+
.withParam("with_merge_requests_enabled ", withMergeRequestsEnabled))
216+
.withParam("min_access_level ", (minAccessLevel != null ? minAccessLevel.toValue() : null)
217+
);
218+
}
219+
}

0 commit comments

Comments
 (0)