1
1
package org .gitlab4j .api .models ;
2
2
3
+ import java .util .Date ;
4
+ import java .util .LinkedHashMap ;
5
+ import java .util .List ;
6
+ import java .util .Map ;
3
7
import com .fasterxml .jackson .annotation .JsonIgnore ;
4
8
import org .gitlab4j .api .Constants ;
5
9
import org .gitlab4j .api .Constants .IssueOrderBy ;
8
12
import org .gitlab4j .api .Constants .SortOrder ;
9
13
import org .gitlab4j .api .GitLabApiForm ;
10
14
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 ;
11
20
12
21
import java .io .Serializable ;
13
22
import java .util .Date ;
@@ -99,6 +108,32 @@ public class IssueFilter implements Serializable {
99
108
*/
100
109
private String iterationTitle ;
101
110
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
+
102
137
103
138
/*- properties -*/
104
139
public List <String > getIids () {
@@ -229,6 +264,14 @@ public void setIterationTitle(String iterationTitle) {
229
264
this .iterationTitle = iterationTitle ;
230
265
}
231
266
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
+
232
275
/*- builder -*/
233
276
public IssueFilter withIids (List <String > iids ) {
234
277
this .iids = iids ;
@@ -310,6 +353,132 @@ public IssueFilter withIterationTitle(String iterationTitle) {
310
353
return (this );
311
354
}
312
355
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
+
313
482
/*- params generator -*/
314
483
@ JsonIgnore
315
484
public GitLabApiForm getQueryParams (int page , int perPage ) {
@@ -336,6 +505,18 @@ public GitLabApiForm getQueryParams() {
336
505
.withParam ("created_before" , ISO8601 .toString (createdBefore , false ))
337
506
.withParam ("updated_after" , ISO8601 .toString (updatedAfter , false ))
338
507
.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 ;
340
521
}
341
522
}
0 commit comments