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