|
| 1 | +package org.gitlab4j.api.models; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import org.gitlab4j.api.Constants.GroupOrderBy; |
| 6 | +import org.gitlab4j.api.Constants.SortOrder; |
| 7 | +import org.gitlab4j.api.GitLabApiForm; |
| 8 | + |
| 9 | +/** |
| 10 | + * This class is used to filter Projects when getting lists of projects for a specified group. |
| 11 | + */ |
| 12 | +public class GroupFilter { |
| 13 | + |
| 14 | + private List<Integer> skipGroups; |
| 15 | + private Boolean allAvailable; |
| 16 | + private String search; |
| 17 | + private GroupOrderBy orderBy; |
| 18 | + private SortOrder sort; |
| 19 | + private Boolean statistics; |
| 20 | + private Boolean withCustomAttributes; |
| 21 | + private Boolean owned; |
| 22 | + private AccessLevel accessLevel; |
| 23 | + |
| 24 | + /** |
| 25 | + * Do not include the provided groups IDs. |
| 26 | + * |
| 27 | + * @param skipGroups List of group IDs to not include in the search |
| 28 | + * @return the reference to this GroupFilter instance |
| 29 | + */ |
| 30 | + public GroupFilter withSkipGroups(List<Integer> skipGroups) { |
| 31 | + this.skipGroups = skipGroups; |
| 32 | + return (this); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Show all the groups you have access to (defaults to false for authenticated users, true for admin). |
| 37 | + * Attributes owned and min_access_level have precedence |
| 38 | + * |
| 39 | + * @param allAvailable if true show all avauilable groups |
| 40 | + * @return the reference to this GroupFilter instance |
| 41 | + */ |
| 42 | + public GroupFilter withAllAvailabley(Boolean allAvailable) { |
| 43 | + this.allAvailable = allAvailable; |
| 44 | + return (this); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Return list of groups matching the search criteria. |
| 49 | + * |
| 50 | + * @param search the search criteria |
| 51 | + * @return the reference to this GroupFilter instance |
| 52 | + */ |
| 53 | + public GroupFilter withSearch(String search) { |
| 54 | + this.search = search; |
| 55 | + return (this); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Return groups ordered by id, name, path, created_at, updated_at, or last_activity_at fields. Default is created_at. |
| 60 | + * |
| 61 | + * @param orderBy specifies what field to order by |
| 62 | + * @return the reference to this GroupFilter instance |
| 63 | + */ |
| 64 | + public GroupFilter withOrderBy(GroupOrderBy orderBy) { |
| 65 | + this.orderBy = orderBy; |
| 66 | + return (this); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Return groups sorted in asc or desc order. Default is desc. |
| 71 | + * |
| 72 | + * @param sort sort direction, ASC or DESC |
| 73 | + * @return the reference to this GroupFilter instance |
| 74 | + */ |
| 75 | + public GroupFilter withSortOder(SortOrder sort) { |
| 76 | + this.sort = sort; |
| 77 | + return (this); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Include group statistics (admins only). |
| 82 | + * |
| 83 | + * @param statistics if true, return statistics with the results |
| 84 | + * @return the reference to this GroupFilter instance |
| 85 | + */ |
| 86 | + public GroupFilter withStatistics(Boolean statistics) { |
| 87 | + this.statistics = statistics; |
| 88 | + return (this); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Include custom attributes in response (admins only). |
| 93 | + * |
| 94 | + * @param withCustomAttributes if true, include custom attributes in the response |
| 95 | + * @return the reference to this GroupFilter instance |
| 96 | + */ |
| 97 | + public GroupFilter withCustomAttributes(Boolean withCustomAttributes) { |
| 98 | + this.withCustomAttributes = withCustomAttributes; |
| 99 | + return (this); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Limit by groups explicitly owned by the current user |
| 104 | + * |
| 105 | + * @param owned if true, limit to groups explicitly owned by the current user |
| 106 | + * @return the reference to this GroupFilter instance |
| 107 | + */ |
| 108 | + public GroupFilter withOwned(Boolean owned) { |
| 109 | + this.owned = owned; |
| 110 | + return (this); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Limit to groups where current user has at least this access level. |
| 115 | + * |
| 116 | + * @param accessLevel limit to groups where current user has at least this access level |
| 117 | + * @return the reference to this GroupFilter instance |
| 118 | + */ |
| 119 | + public GroupFilter withMinAccessLevel(AccessLevel accessLevel) { |
| 120 | + this.accessLevel = accessLevel; |
| 121 | + return (this); |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Get the query params specified by this filter. |
| 126 | + * |
| 127 | + * @return a GitLabApiForm instance holding the query parameters for this GroupFilter instance |
| 128 | + */ |
| 129 | + public GitLabApiForm getQueryParams() { |
| 130 | + return (new GitLabApiForm() |
| 131 | + .withParam("skip_groups", skipGroups) |
| 132 | + .withParam("all_available", allAvailable) |
| 133 | + .withParam("search", search) |
| 134 | + .withParam("order_by", orderBy) |
| 135 | + .withParam("sort", sort) |
| 136 | + .withParam("statistics", statistics) |
| 137 | + .withParam("with_custom_attributes", withCustomAttributes) |
| 138 | + .withParam("owned", owned) |
| 139 | + .withParam("min_access_level ", accessLevel) |
| 140 | + ); |
| 141 | + } |
| 142 | +} |
0 commit comments