1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.catalog.jpa.model;
18
19 import org.apache.commons.lang3.builder.EqualsBuilder;
20 import org.apache.commons.lang3.builder.HashCodeBuilder;
21 import org.apache.logging.log4j.catalog.api.DataType;
22 import org.apache.logging.log4j.catalog.jpa.converter.BooleanToStringConverter;
23 import org.apache.logging.log4j.catalog.jpa.converter.DataTypeConverter;
24
25 import javax.persistence.CascadeType;
26 import javax.persistence.CollectionTable;
27 import javax.persistence.Column;
28 import javax.persistence.Convert;
29 import javax.persistence.ElementCollection;
30 import javax.persistence.Entity;
31 import javax.persistence.FetchType;
32 import javax.persistence.GeneratedValue;
33 import javax.persistence.GenerationType;
34 import javax.persistence.Id;
35 import javax.persistence.JoinColumn;
36 import javax.persistence.OneToMany;
37 import javax.persistence.Table;
38 import javax.persistence.UniqueConstraint;
39 import java.io.Serializable;
40 import java.util.HashSet;
41 import java.util.Set;
42
43 @Entity
44 @Table(name = "EVENT_ATTRIBUTE",
45 uniqueConstraints = { @UniqueConstraint(columnNames = { "NAME" })})
46 public class AttributeModel implements Serializable {
47 private static final long serialVersionUID = -756109102178482698L;
48
49 @Id
50 @GeneratedValue(strategy= GenerationType.IDENTITY)
51 @Column(name = "ID", updatable = false, nullable = false)
52 private Long id;
53 @Column(name = "NAME")
54 private String name;
55 @Column(name = "DISPLAY_NAME")
56 private String displayName;
57 @Column(name = "DESCRIPTION")
58 private String description;
59 @Column(name = "CATALOG_ID")
60 private String catalogId;
61 @Column(name = "DATATYPE")
62 @Convert(converter=DataTypeConverter.class)
63 private DataType dataType;
64 @Column(name = "INDEXED")
65 @Convert(converter=BooleanToStringConverter.class)
66 private boolean indexed;
67 @Column(name = "SORTABLE")
68 @Convert(converter=BooleanToStringConverter.class)
69 private boolean sortable;
70 @Column(name = "REQUIRED")
71 @Convert(converter=BooleanToStringConverter.class)
72 private boolean required;
73 @Column(name = "REQUEST_CONTEXT")
74 @Convert(converter=BooleanToStringConverter.class)
75 private boolean requestContext;
76 @ElementCollection(fetch = FetchType.EAGER)
77 @CollectionTable(name = "attribute_examples", joinColumns = @JoinColumn(name = "attribute_id"))
78 @Column(name = "example")
79 private Set<String> examples = new HashSet<>();
80 @ElementCollection(fetch = FetchType.EAGER)
81 @CollectionTable(name = "attribute_aliases", joinColumns = @JoinColumn(name = "attribute_id"))
82 @Column(name = "alias")
83 private Set<String> aliases = new HashSet<>();
84 @OneToMany(fetch = FetchType.EAGER, mappedBy = "attribute", cascade = CascadeType.ALL)
85 private Set<ConstraintModel> constraints;
86
87 public AttributeModel() {
88 catalogId = "DEFAULT";
89 }
90
91
92
93
94
95
96 public Long getId() {
97 return id;
98 }
99
100
101
102
103
104 public void setId(Long id) {
105 this.id = id;
106 }
107
108
109
110
111 public String getName() {
112 return name;
113 }
114
115
116
117
118
119 public void setName(String name) {
120 this.name = name;
121 }
122
123
124
125
126
127 public String getDisplayName() {
128 return displayName;
129 }
130
131
132
133
134
135 public void setDisplayName(String name) {
136 this.displayName = name;
137 }
138
139
140
141
142
143 public String getDescription() {
144 return description;
145 }
146
147
148
149
150
151 public void setDescription(String description) {
152 this.description = description;
153 }
154
155
156
157
158
159 public DataType getDataType() {
160 return dataType;
161 }
162
163
164
165
166
167 public void setDataType(DataType dataType) {
168 this.dataType = dataType;
169 }
170
171
172
173
174
175 public boolean isIndexed() {
176 return indexed;
177 }
178
179
180
181
182
183 public void setIndexed(boolean indexed) {
184 this.indexed = indexed;
185 }
186
187
188
189
190
191 public boolean isSortable() {
192 return sortable;
193 }
194
195
196
197
198
199 public void setSortable(boolean sortable) {
200 this.sortable = sortable;
201 }
202
203
204
205
206
207 public boolean isRequired() {
208 return required;
209 }
210
211
212
213
214
215 public void setRequired(boolean required) {
216 this.required = required;
217 }
218
219
220
221
222
223 public boolean isRequestContext() {
224 return requestContext;
225 }
226
227
228
229
230
231 public void setRequestContext(boolean isRequestContext) {
232 this.requestContext = isRequestContext;
233 }
234
235
236
237
238
239 public Set<String> getExamples() {
240 return examples;
241 }
242
243
244
245
246
247 public void setExamples(Set<String> examples) {
248 this.examples = examples;
249 }
250
251
252
253
254
255 public Set<String> getAliases() {
256 return aliases;
257 }
258
259
260
261
262
263 public String getCatalogId() {
264 return catalogId;
265 }
266
267
268
269
270
271 public void setCatalogId(String catalogId) {
272 this.catalogId = catalogId;
273 }
274
275
276
277
278
279 public void setAliases(Set<String> aliases) {
280 this.aliases = aliases;
281 }
282
283 public Set<ConstraintModel> getConstraints() {
284 return constraints;
285 }
286
287 public void setConstraints(Set<ConstraintModel> constraints) {
288 if (constraints == null) {
289 if (this.constraints == null) {
290 this.constraints = new HashSet<>();
291 }
292 } else {
293 for (ConstraintModel constraint : constraints) {
294 if (constraint.getAttribute() != this) {
295 constraint.setAttribute(this);
296 }
297 }
298 this.constraints = constraints;
299 }
300 }
301
302
303
304
305
306
307
308
309
310
311 public int hashCode() {
312 return new HashCodeBuilder().append(name).append(catalogId).toHashCode();
313 }
314
315 public boolean equals(Object o) {
316 if (this == o) return true;
317 if (o == null) return false;
318 if (!(o instanceof AttributeModel)) return false;
319
320 AttributeModel other = (AttributeModel)o;
321 return new EqualsBuilder().append(name, other.name).append(catalogId, other.catalogId).isEquals();
322 }
323 }