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.api.web.gwt.client.webservices;
021
022 import java.util.List;
023
024 public class Resource extends ResponsePOJO {
025 public static final String SCOPE_SET = "PRJ";
026 public static final String SCOPE_SPACE = "DIR";
027 public static final String SCOPE_ENTITY = "FIL";
028
029 @Deprecated
030 public static final String SCOPE_PROJECT = SCOPE_SET;
031 @Deprecated
032 public static final String SCOPE_DIRECTORY = SCOPE_SPACE;
033 @Deprecated
034 public static final String SCOPE_FILE = SCOPE_ENTITY;
035
036 public static final String QUALIFIER_PROJECT = "TRK";
037 public static final String QUALIFIER_MODULE = "BRC";
038 @Deprecated
039 public static final String QUALIFIER_PROJECT_TRUNK = QUALIFIER_PROJECT;
040 @Deprecated
041 public static final String QUALIFIER_PROJECT_BRANCH = QUALIFIER_MODULE;
042 public static final String QUALIFIER_PACKAGE = "PAC";
043 public static final String QUALIFIER_DIRECTORY = "DIR";
044 public static final String QUALIFIER_FILE = "FIL";
045 public static final String QUALIFIER_CLASS = "CLA";
046 public static final String QUALIFIER_UNIT_TEST = "UTS";
047
048 private Integer id;
049 private String key;
050 private String name;
051 private String longName;
052 private String qualifier;
053 private String scope;
054 private String language;
055 private Integer copy;
056 private List<Measure> measures;
057
058 public Resource() {
059 }
060
061 public Resource(Integer id, String key, String name, String scope, String qualifier, String language, Integer copy, List<Measure> measures) {
062 this.id = id;
063 this.key = key;
064 this.name = name;
065 this.qualifier = qualifier;
066 this.scope = scope;
067 this.language = language;
068 this.measures = measures;
069 this.copy = copy;
070 }
071
072 public Integer getId() {
073 return id;
074 }
075
076 public String getKey() {
077 return key;
078 }
079
080 public void setKey(String key) {
081 this.key = key;
082 }
083
084 public String getName() {
085 return name;
086 }
087
088 public String getName(boolean longFormatIfDefined) {
089 if (longFormatIfDefined && longName != null && !"".equals(longName)) {
090 return longName;
091 }
092 return name;
093 }
094
095 public void setName(String name) {
096 this.name = name;
097 }
098
099 public String getLongName() {
100 return longName;
101 }
102
103 public void setLongName(String longName) {
104 this.longName = longName;
105 }
106
107 public String getQualifier() {
108 return qualifier;
109 }
110
111 public void setQualifier(String qualifier) {
112 this.qualifier = qualifier;
113 }
114
115 public String getScope() {
116 return scope;
117 }
118
119 public void setScope(String scope) {
120 this.scope = scope;
121 }
122
123 public String getLanguage() {
124 return language;
125 }
126
127 public void setLanguage(String language) {
128 this.language = language;
129 }
130
131 public Integer getCopy() {
132 return copy;
133 }
134
135 public void setCopy(Integer copy) {
136 this.copy = copy;
137 }
138
139 public List<Measure> getMeasures() {
140 return measures;
141 }
142
143 public Measure getMeasure(WSMetrics.Metric metric) {
144 if (measures != null) {
145 for (Measure measure : measures) {
146 if (measure.getMetric().equals(metric.getKey())) {
147 return measure;
148 }
149 }
150 }
151 return null;
152 }
153
154 public boolean hasMeasure(WSMetrics.Metric metric) {
155 return getMeasure(metric) != null;
156 }
157
158 public String getMeasureFormattedValue(WSMetrics.Metric metric, String defaultValue) {
159 Measure measure = getMeasure(metric);
160 if (measure != null) {
161 return measure.getFormattedValue();
162 }
163 return defaultValue;
164 }
165
166 public void setMeasures(List<Measure> measures) {
167 this.measures = measures;
168 }
169
170 public boolean matchesKey(String resourceKey) {
171 return resourceKey != null && (getId().toString().equals(resourceKey) || getKey().equals(resourceKey));
172 }
173
174 @Override
175 public String toString() {
176 return "Resource{" +
177 "id='" + id + '\'' +
178 ", key='" + key + '\'' +
179 ", name='" + name + '\'' +
180 ", longName='" + longName + '\'' +
181 ", scope='" + scope + '\'' +
182 ", qualifier='" + qualifier + '\'' +
183 ", language='" + language + '\'' +
184 ", measures=" + measures +
185 '}';
186 }
187 }