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