1
1
package org .gitlab4j .api .models ;
2
2
3
- import com .fasterxml .jackson .annotation .JsonIgnore ;
4
3
import java .util .Date ;
4
+ import java .util .LinkedHashMap ;
5
5
import java .util .List ;
6
+ import java .util .Map ;
7
+
6
8
import org .gitlab4j .api .Constants ;
7
9
import org .gitlab4j .api .Constants .IssueOrderBy ;
8
10
import org .gitlab4j .api .Constants .IssueScope ;
9
11
import org .gitlab4j .api .Constants .IssueState ;
10
12
import org .gitlab4j .api .Constants .SortOrder ;
11
13
import org .gitlab4j .api .GitLabApiForm ;
12
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 ;
13
20
14
21
/**
15
22
* This class is used to filter issues when getting lists of them.
@@ -96,6 +103,32 @@ public class IssueFilter {
96
103
*/
97
104
private String iterationTitle ;
98
105
106
+ /*
107
+ * Return issues without these parameters
108
+ */
109
+ private Map <IssueField , Object > not ;
110
+
111
+ public enum IssueField {
112
+ ASSIGNEE_ID , ASSIGNEE_USERNAME , AUTHOR_ID , AUTHOR_USERNAME , IIDS , ITERATION_ID , ITERATION_TITLE , LABELS , MILESTONE , MILESTONE_ID ;
113
+
114
+ private static JacksonJsonEnumHelper <IssueField > enumHelper = new JacksonJsonEnumHelper <>(IssueField .class );
115
+
116
+ @ JsonCreator
117
+ public static IssueField forValue (String value ) {
118
+ return enumHelper .forValue (value );
119
+ }
120
+
121
+ @ JsonValue
122
+ public String toValue () {
123
+ return (enumHelper .toString (this ));
124
+ }
125
+
126
+ @ Override
127
+ public String toString () {
128
+ return (enumHelper .toString (this ));
129
+ }
130
+ }
131
+
99
132
100
133
/*- properties -*/
101
134
public List <String > getIids () {
@@ -226,6 +259,14 @@ public void setIterationTitle(String iterationTitle) {
226
259
this .iterationTitle = iterationTitle ;
227
260
}
228
261
262
+ public Map <IssueField , Object > getNot () {
263
+ return not ;
264
+ }
265
+
266
+ public void setNot (Map <IssueField , Object > not ) {
267
+ this .not = not ;
268
+ }
269
+
229
270
/*- builder -*/
230
271
public IssueFilter withIids (List <String > iids ) {
231
272
this .iids = iids ;
@@ -307,6 +348,132 @@ public IssueFilter withIterationTitle(String iterationTitle) {
307
348
return (this );
308
349
}
309
350
351
+ /**
352
+ * Add 'not' filter.
353
+ *
354
+ * @param not the 'not' filter
355
+ * @return the reference to this IssueFilter instance
356
+ */
357
+ public IssueFilter withNot (Map <IssueField , Object > not ) {
358
+ this .not = not ;
359
+ return (this );
360
+ }
361
+
362
+ /**
363
+ * Add 'not' filter entry.
364
+ *
365
+ * @param field the field to be added to the 'not' value
366
+ * @param value the value for the entry
367
+ * @return the reference to this IssueField instance
368
+ */
369
+ public IssueFilter withNot (IssueField field , Object value ) {
370
+ if (not == null ) {
371
+ not = new LinkedHashMap <>();
372
+ }
373
+ not .put (field , value );
374
+ return (this );
375
+ }
376
+
377
+ /**
378
+ * Add labels to the 'not' filter entry.
379
+ *
380
+ * @param labels the labels to add to the filter
381
+ * @return the reference to this IssueFilter instance
382
+ */
383
+ public IssueFilter withoutLabels (String ... labels ) {
384
+ return withNot (IssueField .LABELS , String .join ("," , labels ));
385
+ }
386
+
387
+ /*
388
+ * Add iids to the 'not' filter entry.
389
+ *
390
+ * @param iids the iids to add to the filter
391
+ * @return the reference to this IssueFilter instance
392
+ */
393
+ public IssueFilter withoutIids (String ... iids ) {
394
+ return withNot (IssueField .IIDS , String .join ("," , iids ));
395
+ }
396
+
397
+ /**
398
+ * Add author_id to the 'not' filter entry.
399
+ *
400
+ * @param authorId the id of the author to add to the filter
401
+ * @return the reference to this IssueFilter instance
402
+ */
403
+ public IssueFilter withoutAuthorId (Long authorId ) {
404
+ return withNot (IssueField .AUTHOR_ID , authorId );
405
+ }
406
+
407
+ /**
408
+ * Add author_username to the 'not' filter entry.
409
+ *
410
+ * @param authorUsername the username of the author to add to the filter
411
+ * @return the reference to this IssueFilter instance
412
+ */
413
+ public IssueFilter withoutAuthorUsername (String authorUsername ) {
414
+ return withNot (IssueField .AUTHOR_USERNAME , authorUsername );
415
+ }
416
+
417
+ /**
418
+ * Add assignee_id to the 'not' filter entry.
419
+ *
420
+ * @param assigneeId the id of the assignee to add to the filter
421
+ * @return the reference to this IssueFilter instance
422
+ */
423
+ public IssueFilter withoutAssigneeId (Long assigneeId ) {
424
+ return withNot (IssueField .ASSIGNEE_ID , assigneeId );
425
+ }
426
+
427
+ /**
428
+ * Add assignee_username to the 'not' filter entry.
429
+ *
430
+ * @param assigneeUsername the username of the assignee to add to the filter
431
+ * @return the reference to this IssueFilter instance
432
+ */
433
+ public IssueFilter withoutAssigneeUsername (String assigneeUsername ) {
434
+ return withNot (IssueField .ASSIGNEE_USERNAME , assigneeUsername );
435
+ }
436
+
437
+ /**
438
+ * Add iteration_id to the 'not' filter entry.
439
+ *
440
+ * @param iterationId the id of the iteration to add to the filter
441
+ * @return the reference to this IssueFilter instance
442
+ */
443
+ public IssueFilter withoutIterationId (Long iterationId ) {
444
+ return withNot (IssueField .ITERATION_ID , iterationId );
445
+ }
446
+
447
+ /**
448
+ * Add iteration_title to the 'not' filter entry.
449
+ *
450
+ * @param iterationTitle the title of the iteration to add to the filter
451
+ * @return the reference to this IssueFilter instance
452
+ */
453
+ public IssueFilter withoutIterationTitle (String iterationTitle ) {
454
+ return withNot (IssueField .ITERATION_TITLE , iterationTitle );
455
+ }
456
+
457
+ /**
458
+ * Add milestone_id to the 'not' filter entry.
459
+ *
460
+ * @param milestoneId the id of the milestone to add to the filter
461
+ * @return the reference to this IssueFilter instance
462
+ */
463
+ public IssueFilter withoutMilestoneId (Long iterationId ) {
464
+ return withNot (IssueField .MILESTONE_ID , iterationId );
465
+ }
466
+
467
+ /**
468
+ * Add milestone to the 'not' filter entry.
469
+ *
470
+ * @param milestone the title of the milestone to add to the filter
471
+ * @return the reference to this IssueFilter instance
472
+ */
473
+ public IssueFilter withoutMilestone (String iterationTitle ) {
474
+ return withNot (IssueField .MILESTONE , iterationTitle );
475
+ }
476
+
310
477
/*- params generator -*/
311
478
@ JsonIgnore
312
479
public GitLabApiForm getQueryParams (int page , int perPage ) {
@@ -333,6 +500,18 @@ public GitLabApiForm getQueryParams() {
333
500
.withParam ("created_before" , ISO8601 .toString (createdBefore , false ))
334
501
.withParam ("updated_after" , ISO8601 .toString (updatedAfter , false ))
335
502
.withParam ("updated_before" , ISO8601 .toString (updatedBefore , false )))
336
- .withParam ("iteration_title" , iterationTitle );
503
+ .withParam ("iteration_title" , iterationTitle )
504
+ .withParam ("not" , toStringMap (not ), false );
505
+ }
506
+
507
+ private Map <String , Object > toStringMap (Map <IssueField , Object > map ) {
508
+ if (map == null ) {
509
+ return null ;
510
+ }
511
+ Map <String , Object > result = new LinkedHashMap <>();
512
+ for (Map .Entry <IssueField , Object > entry : map .entrySet ()) {
513
+ result .put (entry .getKey ().toString (), entry .getValue ());
514
+ }
515
+ return result ;
337
516
}
338
517
}
0 commit comments