aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
blob: ab6ec98a9cd81400a5fa6905fb20303059c09715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * Sonar, open source software quality management tool.
 * Copyright (C) 2008-2012 SonarSource
 * mailto:contact AT sonarsource DOT com
 *
 * Sonar is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * Sonar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sonar; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 */

package org.sonar.api.issue;

import com.google.common.base.Preconditions;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;

import java.util.Date;
import java.util.List;

/**
 * TODO add javadoc
 *
 * @since 3.6
 */
public class IssueQuery {

  private final List<String> keys;
  private final List<String> severities;
  private final List<String> statuses;
  private final List<String> resolutions;
  private final List<String> components;
  private final List<String> componentRoots;
  private final String ruleRepository;
  private final String rule;
  private final List<String> userLogins;
  private final List<String> assigneeLogins;
  private final Date createdAfter;
  private final Date createdBefore;
  private final int limit, offset;

  private IssueQuery(Builder builder) {
    this.keys = builder.keys;
    this.severities = builder.severities;
    this.statuses = builder.statuses;
    this.resolutions = builder.resolutions;
    this.components = builder.components;
    this.componentRoots = builder.componentRoots;
    this.ruleRepository = builder.ruleRepository;
    this.rule = builder.rule;
    this.userLogins = builder.userLogins;
    this.assigneeLogins = builder.assigneeLogins;
    this.createdAfter = builder.createdAfter;
    this.createdBefore = builder.createdBefore;
    this.limit = builder.limit;
    this.offset = builder.offset;
  }

  public List<String> keys() {
    return keys;
  }

  public List<String> severities() {
    return severities;
  }

  public List<String> statuses() {
    return statuses;
  }

  public List<String> resolutions() {
    return resolutions;
  }

  public List<String> components() {
    return components;
  }

  public List<String> componentRoots() {
    return componentRoots;
  }

  public String ruleRepository() {
    return ruleRepository;
  }

  public String rule() {
    return rule;
  }

  public List<String> userLogins() {
    return userLogins;
  }

  public List<String> assigneeLogins() {
    return assigneeLogins;
  }

  public Date createdAfter() {
    return createdAfter;
  }

  public Date createdBefore() {
    return createdBefore;
  }

  public int limit() {
    return limit;
  }

  public int offset() {
    return offset;
  }

  @Override
  public String toString() {
    return ReflectionToStringBuilder.toString(this);
  }

  public static Builder builder() {
    return new Builder();
  }


  /**
   * @since 3.6
   */
  public static class Builder {
    private static final int DEFAULT_LIMIT = 100;
    private static final int MAX_LIMIT = 5000;
    private static final int DEFAULT_OFFSET = 0;

    private List<String> keys;
    private List<String> severities;
    private List<String> statuses;
    private List<String> resolutions;
    private List<String> components;
    private List<String> componentRoots;
    private String ruleRepository;
    private String rule;
    private List<String> userLogins;
    private List<String> assigneeLogins;
    private Date createdAfter;
    private Date createdBefore;
    private int limit = DEFAULT_LIMIT;
    private int offset = DEFAULT_OFFSET;

    private Builder() {
    }

    public Builder keys(List<String> l) {
      this.keys = l;
      return this;
    }

    public Builder severities(List<String> l) {
      this.severities = l;
      return this;
    }

    public Builder statuses(List<String> l) {
      this.statuses = l;
      return this;
    }

    public Builder resolutions(List<String> l) {
      this.resolutions = l;
      return this;
    }

    public Builder components(List<String> l) {
      this.components = l;
      return this;
    }

    public Builder componentRoots(List<String> l) {
      this.componentRoots = l;
      return this;
    }

    public Builder ruleRepository(String ruleRepository) {
      this.ruleRepository = ruleRepository;
      return this;
    }

    public Builder rule(String rule) {
      this.rule = rule;
      return this;
    }

    public Builder userLogins(List<String> l) {
      this.userLogins = l;
      return this;
    }

    public Builder assigneeLogins(List<String> l) {
      this.assigneeLogins = l;
      return this;
    }

    public Builder createdAfter(Date createdAfter) {
      this.createdAfter = createdAfter;
      return this;
    }

    public Builder createdBefore(Date createdBefore) {
      this.createdBefore = createdBefore;
      return this;
    }

    public Builder limit(Integer i) {
      Preconditions.checkArgument(i == null || i.intValue() > 0, "Limit must be greater than 0 (got " + i + ")");
      Preconditions.checkArgument(i == null || i.intValue() < MAX_LIMIT, "Limit must be less than " + MAX_LIMIT + " (got " + i + ")");
      this.limit = (i == null ? DEFAULT_LIMIT : i.intValue());
      return this;
    }

    public Builder offset(Integer i) {
      Preconditions.checkArgument(i == null || i.intValue() >= 0, "Offset must be greater than or equal to 0 (got " + i + ")");
      this.offset = (i == null ? DEFAULT_OFFSET : i.intValue());
      return this;
    }

    public IssueQuery build() {
      return new IssueQuery(this);
    }
  }
}