aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ReviewQuery.java
blob: 1b4a3bb274112130a78813bcddbd14c3952d826f (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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * SonarQube, open source software quality management tool.
 * Copyright (C) 2008-2012 SonarSource
 * mailto:contact AT sonarsource DOT com
 *
 * SonarQube 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.
 *
 * SonarQube 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.wsclient.services;

/**
 * @since 2.8
 */
public class ReviewQuery extends Query<Review> {

  public static final String BASE_URL = "/api/reviews";

  public static final String OUTPUT_PLAIN = "PLAIN";
  public static final String OUTPUT_HTML = "HTML";

  /**
   * @deprecated since 2.9, but kept for backward compatibility
   */
  @Deprecated
  private String reviewType;
  private Long id;
  private Long[] ids;
  private String[] statuses;
  private String[] severities;
  private String[] projectKeysOrIds;
  private String[] resourceKeysOrIds;
  private String[] authorLogins;
  private String[] assigneeLogins;
  private String output;
  private String[] resolutions;

  public ReviewQuery() {
  }

  /**
   * @deprecated since 2.9
   * @return NULL
   */
  @Deprecated
  public String getReviewType() {
    return reviewType;
  }

  /**
   * @deprecated since 2.9
   * @param reviewType
   *          the reviewType to set
   */
  @Deprecated
  public ReviewQuery setReviewType(String reviewType) {
    this.reviewType = reviewType;
    return this;
  }

  /**
   * @return the id
   */
  public Long getId() {
    return id;
  }

  /**
   * @param id
   *          the id to set
   */
  public ReviewQuery setId(Long id) {
    this.id = id;
    return this;
  }

  /**
   * @return the ids
   */
  public Long[] getIds() {
    return ids;
  }

  /**
   * @param ids
   *          the ids to set
   */
  public ReviewQuery setIds(Long... ids) {
    this.ids = ids;
    return this;
  }

  /**
   * @return the statuses
   */
  public String[] getStatuses() {
    return statuses;
  }

  /**
   * @param statuses
   *          the statuses to set
   */
  public ReviewQuery setStatuses(String... statuses) {
    this.statuses = statuses;
    return this;
  }

  /**
   * @return the severities
   */
  public String[] getSeverities() {
    return severities;
  }

  /**
   * @param severities
   *          the severities to set
   */
  public ReviewQuery setSeverities(String... severities) {
    this.severities = severities;
    return this;
  }

  /**
   * @return the projectKeysOrIds
   */
  public String[] getProjectKeysOrIds() {
    return projectKeysOrIds;
  }

  /**
   * @param projectKeysOrIds
   *          the projectKeysOrIds to set
   */
  public ReviewQuery setProjectKeysOrIds(String... projectKeysOrIds) {
    this.projectKeysOrIds = projectKeysOrIds;
    return this;
  }

  /**
   * @return the resourceKeysOrIds
   */
  public String[] getResourceKeysOrIds() {
    return resourceKeysOrIds;
  }

  /**
   * @param resourceKeysOrIds
   *          the resourceKeysOrIds to set
   */
  public ReviewQuery setResourceKeysOrIds(String... resourceKeysOrIds) {
    this.resourceKeysOrIds = resourceKeysOrIds;
    return this;
  }

  /**
   * @deprecated since 3.0. Searching by user ID is not possible anymore. Use {@link #getAuthorLogins()} instead.
   */
  @Deprecated
  public String[] getAuthorLoginsOrIds() {
    return authorLogins;
  }

  /**
   * @deprecated since 3.0. Searching by user ID is not possible anymore. Use {@link #setAuthorLogins(String...)} instead.
   */
  @Deprecated
  public ReviewQuery setAuthorLoginsOrIds(String... authorLoginsOrIds) {
    setAuthorLogins(authorLoginsOrIds);
    return this;
  }

  /**
   * @return the authorLogins
   */
  public String[] getAuthorLogins() {
    return authorLogins;
  }

  /**
   * @param authorLogins
   *          the authorLogins to set
   */
  public ReviewQuery setAuthorLogins(String... authorLogins) {
    this.authorLogins = authorLogins;
    return this;
  }

  /**
   * @deprecated since 3.0. Searching by user ID is not possible anymore. Use {@link #getAssigneeLogins()} instead.
   */
  @Deprecated
  public String[] getAssigneeLoginsOrIds() {
    return assigneeLogins;
  }

  /**
   * @deprecated since 3.0. Searching by user ID is not possible anymore. Use {@link #setAssigneeLogins(String...)} instead.
   */
  @Deprecated
  public ReviewQuery setAssigneeLoginsOrIds(String... assigneeLoginsOrIds) {
    setAssigneeLogins(assigneeLoginsOrIds);
    return this;
  }

  /**
   * @return the assigneeLogins
   */
  public String[] getAssigneeLogins() {
    return assigneeLogins;
  }

  /**
   * @param assigneeLogins
   *          the assigneeLogins to set
   */
  public ReviewQuery setAssigneeLogins(String... assigneeLogins) {
    this.assigneeLogins = assigneeLogins;
    return this;
  }

  /**
   * @return the output
   */
  public String getOutput() {
    return output;
  }

  /**
   * 
   * @param output
   *          the output
   */
  public ReviewQuery setOutput(String output) {
    this.output = output;
    return this;
  }

  /**
   * @since 2.9
   */
  public String[] getResolutions() {
    return resolutions;
  }

  /**
   * @since 2.9
   */
  public ReviewQuery setResolutions(String... resolutions) {
    this.resolutions = resolutions;
    return this;
  }

  @Override
  public String getUrl() {
    StringBuilder url = new StringBuilder(BASE_URL);
    url.append('?');
    if (id != null) {
      appendUrlParameter(url, "ids", id);
    } else if (ids != null) {
      appendUrlParameter(url, "ids", ids);
    }
    appendUrlParameter(url, "statuses", statuses);
    appendUrlParameter(url, "severities", severities);
    appendUrlParameter(url, "projects", projectKeysOrIds);
    appendUrlParameter(url, "resources", resourceKeysOrIds);
    appendUrlParameter(url, "authors", authorLogins);
    appendUrlParameter(url, "assignees", assigneeLogins);
    appendUrlParameter(url, "output", output);
    appendUrlParameter(url, "resolutions", resolutions);
    if (resolutions == null && reviewType != null) {
      // Use of the 2.8 deprecated API: handle backward compatibility
      appendUrlParameter(url, "review_type", reviewType);
    }

    return url.toString();
  }

  @Override
  public Class<Review> getModelClass() {
    return Review.class;
  }

  public static ReviewQuery createForReview(Long id) {
    return new ReviewQuery().setId(id);
  }

  public static ReviewQuery createForResource(Resource resource) {
    return new ReviewQuery().setResourceKeysOrIds(resource.getId().toString());
  }

}