Skip to content

Commit b0603d1

Browse files
committed
Merge remote-tracking branch 'origin/main' into 6.x
2 parents 7d0e324 + 7b07abd commit b0603d1

File tree

2 files changed

+340
-3
lines changed

2 files changed

+340
-3
lines changed

src/main/java/org/gitlab4j/api/models/IssueFilter.java

+182-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.gitlab4j.api.models;
22

3+
import java.util.Date;
4+
import java.util.LinkedHashMap;
5+
import java.util.List;
6+
import java.util.Map;
37
import com.fasterxml.jackson.annotation.JsonIgnore;
48
import org.gitlab4j.api.Constants;
59
import org.gitlab4j.api.Constants.IssueOrderBy;
@@ -8,6 +12,11 @@
812
import org.gitlab4j.api.Constants.SortOrder;
913
import org.gitlab4j.api.GitLabApiForm;
1014
import org.gitlab4j.api.utils.ISO8601;
15+
import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
16+
17+
import com.fasterxml.jackson.annotation.JsonCreator;
18+
import com.fasterxml.jackson.annotation.JsonIgnore;
19+
import com.fasterxml.jackson.annotation.JsonValue;
1120

1221
import java.io.Serializable;
1322
import java.util.Date;
@@ -99,6 +108,32 @@ public class IssueFilter implements Serializable {
99108
*/
100109
private String iterationTitle;
101110

111+
/*
112+
* Return issues without these parameters
113+
*/
114+
private Map<IssueField, Object> not;
115+
116+
public enum IssueField {
117+
ASSIGNEE_ID, ASSIGNEE_USERNAME, AUTHOR_ID, AUTHOR_USERNAME, IIDS, ITERATION_ID, ITERATION_TITLE, LABELS, MILESTONE, MILESTONE_ID;
118+
119+
private static JacksonJsonEnumHelper<IssueField> enumHelper = new JacksonJsonEnumHelper<>(IssueField.class);
120+
121+
@JsonCreator
122+
public static IssueField forValue(String value) {
123+
return enumHelper.forValue(value);
124+
}
125+
126+
@JsonValue
127+
public String toValue() {
128+
return (enumHelper.toString(this));
129+
}
130+
131+
@Override
132+
public String toString() {
133+
return (enumHelper.toString(this));
134+
}
135+
}
136+
102137

103138
/*- properties -*/
104139
public List<String> getIids() {
@@ -229,6 +264,14 @@ public void setIterationTitle(String iterationTitle) {
229264
this.iterationTitle = iterationTitle;
230265
}
231266

267+
public Map<IssueField, Object> getNot() {
268+
return not;
269+
}
270+
271+
public void setNot(Map<IssueField, Object> not) {
272+
this.not = not;
273+
}
274+
232275
/*- builder -*/
233276
public IssueFilter withIids(List<String> iids) {
234277
this.iids = iids;
@@ -310,6 +353,132 @@ public IssueFilter withIterationTitle(String iterationTitle) {
310353
return (this);
311354
}
312355

356+
/**
357+
* Add 'not' filter.
358+
*
359+
* @param not the 'not' filter
360+
* @return the reference to this IssueFilter instance
361+
*/
362+
public IssueFilter withNot(Map<IssueField, Object> not) {
363+
this.not = not;
364+
return (this);
365+
}
366+
367+
/**
368+
* Add 'not' filter entry.
369+
*
370+
* @param field the field to be added to the 'not' value
371+
* @param value the value for the entry
372+
* @return the reference to this IssueField instance
373+
*/
374+
public IssueFilter withNot(IssueField field, Object value) {
375+
if(not == null) {
376+
not = new LinkedHashMap<>();
377+
}
378+
not.put(field, value);
379+
return (this);
380+
}
381+
382+
/**
383+
* Add labels to the 'not' filter entry.
384+
*
385+
* @param labels the labels to add to the filter
386+
* @return the reference to this IssueFilter instance
387+
*/
388+
public IssueFilter withoutLabels(String... labels) {
389+
return withNot(IssueField.LABELS, String.join(",", labels));
390+
}
391+
392+
/*
393+
* Add iids to the 'not' filter entry.
394+
*
395+
* @param iids the iids to add to the filter
396+
* @return the reference to this IssueFilter instance
397+
*/
398+
public IssueFilter withoutIids(String... iids) {
399+
return withNot(IssueField.IIDS, String.join(",", iids));
400+
}
401+
402+
/**
403+
* Add author_id to the 'not' filter entry.
404+
*
405+
* @param authorId the id of the author to add to the filter
406+
* @return the reference to this IssueFilter instance
407+
*/
408+
public IssueFilter withoutAuthorId(Long authorId) {
409+
return withNot(IssueField.AUTHOR_ID, authorId);
410+
}
411+
412+
/**
413+
* Add author_username to the 'not' filter entry.
414+
*
415+
* @param authorUsername the username of the author to add to the filter
416+
* @return the reference to this IssueFilter instance
417+
*/
418+
public IssueFilter withoutAuthorUsername(String authorUsername) {
419+
return withNot(IssueField.AUTHOR_USERNAME, authorUsername);
420+
}
421+
422+
/**
423+
* Add assignee_id to the 'not' filter entry.
424+
*
425+
* @param assigneeId the id of the assignee to add to the filter
426+
* @return the reference to this IssueFilter instance
427+
*/
428+
public IssueFilter withoutAssigneeId(Long assigneeId) {
429+
return withNot(IssueField.ASSIGNEE_ID, assigneeId);
430+
}
431+
432+
/**
433+
* Add assignee_username to the 'not' filter entry.
434+
*
435+
* @param assigneeUsername the username of the assignee to add to the filter
436+
* @return the reference to this IssueFilter instance
437+
*/
438+
public IssueFilter withoutAssigneeUsername(String assigneeUsername) {
439+
return withNot(IssueField.ASSIGNEE_USERNAME, assigneeUsername);
440+
}
441+
442+
/**
443+
* Add iteration_id to the 'not' filter entry.
444+
*
445+
* @param iterationId the id of the iteration to add to the filter
446+
* @return the reference to this IssueFilter instance
447+
*/
448+
public IssueFilter withoutIterationId(Long iterationId) {
449+
return withNot(IssueField.ITERATION_ID, iterationId);
450+
}
451+
452+
/**
453+
* Add iteration_title to the 'not' filter entry.
454+
*
455+
* @param iterationTitle the title of the iteration to add to the filter
456+
* @return the reference to this IssueFilter instance
457+
*/
458+
public IssueFilter withoutIterationTitle(String iterationTitle) {
459+
return withNot(IssueField.ITERATION_TITLE, iterationTitle);
460+
}
461+
462+
/**
463+
* Add milestone_id to the 'not' filter entry.
464+
*
465+
* @param milestoneId the id of the milestone to add to the filter
466+
* @return the reference to this IssueFilter instance
467+
*/
468+
public IssueFilter withoutMilestoneId(Long milestoneId) {
469+
return withNot(IssueField.MILESTONE_ID, milestoneId);
470+
}
471+
472+
/**
473+
* Add milestone to the 'not' filter entry.
474+
*
475+
* @param milestone the title of the milestone to add to the filter
476+
* @return the reference to this IssueFilter instance
477+
*/
478+
public IssueFilter withoutMilestone(String milestone) {
479+
return withNot(IssueField.MILESTONE, milestone);
480+
}
481+
313482
/*- params generator -*/
314483
@JsonIgnore
315484
public GitLabApiForm getQueryParams(int page, int perPage) {
@@ -336,6 +505,18 @@ public GitLabApiForm getQueryParams() {
336505
.withParam("created_before", ISO8601.toString(createdBefore, false))
337506
.withParam("updated_after", ISO8601.toString(updatedAfter, false))
338507
.withParam("updated_before", ISO8601.toString(updatedBefore, false)))
339-
.withParam("iteration_title", iterationTitle);
508+
.withParam("iteration_title", iterationTitle)
509+
.withParam("not", toStringMap(not), false);
510+
}
511+
512+
private Map<String, Object> toStringMap(Map<IssueField, Object> map) {
513+
if(map == null) {
514+
return null;
515+
}
516+
Map<String, Object> result = new LinkedHashMap<>();
517+
for (Map.Entry<IssueField, Object> entry : map.entrySet()) {
518+
result.put(entry.getKey().toString(), entry.getValue());
519+
}
520+
return result;
340521
}
341522
}

0 commit comments

Comments
 (0)