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
200
201
202
203
204
205
206
207
208
209
210
211
|
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar 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.
*
* Sonar 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 Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.api.profiles;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.sonar.api.database.BaseIdentifiable;
import org.sonar.api.measures.Metric;
import javax.persistence.*;
/**
* Class to map alerts with hibernate model
*/
@Entity
@Table(name = "alerts")
public class Alert extends BaseIdentifiable implements Cloneable {
/**
* Operator strictly greater than
*/
public static final String OPERATOR_GREATER = ">";
/**
* Operator strictly lesser than
*/
public static final String OPERATOR_SMALLER = "<";
/**
* Operator equals
*/
public static final String OPERATOR_EQUALS = "=";
/**
* Operator not equals
*/
public static final String OPERATOR_NOT_EQUALS = "!=";
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "profile_id")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
private RulesProfile rulesProfile;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "metric_id", nullable = true)
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
private Metric metric;
@Column(name = "operator", updatable = false, nullable = true, length = 3)
private String operator;
@Column(name = "value_error", updatable = false, nullable = true, length = 64)
private String valueError;
@Column(name = "value_warning", updatable = false, nullable = true, length = 64)
private String valueWarning;
/**
* Default constructor
*/
public Alert() {
}
/**
* Creates an alert
*
* @param rulesProfile the profile used to trigger the alert
* @param metric the metric tested for the alert
* @param operator the operator defined
* @param valueError the error value
* @param valueWarning the warning value
*/
public Alert(RulesProfile rulesProfile, Metric metric, String operator, String valueError, String valueWarning) {
super();
this.rulesProfile = rulesProfile;
this.metric = metric;
this.operator = operator;
this.valueError = valueError;
this.valueWarning = valueWarning;
}
/**
* @return the alert profile
*/
public RulesProfile getRulesProfile() {
return rulesProfile;
}
/**
* Sets the alert profile
*/
public void setRulesProfile(RulesProfile rulesProfile) {
this.rulesProfile = rulesProfile;
}
/**
* @return the alert metric
*/
public Metric getMetric() {
return metric;
}
/**
* Sets the alert metric
*/
public void setMetric(Metric metric) {
this.metric = metric;
}
/**
* @return the alert operator
*/
public String getOperator() {
return operator;
}
/**
* Sets the alert operator
*/
public void setOperator(String operator) {
this.operator = operator;
}
/**
* @return the error value
*/
public String getValueError() {
return valueError;
}
/**
* Sets the error value if any
*/
public void setValueError(String valueError) {
this.valueError = valueError;
}
/**
* @return the warning value
*/
public String getValueWarning() {
return valueWarning;
}
/**
* Sets the warning value if any
*/
public void setValueWarning(String valueWarning) {
this.valueWarning = valueWarning;
}
/**
* @return whether the operator is greater than
*/
public boolean isGreaterOperator() {
return operator.equals(OPERATOR_GREATER);
}
/**
* @return whether the operator is lesser than
*/
public boolean isSmallerOperator() {
return operator.equals(OPERATOR_SMALLER);
}
/**
* @return whether the operator is equals
*/
public boolean isEqualsOperator() {
return operator.equals(OPERATOR_EQUALS);
}
/**
* @return whether the operator is not equals
*/
public boolean isNotEqualsOperator() {
return operator.equals(OPERATOR_NOT_EQUALS);
}
public String getAlertLabel(Metric.Level level) {
return new StringBuilder()
.append(getMetric().getName())
.append(" ").append(getOperator())
.append(" ")
.append(level.equals(Metric.Level.ERROR) ? getValueError() : getValueWarning()).toString();
}
@Override
public Object clone() {
return new Alert(getRulesProfile(), getMetric(), getOperator(), getValueError(), getValueWarning());
}
}
|