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 private String reviewType;
033 private Long id;
034 private Long[] ids;
035 private String[] statuses;
036 private String[] severities;
037 private String[] projectKeysOrIds;
038 private String[] resourceKeysOrIds;
039 private String[] authorLoginsOrIds;
040 private String[] assigneeLoginsOrIds;
041 private String output;
042
043 public ReviewQuery() {
044 }
045
046 /**
047 * @return the reviewType
048 */
049 public String getReviewType() {
050 return reviewType;
051 }
052
053 /**
054 * @param reviewType
055 * the reviewType to set
056 */
057 public ReviewQuery setReviewType(String reviewType) {
058 this.reviewType = reviewType;
059 return this;
060 }
061
062 /**
063 * @return the id
064 */
065 public Long getId() {
066 return id;
067 }
068
069 /**
070 * @param id
071 * the id to set
072 */
073 public ReviewQuery setId(Long id) {
074 this.id = id;
075 return this;
076 }
077
078 /**
079 * @return the ids
080 */
081 public Long[] getIds() {
082 return ids;
083 }
084
085 /**
086 * @param ids
087 * the ids to set
088 */
089 public ReviewQuery setIds(Long... ids) {
090 this.ids = ids;
091 return this;
092 }
093
094 /**
095 * @return the statuses
096 */
097 public String[] getStatuses() {
098 return statuses;
099 }
100
101 /**
102 * @param statuses
103 * the statuses to set
104 */
105 public ReviewQuery setStatuses(String... statuses) {
106 this.statuses = statuses;
107 return this;
108 }
109
110 /**
111 * @return the severities
112 */
113 public String[] getSeverities() {
114 return severities;
115 }
116
117 /**
118 * @param severities
119 * the severities to set
120 */
121 public ReviewQuery setSeverities(String... severities) {
122 this.severities = severities;
123 return this;
124 }
125
126
127 /**
128 * @return the projectKeysOrIds
129 */
130 public String[] getProjectKeysOrIds() {
131 return projectKeysOrIds;
132 }
133
134
135 /**
136 * @param projectKeysOrIds the projectKeysOrIds to set
137 */
138 public ReviewQuery setProjectKeysOrIds(String... projectKeysOrIds) {
139 this.projectKeysOrIds = projectKeysOrIds;
140 return this;
141 }
142
143
144 /**
145 * @return the resourceKeysOrIds
146 */
147 public String[] getResourceKeysOrIds() {
148 return resourceKeysOrIds;
149 }
150
151
152 /**
153 * @param resourceKeysOrIds the resourceKeysOrIds to set
154 */
155 public ReviewQuery setResourceKeysOrIds(String... resourceKeysOrIds) {
156 this.resourceKeysOrIds = resourceKeysOrIds;
157 return this;
158 }
159
160
161 /**
162 * @return the authorLoginsOrIds
163 */
164 public String[] getAuthorLoginsOrIds() {
165 return authorLoginsOrIds;
166 }
167
168
169 /**
170 * @param authorLoginsOrIds the authorLoginsOrIds to set
171 */
172 public ReviewQuery setAuthorLoginsOrIds(String... authorLoginsOrIds) {
173 this.authorLoginsOrIds = authorLoginsOrIds;
174 return this;
175 }
176
177
178 /**
179 * @return the assigneeLoginsOrIds
180 */
181 public String[] getAssigneeLoginsOrIds() {
182 return assigneeLoginsOrIds;
183 }
184
185
186 /**
187 * @param assigneeLoginsOrIds the assigneeLoginsOrIds to set
188 */
189 public ReviewQuery setAssigneeLoginsOrIds(String... assigneeLoginsOrIds) {
190 this.assigneeLoginsOrIds = assigneeLoginsOrIds;
191 return this;
192 }
193
194 /**
195 * @return the output
196 */
197 public String getOutput() {
198 return output;
199 }
200
201 public ReviewQuery setOutput(String output) {
202 this.output = output;
203 return this;
204 }
205
206 @Override
207 public String getUrl() {
208 StringBuilder url = new StringBuilder(BASE_URL);
209 url.append('?');
210 if (id != null) {
211 appendUrlParameter(url, "id", id);
212 } else if (ids != null) {
213 appendUrlParameter(url, "ids", ids);
214 }
215 appendUrlParameter(url, "review_type", reviewType);
216 appendUrlParameter(url, "statuses", statuses);
217 appendUrlParameter(url, "severities", severities);
218 appendUrlParameter(url, "projects", projectKeysOrIds);
219 appendUrlParameter(url, "resources", resourceKeysOrIds);
220 appendUrlParameter(url, "authors", authorLoginsOrIds);
221 appendUrlParameter(url, "assignees", assigneeLoginsOrIds);
222 appendUrlParameter(url, "output", output);
223
224 return url.toString();
225 }
226
227 @Override
228 public Class<Review> getModelClass() {
229 return Review.class;
230 }
231
232 public static ReviewQuery createForResource(Resource resource) {
233 return new ReviewQuery().setResourceKeysOrIds(resource.getId().toString());
234 }
235
236 }