diff --git a/src/main/java/org/gitlab4j/api/models/IssueFilter.java b/src/main/java/org/gitlab4j/api/models/IssueFilter.java index 5d963352a..8ce89c14a 100644 --- a/src/main/java/org/gitlab4j/api/models/IssueFilter.java +++ b/src/main/java/org/gitlab4j/api/models/IssueFilter.java @@ -1,5 +1,9 @@ package org.gitlab4j.api.models; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import com.fasterxml.jackson.annotation.JsonIgnore; import org.gitlab4j.api.Constants; import org.gitlab4j.api.Constants.IssueOrderBy; @@ -8,6 +12,11 @@ import org.gitlab4j.api.Constants.SortOrder; import org.gitlab4j.api.GitLabApiForm; import org.gitlab4j.api.utils.ISO8601; +import org.gitlab4j.api.utils.JacksonJsonEnumHelper; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonValue; import java.io.Serializable; import java.util.Date; @@ -99,6 +108,32 @@ public class IssueFilter implements Serializable { */ private String iterationTitle; + /* + * Return issues without these parameters + */ + private Map not; + + public enum IssueField { + ASSIGNEE_ID, ASSIGNEE_USERNAME, AUTHOR_ID, AUTHOR_USERNAME, IIDS, ITERATION_ID, ITERATION_TITLE, LABELS, MILESTONE, MILESTONE_ID; + + private static JacksonJsonEnumHelper enumHelper = new JacksonJsonEnumHelper<>(IssueField.class); + + @JsonCreator + public static IssueField forValue(String value) { + return enumHelper.forValue(value); + } + + @JsonValue + public String toValue() { + return (enumHelper.toString(this)); + } + + @Override + public String toString() { + return (enumHelper.toString(this)); + } + } + /*- properties -*/ public List getIids() { @@ -229,6 +264,14 @@ public void setIterationTitle(String iterationTitle) { this.iterationTitle = iterationTitle; } + public Map getNot() { + return not; + } + + public void setNot(Map not) { + this.not = not; + } + /*- builder -*/ public IssueFilter withIids(List iids) { this.iids = iids; @@ -310,6 +353,132 @@ public IssueFilter withIterationTitle(String iterationTitle) { return (this); } + /** + * Add 'not' filter. + * + * @param not the 'not' filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withNot(Map not) { + this.not = not; + return (this); + } + + /** + * Add 'not' filter entry. + * + * @param field the field to be added to the 'not' value + * @param value the value for the entry + * @return the reference to this IssueField instance + */ + public IssueFilter withNot(IssueField field, Object value) { + if(not == null) { + not = new LinkedHashMap<>(); + } + not.put(field, value); + return (this); + } + + /** + * Add labels to the 'not' filter entry. + * + * @param labels the labels to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutLabels(String... labels) { + return withNot(IssueField.LABELS, String.join(",", labels)); + } + + /* + * Add iids to the 'not' filter entry. + * + * @param iids the iids to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutIids(String... iids) { + return withNot(IssueField.IIDS, String.join(",", iids)); + } + + /** + * Add author_id to the 'not' filter entry. + * + * @param authorId the id of the author to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutAuthorId(Long authorId) { + return withNot(IssueField.AUTHOR_ID, authorId); + } + + /** + * Add author_username to the 'not' filter entry. + * + * @param authorUsername the username of the author to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutAuthorUsername(String authorUsername) { + return withNot(IssueField.AUTHOR_USERNAME, authorUsername); + } + + /** + * Add assignee_id to the 'not' filter entry. + * + * @param assigneeId the id of the assignee to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutAssigneeId(Long assigneeId) { + return withNot(IssueField.ASSIGNEE_ID, assigneeId); + } + + /** + * Add assignee_username to the 'not' filter entry. + * + * @param assigneeUsername the username of the assignee to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutAssigneeUsername(String assigneeUsername) { + return withNot(IssueField.ASSIGNEE_USERNAME, assigneeUsername); + } + + /** + * Add iteration_id to the 'not' filter entry. + * + * @param iterationId the id of the iteration to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutIterationId(Long iterationId) { + return withNot(IssueField.ITERATION_ID, iterationId); + } + + /** + * Add iteration_title to the 'not' filter entry. + * + * @param iterationTitle the title of the iteration to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutIterationTitle(String iterationTitle) { + return withNot(IssueField.ITERATION_TITLE, iterationTitle); + } + + /** + * Add milestone_id to the 'not' filter entry. + * + * @param milestoneId the id of the milestone to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutMilestoneId(Long milestoneId) { + return withNot(IssueField.MILESTONE_ID, milestoneId); + } + + /** + * Add milestone to the 'not' filter entry. + * + * @param milestone the title of the milestone to add to the filter + * @return the reference to this IssueFilter instance + */ + public IssueFilter withoutMilestone(String milestone) { + return withNot(IssueField.MILESTONE, milestone); + } + /*- params generator -*/ @JsonIgnore public GitLabApiForm getQueryParams(int page, int perPage) { @@ -336,6 +505,18 @@ public GitLabApiForm getQueryParams() { .withParam("created_before", ISO8601.toString(createdBefore, false)) .withParam("updated_after", ISO8601.toString(updatedAfter, false)) .withParam("updated_before", ISO8601.toString(updatedBefore, false))) - .withParam("iteration_title", iterationTitle); + .withParam("iteration_title", iterationTitle) + .withParam("not", toStringMap(not), false); + } + + private Map toStringMap(Map map) { + if(map == null) { + return null; + } + Map result = new LinkedHashMap<>(); + for (Map.Entry entry : map.entrySet()) { + result.put(entry.getKey().toString(), entry.getValue()); + } + return result; } } diff --git a/src/main/java/org/gitlab4j/api/models/MergeRequestFilter.java b/src/main/java/org/gitlab4j/api/models/MergeRequestFilter.java index cfb91051f..38c6b8b85 100644 --- a/src/main/java/org/gitlab4j/api/models/MergeRequestFilter.java +++ b/src/main/java/org/gitlab4j/api/models/MergeRequestFilter.java @@ -5,7 +5,9 @@ import java.io.Serializable; import java.util.Date; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.gitlab4j.api.Constants; import org.gitlab4j.api.Constants.MergeRequestOrderBy; @@ -15,8 +17,11 @@ import org.gitlab4j.api.Constants.SortOrder; import org.gitlab4j.api.utils.JacksonJson; import org.gitlab4j.api.GitLabApiForm; +import org.gitlab4j.api.utils.JacksonJsonEnumHelper; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonValue; /** * This class is used to filter merge requests when getting lists of them. @@ -50,6 +55,28 @@ public class MergeRequestFilter implements Serializable { private String search; private MergeRequestSearchIn in; private Boolean wip; + private Map not; + + public enum MergeRequestField { + LABELS, MILESTONE, AUTHOR_ID, AUTHOR_USERNAME, ASSIGNEE_ID, ASSIGNEE_USERNAME, REVIEWER_ID, REVIEWER_USERNAME, MY_REACTION_EMOJI; + + private static JacksonJsonEnumHelper enumHelper = new JacksonJsonEnumHelper<>(MergeRequestField.class); + + @JsonCreator + public static MergeRequestField forValue(String value) { + return enumHelper.forValue(value); + } + + @JsonValue + public String toValue() { + return (enumHelper.toString(this)); + } + + @Override + public String toString() { + return (enumHelper.toString(this)); + } + } public Long getProjectId() { return projectId; @@ -337,6 +364,123 @@ public MergeRequestFilter withWip(Boolean wip) { return (this); } + /** + * Add 'not' filter. + * + * @param not the 'not' filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withNot(Map not) { + this.not = not; + return (this); + } + + /** + * Add 'not' filter entry. + * + * @param field the field to be added to the 'not' value + * @param value the value for the entry + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withNot(MergeRequestField field, Object value) { + if(not == null) { + not = new LinkedHashMap<>(); + } + not.put(field, value); + return (this); + } + + /** + * Add author_id to the 'not' filter entry. + * + * @param authorId the id of the author to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutAuthorId(Long authorId) { + return withNot(MergeRequestField.AUTHOR_ID, authorId); + } + + /** + * Add author_username to the 'not' filter entry. + * + * @param authorUsername the username of the author to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutAuthorUsername(String authorUsername) { + return withNot(MergeRequestField.AUTHOR_USERNAME, authorUsername); + } + + /** + * Add assignee_id to the 'not' filter entry. + * + * @param assigneeId the id of the assignee to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutAssigneeId(Long assigneeId) { + return withNot(MergeRequestField.ASSIGNEE_ID, assigneeId); + } + + /** + * Add assignee_username to the 'not' filter entry. + * + * @param assigneeUsername the username of the assignee to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutAssigneeUsername(String assigneeUsername) { + return withNot(MergeRequestField.ASSIGNEE_USERNAME, assigneeUsername); + } + + /** + * Add reviewer_id to the 'not' filter entry. + * + * @param reviewerId the id of the reviewer to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutReviewerId(Long reviewerId) { + return withNot(MergeRequestField.REVIEWER_ID, reviewerId); + } + + /** + * Add reviewer_username to the 'not' filter entry. + * + * @param reviewerUsername the username of the reviewer to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutReviewerUsername(String reviewerUsername) { + return withNot(MergeRequestField.REVIEWER_USERNAME, reviewerUsername); + } + + + /** + * Add my_reaction_emoji to the 'not' filter entry. + * + * @param myReactionEmoji the name of the reactionEmoji to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutMyReactionEmoji(String myReactionEmoji) { + return withNot(MergeRequestField.MY_REACTION_EMOJI, myReactionEmoji); + } + + /** + * Add milestone to the 'not' filter entry. + * + * @param milestone the name of the milestone to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutMilestone(String milestone) { + return withNot(MergeRequestField.MILESTONE, milestone); + } + + /** + * Add labels to the 'not' filter entry. + * + * @param labels the labels to add to the filter + * @return the reference to this MergeRequestFilter instance + */ + public MergeRequestFilter withoutLabels(String... labels) { + return withNot(MergeRequestField.LABELS, String.join(",", labels)); + } + @JsonIgnore public GitLabApiForm getQueryParams(int page, int perPage) { return (getQueryParams() @@ -365,14 +509,26 @@ public GitLabApiForm getQueryParams() { .withParam("target_branch", targetBranch) .withParam("search", search) .withParam("in", in) - .withParam("wip", (wip == null ? null : wip ? "yes" : "no")); + .withParam("wip", (wip == null ? null : wip ? "yes" : "no")) + .withParam("not", toStringMap(not), false); if (authorId != null && (scope == ALL || scope == ASSIGNED_TO_ME)) { params.withParam("author_id", authorId); } return params; } - + + private Map toStringMap(Map map) { + if(map == null) { + return null; + } + Map result = new LinkedHashMap<>(); + for (Map.Entry entry : map.entrySet()) { + result.put(entry.getKey().toString(), entry.getValue()); + } + return result; + } + @Override public String toString() { return (JacksonJson.toJsonString(this));