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 */
020 package org.sonar.wsclient.services;
021
022 import java.util.Collections;
023 import java.util.Date;
024 import java.util.List;
025
026 public class Resource extends Model {
027
028 /* SCOPES */
029 public static final String SCOPE_SET = "PRJ";
030 public static final String SCOPE_SPACE = "DIR";
031 public static final String SCOPE_ENTITY = "FIL";
032
033 /* QUALIFIERS */
034 public static final String QUALIFIER_VIEW = "VW";
035 public static final String QUALIFIER_SUBVIEW = "SVW";
036 public static final String QUALIFIER_LIB = "LIB";
037 public static final String QUALIFIER_PROJECT = "TRK";
038 public static final String QUALIFIER_MODULE = "BRC";
039 public static final String QUALIFIER_PACKAGE = "PAC";
040 public static final String QUALIFIER_DIRECTORY = "DIR";
041 public static final String QUALIFIER_FILE = "FIL";
042 public static final String QUALIFIER_CLASS = "CLA";
043 public static final String QUALIFIER_UNIT_TEST_CLASS = "UTS";
044
045 /* LANGUAGES */
046 public static final String LANGUAGE_JAVA = "java";
047
048 private Integer id;
049 private String key;
050 private String name;
051 private String longName;
052 private String scope;
053 private String qualifier;
054 private String language;
055 private String version;
056 private Integer copy;
057 private String description;
058 private Date date;
059 private List<Measure> measures;
060
061 // periods used for variations and tracking of violations
062 private String period1Mode, period2Mode, period3Mode, period4Mode, period5Mode;
063 private String period1Param, period2Param, period3Param, period4Param, period5Param;
064 private Date period1Date, period2Date, period3Date, period4Date, period5Date;
065
066 public Integer getId() {
067 return id;
068 }
069
070 public Resource setId(Integer id) {
071 this.id = id;
072 return this;
073 }
074
075 public String getKey() {
076 return key;
077 }
078
079 public Resource setKey(String key) {
080 this.key = key;
081 return this;
082 }
083
084 public String getDescription() {
085 return description;
086 }
087
088 public Resource setDescription(String description) {
089 this.description = description;
090 return this;
091 }
092
093 public String getName() {
094 return name;
095 }
096
097 public String getName(boolean longFormatIfDefined) {
098 if (longFormatIfDefined && longName != null && !"".equals(longName)) {
099 return longName;
100 }
101 return name;
102 }
103
104 public String getLongName() {
105 return longName;
106 }
107
108 public Resource setLongName(String longName) {
109 this.longName = longName;
110 return this;
111 }
112
113 public Resource setName(String s) {
114 this.name = s;
115 return this;
116 }
117
118 public String getScope() {
119 return scope;
120 }
121
122 public Resource setScope(String scope) {
123 this.scope = scope;
124 return this;
125 }
126
127 public String getQualifier() {
128 return qualifier;
129 }
130
131 public Resource setQualifier(String qualifier) {
132 this.qualifier = qualifier;
133 return this;
134 }
135
136 public String getLanguage() {
137 return language;
138 }
139
140 public Resource setLanguage(String language) {
141 this.language = language;
142 return this;
143 }
144
145 public String getVersion() {
146 return version;
147 }
148
149 public Resource setVersion(String version) {
150 this.version = version;
151 return this;
152 }
153
154 public Integer getCopy() {
155 return copy;
156 }
157
158 public Resource setCopy(Integer copy) {
159 this.copy = copy;
160 return this;
161 }
162
163 public Date getDate() {
164 return date;
165 }
166
167 public Resource setDate(Date d) {
168 this.date = d;
169 return this;
170 }
171
172 public List<Measure> getMeasures() {
173 if (measures == null) {
174 return Collections.emptyList();
175 }
176 return measures;
177 }
178
179 public Measure getMeasure(String metricKey) {
180 for (Measure measure : getMeasures()) {
181 if (metricKey.equals(measure.getMetricKey())) {
182 return measure;
183 }
184 }
185 return null;
186 }
187
188 public Double getMeasureValue(String metricKey) {
189 Measure measure = getMeasure(metricKey);
190 if (measure != null) {
191 return measure.getValue();
192 }
193 return null;
194 }
195
196 public Integer getMeasureIntValue(String metricKey) {
197 Double d = getMeasureValue(metricKey);
198 if (d != null) {
199 return d.intValue();
200 }
201 return null;
202 }
203
204 public String getMeasureFormattedValue(String metricKey, String defaultValue) {
205 Measure measure = getMeasure(metricKey);
206 if (measure != null) {
207 return measure.getFormattedValue(defaultValue);
208 }
209 return defaultValue;
210 }
211
212 public void setMeasures(List<Measure> measures) {
213 this.measures = measures;
214 }
215
216 /**
217 * @since 2.5 only on projects, else null
218 */
219 public String getPeriod1Mode() {
220 return period1Mode;
221 }
222
223 /**
224 * @since 2.5
225 */
226 public Resource setPeriod1Mode(String period1Mode) {
227 this.period1Mode = period1Mode;
228 return this;
229 }
230
231 /**
232 * @since 2.5 only on projects, else null
233 */
234 public String getPeriod2Mode() {
235 return period2Mode;
236 }
237
238 /**
239 * @since 2.5
240 */
241 public Resource setPeriod2Mode(String period2Mode) {
242 this.period2Mode = period2Mode;
243 return this;
244 }
245
246 /**
247 * @since 2.5 only on projects, else null
248 */
249 public String getPeriod3Mode() {
250 return period3Mode;
251 }
252
253 /**
254 * @since 2.5
255 */
256 public Resource setPeriod3Mode(String period3Mode) {
257 this.period3Mode = period3Mode;
258 return this;
259 }
260
261 /**
262 * @since 2.5 only on projects, else null
263 */
264 public String getPeriod4Mode() {
265 return period4Mode;
266 }
267
268 /**
269 * @since 2.5
270 */
271 public Resource setPeriod4Mode(String period4Mode) {
272 this.period4Mode = period4Mode;
273 return this;
274 }
275
276 /**
277 * @since 2.5 only on projects, else null
278 */
279 public String getPeriod5Mode() {
280 return period5Mode;
281 }
282
283 /**
284 * @since 2.5
285 */
286 public Resource setPeriod5Mode(String period5Mode) {
287 this.period5Mode = period5Mode;
288 return this;
289 }
290
291 /**
292 * @since 2.5 only on projects, else null
293 */
294 public String getPeriod1Param() {
295 return period1Param;
296 }
297
298 /**
299 * @since 2.5
300 */
301 public Resource setPeriod1Param(String period1Param) {
302 this.period1Param = period1Param;
303 return this;
304 }
305
306 /**
307 * @since 2.5 only on projects, else null
308 */
309 public String getPeriod2Param() {
310 return period2Param;
311 }
312
313 /**
314 * @since 2.5
315 */
316 public Resource setPeriod2Param(String period2Param) {
317 this.period2Param = period2Param;
318 return this;
319 }
320
321 /**
322 * @since 2.5 only on projects, else null
323 */
324 public String getPeriod3Param() {
325 return period3Param;
326 }
327
328 /**
329 * @since 2.5
330 */
331 public Resource setPeriod3Param(String period3Param) {
332 this.period3Param = period3Param;
333 return this;
334 }
335
336 /**
337 * @since 2.5 only on projects, else null
338 */
339 public String getPeriod4Param() {
340 return period4Param;
341 }
342
343 /**
344 * @since 2.5
345 */
346 public Resource setPeriod4Param(String period4Param) {
347 this.period4Param = period4Param;
348 return this;
349 }
350
351 /**
352 * @since 2.5 only on projects, else null
353 */
354 public String getPeriod5Param() {
355 return period5Param;
356 }
357
358 /**
359 * @since 2.5
360 */
361 public Resource setPeriod5Param(String period5Param) {
362 this.period5Param = period5Param;
363 return this;
364 }
365
366 /**
367 * @since 2.5 only on projects, else null
368 */
369 public Date getPeriod1Date() {
370 return period1Date;
371 }
372
373 /**
374 * @since 2.5
375 */
376 public Resource setPeriod1Date(Date period1Date) {
377 this.period1Date = period1Date;
378 return this;
379 }
380
381 /**
382 * @since 2.5 only on projects, else null
383 */
384 public Date getPeriod2Date() {
385 return period2Date;
386 }
387
388 /**
389 * @since 2.5
390 */
391 public Resource setPeriod2Date(Date period2Date) {
392 this.period2Date = period2Date;
393 return this;
394 }
395
396 /**
397 * @since 2.5 only on projects, else null
398 */
399 public Date getPeriod3Date() {
400 return period3Date;
401 }
402
403 /**
404 * @since 2.5
405 */
406 public Resource setPeriod3Date(Date period3Date) {
407 this.period3Date = period3Date;
408 return this;
409 }
410
411 /**
412 * @since 2.5 only on projects, else null
413 */
414 public Date getPeriod4Date() {
415 return period4Date;
416 }
417
418 /**
419 * @since 2.5
420 */
421 public Resource setPeriod4Date(Date period4Date) {
422 this.period4Date = period4Date;
423 return this;
424 }
425
426 /**
427 * @since 2.5 only on projects, else null
428 */
429 public Date getPeriod5Date() {
430 return period5Date;
431 }
432
433 /**
434 * @since 2.5
435 */
436 public Resource setPeriod5Date(Date period5Date) {
437 this.period5Date = period5Date;
438 return this;
439 }
440
441 @Override
442 public String toString() {
443 return new StringBuilder()
444 .append("[id=")
445 .append(id)
446 .append(",key=")
447 .append(key)
448 .append("]")
449 .toString();
450 }
451 }