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.database.model;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.apache.commons.lang.builder.EqualsBuilder;
024 import org.apache.commons.lang.builder.HashCodeBuilder;
025 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
026 import org.sonar.api.database.BaseIdentifiable;
027 import org.sonar.api.rules.RulePriority;
028
029 import javax.persistence.*;
030 import java.util.Date;
031
032 @Entity
033 @Table(name = "rule_failures")
034 public class RuleFailureModel extends BaseIdentifiable {
035
036 public static final int MESSAGE_COLUMN_SIZE = 4000;
037
038 @Column(name = "snapshot_id")
039 protected Integer snapshotId;
040
041 @Column(name = "rule_id", updatable = false, nullable = false)
042 private Integer ruleId;
043
044 @Column(name = "failure_level", updatable = true, nullable = false)
045 @Enumerated(EnumType.ORDINAL)
046 private RulePriority priority;
047
048 @Column(name = "message", updatable = false, nullable = true, length = MESSAGE_COLUMN_SIZE)
049 private String message;
050
051 @Column(name = "line", updatable = true, nullable = true)
052 private Integer line;
053
054 @Column(name = "cost", updatable = true, nullable = true)
055 private Double cost;
056
057 @Temporal(TemporalType.TIMESTAMP)
058 @Column(name = "created_at", updatable = true, nullable = true)
059 private Date createdAt;
060
061 @Column(name = "checksum", updatable = true, nullable = true, length = 1000)
062 private String checksum;
063
064 @Column(name = "permanent_id", updatable = true, nullable = true)
065 private Integer permanentId;
066
067 @Column(name = "switched_off", updatable = true, nullable = true)
068 private Boolean switchedOff = Boolean.FALSE;
069
070 public String getMessage() {
071 return message;
072 }
073
074 public void setMessage(String message) {
075 this.message = abbreviateMessage(message);
076 }
077
078 public static String abbreviateMessage(String message) {
079 return StringUtils.abbreviate(StringUtils.trim(message), MESSAGE_COLUMN_SIZE);
080 }
081
082 /**
083 * @deprecated since 2.7. Replace by getPriority()
084 */
085 @Deprecated
086 public RulePriority getLevel() {
087 return priority;
088 }
089
090 /**
091 * @deprecated since 2.7. Replace by setPriority()
092 */
093 @Deprecated
094 public void setLevel(RulePriority priority) {
095 this.priority = priority;
096 }
097
098 public Integer getRuleId() {
099 return ruleId;
100 }
101
102 public void setRuleId(Integer ruleId) {
103 this.ruleId = ruleId;
104 }
105
106 public Integer getLine() {
107 return line;
108 }
109
110 public RulePriority getPriority() {
111 return priority;
112 }
113
114 public Integer getSnapshotId() {
115 return snapshotId;
116 }
117
118 public void setSnapshotId(Integer snapshotId) {
119 this.snapshotId = snapshotId;
120 }
121
122 public void setPriority(RulePriority priority) {
123 this.priority = priority;
124 }
125
126 public void setLine(Integer line) {
127 this.line = line;
128 }
129
130 public Double getCost() {
131 return cost;
132 }
133
134 public RuleFailureModel setCost(Double d) {
135 this.cost = d;
136 return this;
137 }
138
139 public Date getCreatedAt() {
140 return createdAt;
141 }
142
143 public void setCreatedAt(Date createdAt) {
144 this.createdAt = createdAt;
145 }
146
147 public String getChecksum() {
148 return checksum;
149 }
150
151 public void setChecksum(String checksum) {
152 this.checksum = checksum;
153 }
154
155 public Integer getPermanentId() {
156 return permanentId;
157 }
158
159 public RuleFailureModel setPermanentId(Integer i) {
160 this.permanentId = i;
161 return this;
162 }
163
164 public boolean isSwitchedOff() {
165 return (switchedOff != null && switchedOff.booleanValue());
166 }
167
168 public RuleFailureModel setSwitchedOff(boolean b) {
169 this.switchedOff = b;
170 return this;
171 }
172
173 @Override
174 public boolean equals(Object obj) {
175 if (!(obj instanceof RuleFailureModel)) {
176 return false;
177 }
178 if (this == obj) {
179 return true;
180 }
181 RuleFailureModel other = (RuleFailureModel) obj;
182 return new EqualsBuilder()
183 .append(getId(), other.getId()).isEquals();
184 }
185
186 @Override
187 public int hashCode() {
188 return new HashCodeBuilder(17, 37).
189 append(getId()).toHashCode();
190 }
191
192 @Override
193 public String toString() {
194 return ReflectionToStringBuilder.toString(this);
195 }
196 }