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      @Column(name = "committer", updatable = true, nullable = true, length = 100)
071      private String committer;
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      /**
086       * @deprecated since 2.7. Replace by getPriority()
087       */
088      @Deprecated
089      public RulePriority getLevel() {
090        return priority;
091      }
092    
093      /**
094       * @deprecated since 2.7. Replace by setPriority()
095       */
096      @Deprecated
097      public void setLevel(RulePriority priority) {
098        this.priority = priority;
099      }
100    
101      public Integer getRuleId() {
102        return ruleId;
103      }
104    
105      public void setRuleId(Integer ruleId) {
106        this.ruleId = ruleId;
107      }
108    
109      public Integer getLine() {
110        return line;
111      }
112    
113      public RulePriority getPriority() {
114        return priority;
115      }
116    
117      public Integer getSnapshotId() {
118        return snapshotId;
119      }
120    
121      public void setSnapshotId(Integer i) {
122        this.snapshotId = i;
123      }
124    
125      public void setPriority(RulePriority priority) {
126        this.priority = priority;
127      }
128    
129      public void setLine(Integer line) {
130        this.line = line;
131      }
132    
133      public Double getCost() {
134        return cost;
135      }
136    
137      public RuleFailureModel setCost(Double d) {
138        this.cost = d;
139        return this;
140      }
141    
142      public Date getCreatedAt() {
143        return createdAt;
144      }
145    
146      public void setCreatedAt(Date createdAt) {
147        this.createdAt = createdAt;
148      }
149    
150      public String getChecksum() {
151        return checksum;
152      }
153    
154      public void setChecksum(String checksum) {
155        this.checksum = checksum;
156      }
157    
158      public Integer getPermanentId() {
159        return permanentId;
160      }
161    
162      public RuleFailureModel setPermanentId(Integer i) {
163        this.permanentId = i;
164        return this;
165      }
166    
167      public boolean isSwitchedOff() {
168        return (switchedOff != null && switchedOff.booleanValue());
169      }
170    
171      public RuleFailureModel setSwitchedOff(boolean b) {
172        this.switchedOff = b;
173        return this;
174      }
175    
176      public String getCommitter() {
177        return committer;
178      }
179    
180      public RuleFailureModel setCommitter(String committer) {
181        this.committer = committer;
182        return this;
183      }
184    
185      @Override
186      public boolean equals(Object obj) {
187        if (!(obj instanceof RuleFailureModel)) {
188          return false;
189        }
190        if (this == obj) {
191          return true;
192        }
193        RuleFailureModel other = (RuleFailureModel) obj;
194        return new EqualsBuilder()
195          .append(getId(), other.getId()).isEquals();
196      }
197    
198      @Override
199      public int hashCode() {
200        return new HashCodeBuilder(17, 37).
201          append(getId()).toHashCode();
202      }
203    
204      @Override
205      public String toString() {
206        return ReflectionToStringBuilder.toString(this);
207      }
208    }