1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
25 import javax.persistence.*;
26 import java.io.Serializable;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 @Entity
31 @Table(name = "rules_profiles")
32 public class RulesProfile implements Serializable {
33 public static final String SONAR_WAY_NAME = "Sonar way";
34 public static final String SUN_CONVENTIONS_NAME = "Sun checks";
35
36 @Id
37 @Column(name = "id")
38 @SequenceGenerator(name = "RULES_PROFILES_SEQ", sequenceName = "RULES_PROFILES_SEQ")
39 @GeneratedValue(strategy = GenerationType.AUTO, generator = "RULES_PROFILES_SEQ")
40 private Integer id;
41
42 @Column(name = "name", updatable = true, nullable = false)
43 private String name;
44
45 @Column(name = "active", updatable = true, nullable = false)
46 private Boolean active = Boolean.FALSE;
47
48 @Column(name = "provided", updatable = true, nullable = false)
49 private Boolean provided = Boolean.FALSE;
50
51 @Column(name = "language", updatable = true, nullable = false)
52 private String language;
53
54 @OneToMany(mappedBy = "rulesProfile", fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE})
55 private List<ActiveRule> activeRules;
56
57 public RulesProfile() {
58 }
59
60 public RulesProfile(String name) {
61 this.name=name;
62 activeRules = new ArrayList<ActiveRule>();
63 }
64
65 public RulesProfile(String name, String language, boolean active, boolean provided) {
66 this.name=name;
67 this.language=language;
68 this.active=active;
69 this.provided=provided;
70 activeRules = new ArrayList<ActiveRule>();
71 }
72
73 public Integer getId() {
74 return id;
75 }
76
77 public void setId(Integer id) {
78 this.id = id;
79 }
80
81 public String getName() {
82 return name;
83 }
84
85 public void setName(String name) {
86 this.name = name;
87 }
88
89 public List<ActiveRule> getActiveRules() {
90 return activeRules;
91 }
92
93 public void setActiveRules(List<ActiveRule> activeRules) {
94 this.activeRules = activeRules;
95 }
96
97 public Boolean getActive() {
98 return active;
99 }
100
101 public void setActive(Boolean active) {
102 this.active = active;
103 }
104
105 public Boolean getProvided() {
106 return provided;
107 }
108
109 public void setProvided(Boolean provided) {
110 this.provided = provided;
111 }
112
113 public String getLanguage() {
114 return language;
115 }
116
117 public void setLanguage(String language) {
118 this.language = language;
119 }
120
121 public boolean equals(Object obj) {
122 if (!(obj instanceof RulesProfile)) {
123 return false;
124 }
125 if (this == obj) {
126 return true;
127 }
128 RulesProfile other = (RulesProfile) obj;
129 return new EqualsBuilder()
130 .append(language, other.getLanguage())
131 .append(name, other.getName())
132 .isEquals();
133 }
134
135 public int hashCode() {
136 return new HashCodeBuilder(17, 37)
137 .append(language)
138 .append(name)
139 .toHashCode();
140 }
141
142 public List<ActiveRule> getActiveRules(RuleFailureLevel level) {
143 List<ActiveRule> result = new ArrayList<ActiveRule>();
144 for(ActiveRule activeRule:getActiveRules()) {
145 if(activeRule.getLevel().equals(level)) {
146 result.add(activeRule);
147 }
148 }
149 return result;
150 }
151
152 public List<ActiveRule> getActiveRulesByPlugin(String pluginKey) {
153 List<ActiveRule> result = new ArrayList<ActiveRule>();
154 for(ActiveRule activeRule:getActiveRules()) {
155 if(pluginKey.equals(activeRule.getRule().getPluginName())) {
156 result.add(activeRule);
157 }
158 }
159 return result;
160 }
161
162 public ActiveRule getActiveRule(String pluginKey, String ruleKey) {
163 for(ActiveRule activeRule:getActiveRules()) {
164 if(activeRule.getRule().getKey().equals(ruleKey) && activeRule.getRule().getPluginName().equals(pluginKey)) {
165 return activeRule;
166 }
167 }
168 return null;
169 }
170
171 }