001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2011 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.wsclient.services;
021
022 /**
023 * @since 2.8
024 */
025 public class ReviewQuery extends Query<Review> {
026
027 public static final String BASE_URL = "/api/reviews";
028
029 public static final String OUTPUT_PLAIN = "PLAIN";
030 public static final String OUTPUT_HTML = "HTML";
031
032 /**
033 * @deprecated since 2.9, but kept for backward compatibility
034 */
035 @Deprecated
036 private String reviewType;
037 private Long id;
038 private Long[] ids;
039 private String[] statuses;
040 private String[] severities;
041 private String[] projectKeysOrIds;
042 private String[] resourceKeysOrIds;
043 private String[] authorLoginsOrIds;
044 private String[] assigneeLoginsOrIds;
045 private String output;
046 private String[] resolutions;
047
048 public ReviewQuery() {
049 }
050
051 /**
052 * @deprecated since 2.9
053 * @return NULL
054 */
055 @Deprecated
056 public String getReviewType() {
057 return reviewType;
058 }
059
060 /**
061 * @deprecated since 2.9
062 * @param reviewType
063 * the reviewType to set
064 */
065 @Deprecated
066 public ReviewQuery setReviewType(String reviewType) {
067 this.reviewType = reviewType;
068 return this;
069 }
070
071 /**
072 * @return the id
073 */
074 public Long getId() {
075 return id;
076 }
077
078 /**
079 * @param id
080 * the id to set
081 */
082 public ReviewQuery setId(Long id) {
083 this.id = id;
084 return this;
085 }
086
087 /**
088 * @return the ids
089 */
090 public Long[] getIds() {
091 return ids;
092 }
093
094 /**
095 * @param ids
096 * the ids to set
097 */
098 public ReviewQuery setIds(Long... ids) {
099 this.ids = ids;
100 return this;
101 }
102
103 /**
104 * @return the statuses
105 */
106 public String[] getStatuses() {
107 return statuses;
108 }
109
110 /**
111 * @param statuses
112 * the statuses to set
113 */
114 public ReviewQuery setStatuses(String... statuses) {
115 this.statuses = statuses;
116 return this;
117 }
118
119 /**
120 * @return the severities
121 */
122 public String[] getSeverities() {
123 return severities;
124 }
125
126 /**
127 * @param severities
128 * the severities to set
129 */
130 public ReviewQuery setSeverities(String... severities) {
131 this.severities = severities;
132 return this;
133 }
134
135 /**
136 * @return the projectKeysOrIds
137 */
138 public String[] getProjectKeysOrIds() {
139 return projectKeysOrIds;
140 }
141
142 /**
143 * @param projectKeysOrIds
144 * the projectKeysOrIds to set
145 */
146 public ReviewQuery setProjectKeysOrIds(String... projectKeysOrIds) {
147 this.projectKeysOrIds = projectKeysOrIds;
148 return this;
149 }
150
151 /**
152 * @return the resourceKeysOrIds
153 */
154 public String[] getResourceKeysOrIds() {
155 return resourceKeysOrIds;
156 }
157
158 /**
159 * @param resourceKeysOrIds
160 * the resourceKeysOrIds to set
161 */
162 public ReviewQuery setResourceKeysOrIds(String... resourceKeysOrIds) {
163 this.resourceKeysOrIds = resourceKeysOrIds;
164 return this;
165 }
166
167 /**
168 * @return the authorLoginsOrIds
169 */
170 public String[] getAuthorLoginsOrIds() {
171 return authorLoginsOrIds;
172 }
173
174 /**
175 * @param authorLoginsOrIds
176 * the authorLoginsOrIds to set
177 */
178 public ReviewQuery setAuthorLoginsOrIds(String... authorLoginsOrIds) {
179 this.authorLoginsOrIds = authorLoginsOrIds;
180 return this;
181 }
182
183 /**
184 * @return the assigneeLoginsOrIds
185 */
186 public String[] getAssigneeLoginsOrIds() {
187 return assigneeLoginsOrIds;
188 }
189
190 /**
191 * @param assigneeLoginsOrIds
192 * the assigneeLoginsOrIds to set
193 */
194 public ReviewQuery setAssigneeLoginsOrIds(String... assigneeLoginsOrIds) {
195 this.assigneeLoginsOrIds = assigneeLoginsOrIds;
196 return this;
197 }
198
199 /**
200 * @return the output
201 */
202 public String getOutput() {
203 return output;
204 }
205
206 /**
207 *
208 * @param output
209 * the output
210 */
211 public ReviewQuery setOutput(String output) {
212 this.output = output;
213 return this;
214 }
215
216 /**
217 * @since 2.9
218 */
219 public String[] getResolutions() {
220 return resolutions;
221 }
222
223 /**
224 * @since 2.9
225 */
226 public ReviewQuery setResolutions(String... resolutions) {
227 this.resolutions = resolutions;
228 return this;
229 }
230
231 @Override
232 public String getUrl() {
233 StringBuilder url = new StringBuilder(BASE_URL);
234 url.append('?');
235 if (id != null) {
236 appendUrlParameter(url, "id", id);
237 } else if (ids != null) {
238 appendUrlParameter(url, "ids", ids);
239 }
240 appendUrlParameter(url, "statuses", statuses);
241 appendUrlParameter(url, "severities", severities);
242 appendUrlParameter(url, "projects", projectKeysOrIds);
243 appendUrlParameter(url, "resources", resourceKeysOrIds);
244 appendUrlParameter(url, "authors", authorLoginsOrIds);
245 appendUrlParameter(url, "assignees", assigneeLoginsOrIds);
246 appendUrlParameter(url, "output", output);
247 appendUrlParameter(url, "resolutions", resolutions);
248 if (resolutions == null && reviewType != null) {
249 // Use of the 2.8 deprecated API: handle backward compatibility
250 appendUrlParameter(url, "review_type", reviewType);
251 }
252
253 return url.toString();
254 }
255
256 @Override
257 public Class<Review> getModelClass() {
258 return Review.class;
259 }
260
261 public static ReviewQuery createForReview(Long id) {
262 return new ReviewQuery().setId(id);
263 }
264
265 public static ReviewQuery createForResource(Resource resource) {
266 return new ReviewQuery().setResourceKeysOrIds(resource.getId().toString());
267 }
268
269 }