-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathNotificationRule.java
More file actions
268 lines (220 loc) · 7.35 KB
/
NotificationRule.java
File metadata and controls
268 lines (220 loc) · 7.35 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* This file is part of Dependency-Track.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* Copyright (c) OWASP Foundation. All Rights Reserved.
*/
package org.dependencytrack.persistence.model;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import org.dependencytrack.persistence.converter.NotificationScopeConverter;
import org.hibernate.annotations.JdbcType;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
@Entity
@Table(name = "NOTIFICATIONRULE")
public class NotificationRule extends PanacheEntityBase {
@Id
@Column(name = "ID")
private long id;
@Column(name = "NAME", nullable = false)
private String name;
@Column(name = "ENABLED", nullable = false)
private boolean enabled;
@Column(name = "SCOPE", nullable = false, columnDefinition = "varchar")
@Convert(converter = NotificationScopeConverter.class)
private NotificationScope scope;
@JdbcTypeCode(SqlTypes.NAMED_ENUM)
@Column(name = "NOTIFICATION_LEVEL", columnDefinition = "notification_level", nullable = false)
private NotificationLevel notificationLevel;
@OneToMany
@JoinTable(
name = "NOTIFICATIONRULE_PROJECTS",
joinColumns = @JoinColumn(name = "NOTIFICATIONRULE_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "PROJECT_ID", referencedColumnName = "ID")
)
@OrderBy("name ASC, version ASC")
private List<Project> projects;
@OneToMany
@JoinTable(
name = "NOTIFICATIONRULE_TAGS",
joinColumns = @JoinColumn(name = "NOTIFICATIONRULE_ID", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "TAG_ID", referencedColumnName = "ID")
)
@OrderBy("name ASC")
private List<Tag> tags;
// @Join(column = "NOTIFICATIONRULE_ID")
// @Element(column = "TEAM_ID")
// @Order(extensions = @Extension(vendorName = "datanucleus", key = "list-ordering", value = "name ASC"))
// @OneToMany(cascade = CascadeType.ALL)
// @JoinTable(
// name = "Team",
// joinColumns = @JoinColumn(name = "TEAM_ID")
// )
// @OrderBy("name ASC")
// private List<Team> teams;
@Column(name = "NOTIFY_ON")
private String notifyOn;
@Column(name = "MESSAGE")
private String message;
@JoinColumn(name = "PUBLISHER", columnDefinition = "bigint")
@ManyToOne(cascade = CascadeType.ALL)
private NotificationPublisher publisher;
@Column(name = "PUBLISHER_CONFIG")
private String publisherConfig;
@Column(name = "UUID", nullable = false)
@JdbcType(UUIDJdbcType.class)
private UUID uuid;
@Column(name = "NOTIFY_CHILDREN")
private boolean notifyChildren;
/**
* In addition to warnings and errors, also emit a log message upon successful publishing.
* <p>
* Intended to aid in debugging of missing notifications, or environments where notification
* delivery is critical and subject to auditing.
*
* @since 4.10.0
*/
@Column(name = "LOG_SUCCESSFUL_PUBLISH")
private Boolean logSuccessfulPublish;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isLogSuccessfulPublish() {
return logSuccessfulPublish != null ? logSuccessfulPublish : false;
}
public void setLogSuccessfulPublish(final boolean logSuccessfulPublish) {
this.logSuccessfulPublish = logSuccessfulPublish;
}
public NotificationScope getScope() {
return scope;
}
public void setScope(NotificationScope scope) {
this.scope = scope;
}
public NotificationLevel getNotificationLevel() {
return notificationLevel;
}
public void setNotificationLevel(NotificationLevel notificationLevel) {
this.notificationLevel = notificationLevel;
}
public boolean isNotifyChildren() {
return notifyChildren;
}
public void setNotifyChildren(boolean notifyChildren) {
this.notifyChildren = notifyChildren;
}
public List<Project> getProjects() {
return projects;
}
public void setProjects(List<Project> projects) {
this.projects = projects;
}
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
// public List<Team> getTeams() {
// return teams;
// }
//
// public void setTeams(List<Team> teams) {
// this.teams = teams;
// }
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Set<NotificationGroup> getNotifyOn() {
Set<NotificationGroup> result = new TreeSet<>();
if (notifyOn != null) {
String[] groups = notifyOn.split(",");
for (String s : groups) {
result.add(NotificationGroup.valueOf(s.trim()));
}
}
return result;
}
public void setNotifyOn(Set<NotificationGroup> groups) {
if (groups.isEmpty()) {
this.notifyOn = null;
return;
}
StringBuilder sb = new StringBuilder();
List<NotificationGroup> list = new ArrayList<>(groups);
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
sb.append(list.get(i));
if (i + 1 < list.size()) {
sb.append(",");
}
}
this.notifyOn = sb.toString();
}
public NotificationPublisher getPublisher() {
return publisher;
}
public void setPublisher(NotificationPublisher publisher) {
this.publisher = publisher;
}
public String getPublisherConfig() {
return publisherConfig;
}
public void setPublisherConfig(String publisherConfig) {
this.publisherConfig = publisherConfig;
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
}