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