1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.rules;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.BaseIdentifiable;
import org.sonar.api.profiles.RulesProfile;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* A class to map a RuleChange to the hibernate model
*
* @since 2.9
*/
@Entity
@Table(name = "active_rule_changes")
public class ActiveRuleChange extends BaseIdentifiable {
@Column(name = "username", updatable = false, nullable = true)
private String userName;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "profile_id", updatable = false, nullable = false)
private RulesProfile rulesProfile;
@Column(name = "profile_version", updatable = false, nullable = false)
private int profileVersion;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "rule_id", updatable = false, nullable = false)
private Rule rule;
@Column(name = "change_date", updatable = false, nullable = false)
private Date date;
/**
* true means rule was enabled
* false means rule was disabled
* null means rule stay enabled (another param was changed)
*/
@Column(name = "enabled")
private Boolean enabled;
@Column(name = "old_severity", updatable = false, nullable = true)
@Enumerated(EnumType.ORDINAL)
private RulePriority oldSeverity;
@Column(name = "new_severity", updatable = false, nullable = true)
@Enumerated(EnumType.ORDINAL)
private RulePriority newSeverity;
@OneToMany(mappedBy = "activeRuleChange", fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE })
private List<ActiveRuleParamChange> activeRuleParamChanges = new ArrayList<ActiveRuleParamChange>();
public ActiveRuleChange(String userName, RulesProfile profile, Rule rule) {
this.userName = userName;
this.rulesProfile = profile;
this.profileVersion = profile.getVersion();
this.rule = rule;
this.date = Calendar.getInstance().getTime();
}
public Rule getRule() {
return rule;
}
public RulePriority getOldSeverity() {
return oldSeverity;
}
public void setOldSeverity(RulePriority oldSeverity) {
this.oldSeverity = oldSeverity;
}
public RulePriority getNewSeverity() {
return newSeverity;
}
public void setNewSeverity(RulePriority newSeverity) {
this.newSeverity = newSeverity;
}
public RulesProfile getRulesProfile() {
return rulesProfile;
}
public int getProfileVersion() {
return profileVersion;
}
public String getRepositoryKey() {
return rule.getRepositoryKey();
}
/**
* @return the config key the changed rule belongs to
*/
public String getConfigKey() {
return rule.getConfigKey();
}
/**
* @return the key of the changed rule
*/
public String getRuleKey() {
return rule.getKey();
}
public Boolean isEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public List<ActiveRuleParamChange> getActiveRuleParamChanges() {
return activeRuleParamChanges;
}
public String getUserName() {
return userName;
}
public ActiveRuleChange setParameterChange(String key, String oldValue, String newValue) {
RuleParam ruleParameter = rule.getParam(key);
if (ruleParameter != null) {
activeRuleParamChanges.add(new ActiveRuleParamChange(this, ruleParameter, oldValue, newValue));
}
return this;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}
ActiveRuleChange rhs = (ActiveRuleChange) obj;
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(userName, rhs.userName)
.append(rulesProfile, rhs.rulesProfile)
.append(rule, rhs.rule)
.append(date, rhs.date)
.append(enabled, rhs.enabled)
.append(newSeverity, rhs.newSeverity)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(41, 33)
.append(userName)
.append(rulesProfile)
.append(rule)
.append(date)
.append(enabled)
.append(newSeverity)
.toHashCode();
}
@Override
public String toString() {
return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
}
}
|