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 qualifier;
052 private String scope;
053 private String language;
054 private Integer copy;
055 private List<Measure> measures;
056
057 public Resource() {
058 }
059
060 public Resource(Integer id, String key, String name, String scope, String qualifier, String language, Integer copy, List<Measure> measures) {
061 this.id = id;
062 this.key = key;
063 this.name = name;
064 this.qualifier = qualifier;
065 this.scope = scope;
066 this.language = language;
067 this.measures = measures;
068 this.copy = copy;
069 }
070
071 public Integer getId() {
072 return id;
073 }
074
075 public String getKey() {
076 return key;
077 }
078
079 public void setKey(String key) {
080 this.key = key;
081 }
082
083 public String getName() {
084 return name;
085 }
086
087 public void setName(String name) {
088 this.name = name;
089 }
090
091 public String getQualifier() {
092 return qualifier;
093 }
094
095 public void setQualifier(String qualifier) {
096 this.qualifier = qualifier;
097 }
098
099 public String getScope() {
100 return scope;
101 }
102
103 public void setScope(String scope) {
104 this.scope = scope;
105 }
106
107 public String getLanguage() {
108 return language;
109 }
110
111 public void setLanguage(String language) {
112 this.language = language;
113 }
114
115 public Integer getCopy() {
116 return copy;
117 }
118
119 public void setCopy(Integer copy) {
120 this.copy = copy;
121 }
122
123 public List<Measure> getMeasures() {
124 return measures;
125 }
126
127 public Measure getMeasure(WSMetrics.Metric metric) {
128 if (measures != null) {
129 for (Measure measure : measures) {
130 if (measure.getMetric().equals(metric.getKey())) {
131 return measure;
132 }
133 }
134 }
135 return null;
136 }
137
138 public boolean hasMeasure(WSMetrics.Metric metric) {
139 return getMeasure(metric) != null;
140 }
141
142 public String getMeasureFormattedValue(WSMetrics.Metric metric, String defaultValue) {
143 Measure measure = getMeasure(metric);
144 if (measure != null) {
145 return measure.getFormattedValue();
146 }
147 return defaultValue;
148 }
149
150 public void setMeasures(List<Measure> measures) {
151 this.measures = measures;
152 }
153
154 public boolean matchesKey(String resourceKey) {
155 return resourceKey != null && (getId().toString().equals(resourceKey) || getKey().equals(resourceKey));
156 }
157
158 @Override
159 public String toString() {
160 return "Resource{" +
161 "id='" + id + '\'' +
162 ", key='" + key + '\'' +
163 ", name='" + name + '\'' +
164 ", scope='" + scope + '\'' +
165 ", qualifier='" + qualifier + '\'' +
166 ", language='" + language + '\'' +
167 ", measures=" + measures +
168 '}';
169 }
170 }