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 = 450;
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      public RuleFailureModel() {
056      }
057    
058      public RuleFailureModel(Rule rule, RulePriority priority) {
059        this.rule = rule;
060        this.priority = priority;
061      }
062    
063    
064      public String getMessage() {
065        return message;
066      }
067    
068      public void setMessage(String message) {
069        this.message = StringUtils.abbreviate(StringUtils.trim(message), MESSAGE_COLUMN_SIZE);
070      }
071    
072      public RulePriority getLevel() {
073        return priority;
074      }
075    
076      public void setLevel(RulePriority priority) {
077        this.priority = priority;
078      }
079    
080      public Rule getRule() {
081        return rule;
082      }
083    
084      public void setRule(Rule rule) {
085        this.rule = rule;
086      }
087    
088      public Integer getLine() {
089        return line;
090      }
091    
092      public RulePriority getPriority() {
093        return priority;
094      }
095    
096      public Integer getSnapshotId() {
097        return snapshotId;
098      }
099    
100      public void setSnapshotId(Integer snapshotId) {
101        this.snapshotId = snapshotId;
102      }
103    
104      public void setPriority(RulePriority priority) {
105        this.priority = priority;
106      }
107    
108      public void setLine(Integer line) {
109        this.line = line;
110      }
111    
112      @Override
113      public boolean equals(Object obj) {
114        if (!(obj instanceof RuleFailureModel)) {
115          return false;
116        }
117        if (this == obj) {
118          return true;
119        }
120        RuleFailureModel other = (RuleFailureModel) obj;
121        return new EqualsBuilder()
122            .append(getId(), other.getId()).isEquals();
123      }
124    
125      @Override
126      public int hashCode() {
127        return new HashCodeBuilder(17, 37).
128            append(getId()).toHashCode();
129      }
130    
131      @Override
132      public String toString() {
133        return ReflectionToStringBuilder.toString(this);
134      }
135    }