001/*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 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 */
020package org.sonar.api.database.model;
021
022import org.apache.commons.lang.StringUtils;
023import org.apache.commons.lang.builder.EqualsBuilder;
024import org.apache.commons.lang.builder.HashCodeBuilder;
025import org.apache.commons.lang.builder.ReflectionToStringBuilder;
026import org.sonar.api.database.BaseIdentifiable;
027import org.sonar.api.rules.RulePriority;
028
029import javax.persistence.*;
030import java.util.Date;
031
032@Entity
033@Table(name = "rule_failures")
034public 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  @Column(name = "person_id", updatable = true, nullable = true)
071  private Integer personId;
072
073  public String getMessage() {
074    return message;
075  }
076
077  public void setMessage(String message) {
078    this.message = abbreviateMessage(message);
079  }
080
081  public static String abbreviateMessage(String message) {
082    return StringUtils.abbreviate(StringUtils.trim(message), MESSAGE_COLUMN_SIZE);
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 i) {
106    this.snapshotId = i;
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  public Integer getPermanentId() {
143    return permanentId;
144  }
145
146  public RuleFailureModel setPermanentId(Integer i) {
147    this.permanentId = i;
148    return this;
149  }
150
151  public boolean isSwitchedOff() {
152    return (switchedOff != null && switchedOff.booleanValue());
153  }
154
155  public RuleFailureModel setSwitchedOff(boolean b) {
156    this.switchedOff = b;
157    return this;
158  }
159
160  public Integer getPersonId() {
161    return personId;
162  }
163
164  public RuleFailureModel setPersonId(Integer i) {
165    this.personId = i;
166    return this;
167  }
168
169  @Override
170  public boolean equals(Object obj) {
171    if (!(obj instanceof RuleFailureModel)) {
172      return false;
173    }
174    if (this == obj) {
175      return true;
176    }
177    RuleFailureModel other = (RuleFailureModel) obj;
178    return new EqualsBuilder()
179      .append(getId(), other.getId()).isEquals();
180  }
181
182  @Override
183  public int hashCode() {
184    return new HashCodeBuilder(17, 37).
185      append(getId()).toHashCode();
186  }
187
188  @Override
189  public String toString() {
190    return ReflectionToStringBuilder.toString(this);
191  }
192}