|
| 1 | +package org.gitlab4j.api.models; |
| 2 | + |
| 3 | +import org.gitlab4j.api.Constants.PackageStatus; |
| 4 | +import org.gitlab4j.api.Constants.PackageOrderBy; |
| 5 | +import org.gitlab4j.api.Constants.SortOrder; |
| 6 | +import org.gitlab4j.api.GitLabApiForm; |
| 7 | + |
| 8 | +/** |
| 9 | + * This class is used to filter Projects when getting lists of projects for a specified group. |
| 10 | + */ |
| 11 | +public class PackageFilter { |
| 12 | + |
| 13 | + private Boolean excludeSubgroups; |
| 14 | + private PackageOrderBy orderBy; |
| 15 | + private SortOrder sort; |
| 16 | + private PackageType packageType; |
| 17 | + private String packageName; |
| 18 | + private Boolean includeVersionless; |
| 19 | + private PackageStatus status; |
| 20 | + |
| 21 | + /** |
| 22 | + * Exclude Subgroups. |
| 23 | + * |
| 24 | + * @param excludeSubgroups if true, packages from projects from subgroups are not listed. |
| 25 | + * @return the reference to this ProjectFilter instance |
| 26 | + */ |
| 27 | + public PackageFilter withExcludeSubgroups(Boolean excludeSubgroups) { |
| 28 | + this.excludeSubgroups = excludeSubgroups; |
| 29 | + return (this); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Return projects ordered by created_at, name, version, type, or project_path |
| 34 | + * |
| 35 | + * @param orderBy specifies what field to order by |
| 36 | + * @return the reference to this ProjectFilter instance |
| 37 | + */ |
| 38 | + public PackageFilter withOrderBy(PackageOrderBy orderBy) { |
| 39 | + this.orderBy = orderBy; |
| 40 | + return (this); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Return projects sorted in asc or desc order. Default is desc. |
| 45 | + * |
| 46 | + * @param sort sort direction, ASC or DESC |
| 47 | + * @return the reference to this ProjectFilter instance |
| 48 | + */ |
| 49 | + public PackageFilter withSortOder(SortOrder sort) { |
| 50 | + this.sort = sort; |
| 51 | + return (this); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Filter the returned packages by type. |
| 56 | + * |
| 57 | + * @param packageType One of conan, maven, npm, pypi, composer, nuget, helm, generic or golang |
| 58 | + * @return the reference to this ProjectFilter instance |
| 59 | + */ |
| 60 | + public PackageFilter withPackageType(PackageType packageType) { |
| 61 | + this.packageType = packageType; |
| 62 | + return (this); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Filter the project packages with a fuzzy search by name |
| 67 | + * |
| 68 | + * @param packageName |
| 69 | + * @return the reference to this ProjectFilter instance |
| 70 | + */ |
| 71 | + public PackageFilter withPackageName(String packageName) { |
| 72 | + this.packageName = packageName; |
| 73 | + return (this); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @param includeVersionless if true, versionless packages are included in the response |
| 78 | + * @return the reference to this ProjectFilter instance |
| 79 | + */ |
| 80 | + public PackageFilter withIncludeVersionless(Boolean includeVersionless) { |
| 81 | + this.includeVersionless = includeVersionless; |
| 82 | + return (this); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Filter the returned packages by status. |
| 87 | + * |
| 88 | + * @param status One of default (default), hidden, or processing |
| 89 | + * @return the reference to this ProjectFilter instance |
| 90 | + */ |
| 91 | + public PackageFilter withStatus(PackageStatus status) { |
| 92 | + this.status = status; |
| 93 | + return (this); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Get the query params specified by this filter. |
| 98 | + * |
| 99 | + * @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance |
| 100 | + */ |
| 101 | + public GitLabApiForm getQueryParams() { |
| 102 | + return (new GitLabApiForm() |
| 103 | + .withParam("order_by", orderBy) |
| 104 | + .withParam("sort", sort) |
| 105 | + .withParam("exclude_subgroups", excludeSubgroups) |
| 106 | + .withParam("package_type", packageType) |
| 107 | + .withParam("package_name", packageName) |
| 108 | + .withParam("include_versionless", includeVersionless) |
| 109 | + .withParam("status", status) |
| 110 | + ); |
| 111 | + } |
| 112 | +} |
0 commit comments