Commit 235a3755 authored by Michaël van de Giessen's avatar Michaël van de Giessen
Browse files

#755 added Package filter

based on docs https://docs.gitlab.com/ee/api/packages.html and inspired by GroupProjectsFilter
parent 20e122b2
......@@ -131,6 +131,52 @@ public interface Constants {
}
}
/** Enum to use for ordering the results of getPackages(). */
public enum PackageOrderBy {
NAME, CREATED_AT, VERSION, TYPE, PROJECT_PATH;
private static JacksonJsonEnumHelper<PackageOrderBy> enumHelper = new JacksonJsonEnumHelper<>(PackageOrderBy.class);
@JsonCreator
public static PackageOrderBy forValue(String value) {
return enumHelper.forValue(value);
}
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (enumHelper.toString(this));
}
}
/** Enum to use for filtering the results of getPackages(). */
public enum PackageStatus {
DEFAULT, HIDDEN, PROCESSING;
private static JacksonJsonEnumHelper<PackageStatus> enumHelper = new JacksonJsonEnumHelper<>(PackageStatus.class);
@JsonCreator
public static PackageStatus forValue(String value) {
return enumHelper.forValue(value);
}
@JsonValue
public String toValue() {
return (enumHelper.toString(this));
}
@Override
public String toString() {
return (enumHelper.toString(this));
}
}
/** Enum to use for ordering the results of getProjects(). */
public enum ProjectOrderBy {
......
package org.gitlab4j.api.models;
import org.gitlab4j.api.Constants.PackageStatus;
import org.gitlab4j.api.Constants.PackageOrderBy;
import org.gitlab4j.api.Constants.SortOrder;
import org.gitlab4j.api.GitLabApiForm;
/**
* This class is used to filter Projects when getting lists of projects for a specified group.
*/
public class PackageFilter {
private Boolean excludeSubgroups;
private PackageOrderBy orderBy;
private SortOrder sort;
private PackageType packageType;
private String packageName;
private Boolean includeVersionless;
private PackageStatus status;
/**
* Exclude Subgroups.
*
* @param excludeSubgroups if true, packages from projects from subgroups are not listed.
* @return the reference to this ProjectFilter instance
*/
public PackageFilter withExcludeSubgroups(Boolean excludeSubgroups) {
this.excludeSubgroups = excludeSubgroups;
return (this);
}
/**
* Return projects ordered by created_at, name, version, type, or project_path
*
* @param orderBy specifies what field to order by
* @return the reference to this ProjectFilter instance
*/
public PackageFilter withOrderBy(PackageOrderBy orderBy) {
this.orderBy = orderBy;
return (this);
}
/**
* Return projects sorted in asc or desc order. Default is desc.
*
* @param sort sort direction, ASC or DESC
* @return the reference to this ProjectFilter instance
*/
public PackageFilter withSortOder(SortOrder sort) {
this.sort = sort;
return (this);
}
/**
* Filter the returned packages by type.
*
* @param packageType One of conan, maven, npm, pypi, composer, nuget, helm, generic or golang
* @return the reference to this ProjectFilter instance
*/
public PackageFilter withPackageType(PackageType packageType) {
this.packageType = packageType;
return (this);
}
/**
* Filter the project packages with a fuzzy search by name
*
* @param packageName
* @return the reference to this ProjectFilter instance
*/
public PackageFilter withPackageName(String packageName) {
this.packageName = packageName;
return (this);
}
/**
* @param includeVersionless if true, versionless packages are included in the response
* @return the reference to this ProjectFilter instance
*/
public PackageFilter withIncludeVersionless(Boolean includeVersionless) {
this.includeVersionless = includeVersionless;
return (this);
}
/**
* Filter the returned packages by status.
*
* @param status One of default (default), hidden, or processing
* @return the reference to this ProjectFilter instance
*/
public PackageFilter withStatus(PackageStatus status) {
this.status = status;
return (this);
}
/**
* Get the query params specified by this filter.
*
* @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance
*/
public GitLabApiForm getQueryParams() {
return (new GitLabApiForm()
.withParam("order_by", orderBy)
.withParam("sort", sort)
.withParam("exclude_subgroups", excludeSubgroups)
.withParam("package_type", packageType)
.withParam("package_name", packageName)
.withParam("include_versionless", includeVersionless)
.withParam("status", status)
);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment