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.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 = false, 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 public RulePriority getLevel() {
078 return priority;
079 }
080
081 public void setLevel(RulePriority priority) {
082 this.priority = priority;
083 }
084
085 public Integer getRuleId() {
086 return ruleId;
087 }
088
089 public void setRuleId(Integer ruleId) {
090 this.ruleId = ruleId;
091 }
092
093 public Integer getLine() {
094 return line;
095 }
096
097 public RulePriority getPriority() {
098 return priority;
099 }
100
101 public Integer getSnapshotId() {
102 return snapshotId;
103 }
104
105 public void setSnapshotId(Integer snapshotId) {
106 this.snapshotId = snapshotId;
107 }
108
109 public void setPriority(RulePriority priority) {
110 this.priority = priority;
111 }
112
113 public void setLine(Integer line) {
114 this.line = line;
115 }
116
117 public Double getCost() {
118 return cost;
119 }
120
121 public RuleFailureModel setCost(Double d) {
122 this.cost = d;
123 return this;
124 }
125
126 public Date getCreatedAt() {
127 return createdAt;
128 }
129
130 public void setCreatedAt(Date createdAt) {
131 this.createdAt = createdAt;
132 }
133
134 public String getChecksum() {
135 return checksum;
136 }
137
138 public void setChecksum(String checksum) {
139 this.checksum = checksum;
140 }
141
142 @Override
143 public boolean equals(Object obj) {
144 if (!(obj instanceof RuleFailureModel)) {
145 return false;
146 }
147 if (this == obj) {
148 return true;
149 }
150 RuleFailureModel other = (RuleFailureModel) obj;
151 return new EqualsBuilder()
152 .append(getId(), other.getId()).isEquals();
153 }
154
155 @Override
156 public int hashCode() {
157 return new HashCodeBuilder(17, 37).
158 append(getId()).toHashCode();
159 }
160
161 @Override
162 public String toString() {
163 return ReflectionToStringBuilder.toString(this);
164 }
165 }