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.Rule;
028 import org.sonar.api.rules.RulePriority;
029
030 import javax.persistence.*;
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 @ManyToOne(fetch = FetchType.EAGER)
042 @JoinColumn(name = "rule_id")
043 private Rule rule;
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 public RuleFailureModel() {
059 }
060
061 public RuleFailureModel(Rule rule, RulePriority priority) {
062 this.rule = rule;
063 this.priority = priority;
064 }
065
066
067 public String getMessage() {
068 return message;
069 }
070
071 public void setMessage(String message) {
072 this.message = StringUtils.abbreviate(StringUtils.trim(message), MESSAGE_COLUMN_SIZE);
073 }
074
075 public RulePriority getLevel() {
076 return priority;
077 }
078
079 public void setLevel(RulePriority priority) {
080 this.priority = priority;
081 }
082
083 public Rule getRule() {
084 return rule;
085 }
086
087 public void setRule(Rule rule) {
088 this.rule = rule;
089 }
090
091 public Integer getLine() {
092 return line;
093 }
094
095 public RulePriority getPriority() {
096 return priority;
097 }
098
099 public Integer getSnapshotId() {
100 return snapshotId;
101 }
102
103 public void setSnapshotId(Integer snapshotId) {
104 this.snapshotId = snapshotId;
105 }
106
107 public void setPriority(RulePriority priority) {
108 this.priority = priority;
109 }
110
111 public void setLine(Integer line) {
112 this.line = line;
113 }
114
115 public Double getCost() {
116 return cost;
117 }
118
119 public RuleFailureModel setCost(Double d) {
120 this.cost = d;
121 return this;
122 }
123
124 @Override
125 public boolean equals(Object obj) {
126 if (!(obj instanceof RuleFailureModel)) {
127 return false;
128 }
129 if (this == obj) {
130 return true;
131 }
132 RuleFailureModel other = (RuleFailureModel) obj;
133 return new EqualsBuilder()
134 .append(getId(), other.getId()).isEquals();
135 }
136
137 @Override
138 public int hashCode() {
139 return new HashCodeBuilder(17, 37).
140 append(getId()).toHashCode();
141 }
142
143 @Override
144 public String toString() {
145 return ReflectionToStringBuilder.toString(this);
146 }
147 }