001/* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2012 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 */ 020package org.sonar.wsclient.services; 021 022/** 023 * @since 2.8 024 */ 025public 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[] authorLogins; 044 private String[] assigneeLogins; 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 * @deprecated since 3.0. Searching by user ID is not possible anymore. Use {@link #getAuthorLogins()} instead. 169 */ 170 @Deprecated 171 public String[] getAuthorLoginsOrIds() { 172 return authorLogins; 173 } 174 175 /** 176 * @deprecated since 3.0. Searching by user ID is not possible anymore. Use {@link #setAuthorLogins(String...)} instead. 177 */ 178 @Deprecated 179 public ReviewQuery setAuthorLoginsOrIds(String... authorLoginsOrIds) { 180 setAuthorLogins(authorLoginsOrIds); 181 return this; 182 } 183 184 /** 185 * @return the authorLogins 186 */ 187 public String[] getAuthorLogins() { 188 return authorLogins; 189 } 190 191 /** 192 * @param authorLogins 193 * the authorLogins to set 194 */ 195 public ReviewQuery setAuthorLogins(String... authorLogins) { 196 this.authorLogins = authorLogins; 197 return this; 198 } 199 200 /** 201 * @deprecated since 3.0. Searching by user ID is not possible anymore. Use {@link #getAssigneeLogins()} instead. 202 */ 203 @Deprecated 204 public String[] getAssigneeLoginsOrIds() { 205 return assigneeLogins; 206 } 207 208 /** 209 * @deprecated since 3.0. Searching by user ID is not possible anymore. Use {@link #setAssigneeLogins(String...)} instead. 210 */ 211 @Deprecated 212 public ReviewQuery setAssigneeLoginsOrIds(String... assigneeLoginsOrIds) { 213 setAssigneeLogins(assigneeLoginsOrIds); 214 return this; 215 } 216 217 /** 218 * @return the assigneeLogins 219 */ 220 public String[] getAssigneeLogins() { 221 return assigneeLogins; 222 } 223 224 /** 225 * @param assigneeLogins 226 * the assigneeLogins to set 227 */ 228 public ReviewQuery setAssigneeLogins(String... assigneeLogins) { 229 this.assigneeLogins = assigneeLogins; 230 return this; 231 } 232 233 /** 234 * @return the output 235 */ 236 public String getOutput() { 237 return output; 238 } 239 240 /** 241 * 242 * @param output 243 * the output 244 */ 245 public ReviewQuery setOutput(String output) { 246 this.output = output; 247 return this; 248 } 249 250 /** 251 * @since 2.9 252 */ 253 public String[] getResolutions() { 254 return resolutions; 255 } 256 257 /** 258 * @since 2.9 259 */ 260 public ReviewQuery setResolutions(String... resolutions) { 261 this.resolutions = resolutions; 262 return this; 263 } 264 265 @Override 266 public String getUrl() { 267 StringBuilder url = new StringBuilder(BASE_URL); 268 url.append('?'); 269 if (id != null) { 270 appendUrlParameter(url, "ids", id); 271 } else if (ids != null) { 272 appendUrlParameter(url, "ids", ids); 273 } 274 appendUrlParameter(url, "statuses", statuses); 275 appendUrlParameter(url, "severities", severities); 276 appendUrlParameter(url, "projects", projectKeysOrIds); 277 appendUrlParameter(url, "resources", resourceKeysOrIds); 278 appendUrlParameter(url, "authors", authorLogins); 279 appendUrlParameter(url, "assignees", assigneeLogins); 280 appendUrlParameter(url, "output", output); 281 appendUrlParameter(url, "resolutions", resolutions); 282 if (resolutions == null && reviewType != null) { 283 // Use of the 2.8 deprecated API: handle backward compatibility 284 appendUrlParameter(url, "review_type", reviewType); 285 } 286 287 return url.toString(); 288 } 289 290 @Override 291 public Class<Review> getModelClass() { 292 return Review.class; 293 } 294 295 public static ReviewQuery createForReview(Long id) { 296 return new ReviewQuery().setId(id); 297 } 298 299 public static ReviewQuery createForResource(Resource resource) { 300 return new ReviewQuery().setResourceKeysOrIds(resource.getId().toString()); 301 } 302 303}