View Javadoc

1   /*
2    * Sonar, entreprise quality control tool.
3    * Copyright (C) 2007-2008 Hortis-GRC SA
4    * mailto:be_agile HAT hortis DOT ch
5    *
6    * Sonar is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * Sonar is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with {library}; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
19   */
20  package ch.hortis.sonar.model;
21  
22  import org.apache.commons.lang.builder.EqualsBuilder;
23  import org.apache.commons.lang.builder.HashCodeBuilder;
24  import org.apache.commons.lang.builder.ToStringBuilder;
25  import org.sonar.commons.rules.ActiveRuleParam;
26  
27  import javax.persistence.*;
28  import java.io.Serializable;
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  @Entity
33  @Table(name = "active_rules")
34  public class ActiveRule implements Serializable {
35  
36    private static final long serialVersionUID = -6161808961786732538L;
37  
38    @Id
39    @Column(name = "id")
40    @SequenceGenerator(name = "ACTIVE_RULES_SEQ", sequenceName = "ACTIVE_RULES_SEQ")
41    @GeneratedValue(strategy = GenerationType.AUTO, generator = "ACTIVE_RULES_SEQ")
42    private Integer id;
43  
44    @ManyToOne(fetch = FetchType.EAGER)
45    @JoinColumn(name = "rule_id", updatable = true, nullable = false)
46    private Rule rule;
47  
48    @Column(name = "failure_level", updatable = true, nullable = false)
49    @Enumerated(EnumType.ORDINAL)
50    private RuleFailureLevel level;
51  
52    @ManyToOne(fetch = FetchType.LAZY)
53    @JoinColumn(name = "profile_id", updatable = true, nullable = false)
54    private RulesProfile rulesProfile;
55  
56    @OneToMany(mappedBy = "activeRule", cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE})
57    private List<ActiveRuleParam> activeRuleParams = new ArrayList<ActiveRuleParam>();
58  
59    public ActiveRule() {
60    }
61  
62    public ActiveRule(RulesProfile profile, Rule rule, RuleFailureLevel level) {
63      this.rule = rule;
64      this.level = level;
65      this.rulesProfile = profile;
66    }
67  
68    public Integer getId() {
69      return id;
70    }
71  
72    public void setId(Integer id) {
73      this.id = id;
74    }
75  
76    public Rule getRule() {
77      return rule;
78    }
79  
80    public void setRule(Rule rule) {
81      this.rule = rule;
82    }
83  
84    public RuleFailureLevel getLevel() {
85      return level;
86    }
87  
88    public void setLevel(RuleFailureLevel level) {
89      this.level = level;
90    }
91  
92    public RulesProfile getRulesProfile() {
93      return rulesProfile;
94    }
95  
96    public void setRulesProfile(RulesProfile rulesProfile) {
97      this.rulesProfile = rulesProfile;
98    }
99  
100   public List<ActiveRuleParam> getActiveRuleParams() {
101     return activeRuleParams;
102   }
103 
104   public void setActiveRuleParams(List<ActiveRuleParam> params) {
105     this.activeRuleParams = params;
106   }
107 
108   public boolean equals(Object obj) {
109     if (!(obj instanceof ActiveRule)) {
110       return false;
111     }
112     if (this == obj) {
113       return true;
114     }
115     ActiveRule other = (ActiveRule) obj;
116     return new EqualsBuilder()
117         .append(id, other.getId()).isEquals();
118   }
119 
120   public int hashCode() {
121     return new HashCodeBuilder(17, 37).
122         append(id).toHashCode();
123   }
124 
125   public String toString() {
126     return new ToStringBuilder(this)
127         .append("id", id)
128         .append("rule", rule)
129         .append("level", level)
130         .append("params", activeRuleParams)
131         .toString();
132   }
133 }