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