Skip to content

Commit

Permalink
Implement the not attribute for the Issue and MergeRequest Filter (#1070
Browse files Browse the repository at this point in the history
)
  • Loading branch information
KoCoder committed Feb 5, 2024
1 parent 2e90153 commit 7b07abd
Show file tree
Hide file tree
Showing 2 changed files with 340 additions and 3 deletions.
183 changes: 182 additions & 1 deletion src/main/java/org/gitlab4j/api/models/IssueFilter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -99,6 +108,32 @@ public class IssueFilter implements Serializable {
*/
private String iterationTitle;

/*
* Return issues without these parameters
*/
private Map<IssueField, Object> not;

public enum IssueField {
ASSIGNEE_ID, ASSIGNEE_USERNAME, AUTHOR_ID, AUTHOR_USERNAME, IIDS, ITERATION_ID, ITERATION_TITLE, LABELS, MILESTONE, MILESTONE_ID;

private static JacksonJsonEnumHelper<IssueField> 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<String> getIids() {
Expand Down Expand Up @@ -229,6 +264,14 @@ public void setIterationTitle(String iterationTitle) {
this.iterationTitle = iterationTitle;
}

public Map<IssueField, Object> getNot() {
return not;
}

public void setNot(Map<IssueField, Object> not) {
this.not = not;
}

/*- builder -*/
public IssueFilter withIids(List<String> iids) {
this.iids = iids;
Expand Down Expand Up @@ -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<IssueField, Object> 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) {
Expand All @@ -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<String, Object> toStringMap(Map<IssueField, Object> map) {
if(map == null) {
return null;
}
Map<String, Object> result = new LinkedHashMap<>();
for (Map.Entry<IssueField, Object> entry : map.entrySet()) {
result.put(entry.getKey().toString(), entry.getValue());
}
return result;
}
}
Loading

0 comments on commit 7b07abd

Please sign in to comment.