001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
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.List;
024
025 public class Resource extends Model {
026
027 /* SCOPES */
028 public static final String SCOPE_SET = "PRJ";
029 public static final String SCOPE_SPACE = "DIR";
030 public static final String SCOPE_ENTITY = "FIL";
031 public static final String SCOPE_LIB = "LIB";
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 List<Measure> measures;
059
060 public Integer getId() {
061 return id;
062 }
063
064 public Resource setId(Integer id) {
065 this.id = id;
066 return this;
067 }
068
069 public String getKey() {
070 return key;
071 }
072
073 public Resource setKey(String key) {
074 this.key = key;
075 return this;
076 }
077
078 public String getDescription() {
079 return description;
080 }
081
082 public Resource setDescription(String description) {
083 this.description = description;
084 return this;
085 }
086
087 public String getName() {
088 return name;
089 }
090
091 public String getName(boolean longFormatIfDefined) {
092 if (longFormatIfDefined && longName != null && !"".equals(longName)) {
093 return longName;
094 }
095 return name;
096 }
097
098 public String getLongName() {
099 return longName;
100 }
101
102 public Resource setLongName(String longName) {
103 this.longName = longName;
104 return this;
105 }
106
107 public Resource setName(String s) {
108 this.name = s;
109 return this;
110 }
111
112 public String getScope() {
113 return scope;
114 }
115
116 public Resource setScope(String scope) {
117 this.scope = scope;
118 return this;
119 }
120
121 public String getQualifier() {
122 return qualifier;
123 }
124
125 public Resource setQualifier(String qualifier) {
126 this.qualifier = qualifier;
127 return this;
128 }
129
130 public String getLanguage() {
131 return language;
132 }
133
134 public Resource setLanguage(String language) {
135 this.language = language;
136 return this;
137 }
138
139 public String getVersion() {
140 return version;
141 }
142
143 public Resource setVersion(String version) {
144 this.version = version;
145 return this;
146 }
147
148 public Integer getCopy() {
149 return copy;
150 }
151
152 public Resource setCopy(Integer copy) {
153 this.copy = copy;
154 return this;
155 }
156
157 public List<Measure> getMeasures() {
158 if (measures == null) {
159 return Collections.emptyList();
160 }
161 return measures;
162 }
163
164 public Measure getMeasure(String metricKey) {
165 for (Measure measure : getMeasures()) {
166 if (metricKey.equals(measure.getMetricKey())) {
167 return measure;
168 }
169 }
170 return null;
171 }
172
173 public Double getMeasureValue(String metricKey) {
174 Measure measure = getMeasure(metricKey);
175 if (measure != null) {
176 return measure.getValue();
177 }
178 return null;
179 }
180
181 public Integer getMeasureIntValue(String metricKey) {
182 Double d = getMeasureValue(metricKey);
183 if (d != null) {
184 return d.intValue();
185 }
186 return null;
187 }
188
189 public String getMeasureFormattedValue(String metricKey, String defaultValue) {
190 Measure measure = getMeasure(metricKey);
191 if (measure != null) {
192 return measure.getFormattedValue(defaultValue);
193 }
194 return defaultValue;
195 }
196
197 public void setMeasures(List<Measure> measures) {
198 this.measures = measures;
199 }
200
201 @Override
202 public String toString() {
203 return new StringBuilder()
204 .append("[id=")
205 .append(id)
206 .append(",key=")
207 .append(key)
208 .append("]")
209 .toString();
210 }
211 }