1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.domain

File ConfigurationDO.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
49
26
1
346
172
32
0.65
1.88
26
1.23

Classes

Class Line # Actions
ConfigurationDO 35 49 0% 32 0
1.0100%
 

Contributing tests

This file is covered by 48 tests. .

Source view

1    package org.europa.together.domain;
2   
3    import java.io.Serializable;
4    import java.util.Objects;
5    import jakarta.persistence.Column;
6    import jakarta.persistence.Entity;
7    import jakarta.persistence.Id;
8    import jakarta.persistence.Index;
9    import jakarta.persistence.PrePersist;
10    import jakarta.persistence.Table;
11    import jakarta.persistence.UniqueConstraint;
12    import org.europa.together.application.LogbackLogger;
13    import org.europa.together.business.Logger;
14    import org.europa.together.utils.StringUtils;
15   
16    /**
17    * Application wide configuration with key=value entries. For an easier
18    * maintenance are entries with module-name, module-version and a deprecated
19    * marker extended.
20    */
21    @Entity
22    @Table(name = "APP_CONFIG",
23    //CHECKSTYLE:OFF
24    indexes = {
25    @Index(columnList = "CONF_KEY", name = "configuration_key"),
26    @Index(columnList = "MODUL_NAME", name = "modul_name"),
27    @Index(columnList = "CONF_SET", name = "configuration_set")
28    },
29    //CHECKSTYLE:ON
30    uniqueConstraints = {
31    @UniqueConstraint(columnNames
32    = {"MODUL_NAME", "SERVICE_VERSION", "CONF_KEY"})
33    }
34    )
 
35    public class ConfigurationDO implements Serializable {
36   
37    private static final long serialVersionUID = 102L;
38    private static final Logger LOGGER = new LogbackLogger(ConfigurationDO.class);
39   
40    /**
41    * The name of the used database table for this domain object.
42    */
43    public static final String TABLE_NAME = "APP_CONFIG";
44   
45    @Id //validate uuid
46    @Column(name = "IDX")
47    private String uuid;
48   
49    @Column(name = "CONF_KEY", nullable = false)
50    private String key;
51   
52    @Column(name = "CONF_VALUE")
53    private String value;
54   
55    @Column(name = "DEFAULT_VALUE", nullable = false)
56    private String defaultValue;
57   
58    @Column(name = "MODUL_NAME", nullable = false)
59    private String modulName;
60   
61    @Column(name = "SERVICE_VERSION", nullable = false)
62    private String version;
63   
64    @Column(name = "CONF_SET", nullable = false)
65    private String configurationSet;
66   
67    @Column(name = "DEPRECATED", nullable = false)
68    private boolean deprecated;
69   
70    @Column(name = "MANDATORY", nullable = false)
71    private boolean mandatory;
72   
73    @Column(name = "COMMENT")
74    private String comment;
75   
76    /**
77    * Constructor.
78    */
 
79  316 toggle public ConfigurationDO() {
80    //PreSet
81  316 this.uuid = StringUtils.generateUUID();
82    }
83   
84    /**
85    * Constructor.
86    *
87    * @param key as String
88    * @param value as String
89    * @param modulName as String
90    * @param version as String
91    */
 
92  10 toggle public ConfigurationDO(final String key, final String value, final String modulName,
93    final String version) {
94    //PreSet
95  10 this.uuid = StringUtils.generateUUID();
96    //mandatory
97  10 this.modulName = modulName;
98  10 this.version = version;
99  10 this.key = key;
100  10 this.value = value;
101    //optional
102  10 this.configurationSet = "default";
103  10 this.defaultValue = "NIL";
104  10 this.deprecated = false;
105  10 this.mandatory = false;
106  10 this.comment = "";
107    }
108   
109    /**
110    * Actions who have to performed before objects get persisted. e.g. cerate
111    * default entries in the database.
112    */
 
113  8 toggle @PrePersist
114    public void prePersist() {
115  8 this.configurationSet = "default";
116  8 this.defaultValue = "NIL";
117  8 this.deprecated = false;
118  8 this.mandatory = false;
119  8 LOGGER.log("@PrePersist [ConfigurationDO]", LogLevel.INFO);
120    }
121   
122    //<editor-fold defaultstate="collapsed" desc="Getter / Setter">
123    /**
124    * Show if entry is deprecated.
125    *
126    * @return true if is deprecated
127    */
 
128  2 toggle public boolean isDeprecated() {
129  2 return deprecated;
130    }
131   
132    /**
133    * Mark if an configuration entry is mandatory.
134    *
135    * @return true if is mandatory
136    */
 
137  5 toggle public boolean isMandatory() {
138  5 return mandatory;
139    }
140   
141    /**
142    * Set the comment.
143    *
144    * @param comment as String
145    */
 
146  3 toggle public void setComment(final String comment) {
147  3 this.comment = comment;
148    }
149   
150    /**
151    * Set the configuration set.
152    *
153    * @param configurationSet as String
154    */
 
155  36 toggle public void setConfigurationSet(final String configurationSet) {
156  36 this.configurationSet = configurationSet;
157    }
158   
159    /**
160    * Set the default value.
161    *
162    * @param defaultValue as String
163    */
 
164  36 toggle public void setDefaultValue(final String defaultValue) {
165  36 this.defaultValue = defaultValue;
166    }
167   
168    /**
169    * Set if a entry is deprecated.
170    *
171    * @param deprecated as boolean
172    */
 
173  2 toggle public void setDeprecated(final boolean deprecated) {
174  2 this.deprecated = deprecated;
175    }
176   
177    /**
178    * Set if a entry is mandatory.
179    *
180    * @param mandatory as boolean
181    */
 
182  2 toggle public void setMandatory(final boolean mandatory) {
183  2 this.mandatory = mandatory;
184    }
185   
186    /**
187    * Set key.
188    *
189    * @param key as String
190    */
 
191  45 toggle public void setKey(final String key) {
192  45 this.key = key;
193    }
194   
195    /**
196    * Set module´name.
197    *
198    * @param modulName as String
199    */
 
200  45 toggle public void setModulName(final String modulName) {
201  45 this.modulName = modulName;
202    }
203   
204    /**
205    * Set the UUID.
206    *
207    * @param uuid as String
208    */
 
209  34 toggle public void setUuid(final String uuid) {
210  34 this.uuid = uuid;
211    }
212   
213    /**
214    * Set value.
215    *
216    * @param value as String
217    */
 
218  53 toggle public void setValue(final String value) {
219  53 this.value = value;
220    }
221   
222    /**
223    * Set version of module.
224    *
225    * @param version as String
226    */
 
227  43 toggle public void setVersion(final String version) {
228  43 this.version = version;
229    }
230   
231    /**
232    * Get the comment.
233    *
234    * @return comment as String
235    */
 
236  3 toggle public String getComment() {
237  3 return comment;
238    }
239   
240    /**
241    * Get the configuration set.
242    *
243    * @return ConfigurationSet as String.
244    */
 
245  3 toggle public String getConfigurationSet() {
246  3 return configurationSet;
247    }
248   
249    /**
250    * Get the default value.
251    *
252    * @return dafaultValue as String
253    */
 
254  65 toggle public String getDefaultValue() {
255  65 return defaultValue;
256    }
257   
258    /**
259    * Get the key.
260    *
261    * @return key as String
262    */
 
263  286 toggle public String getKey() {
264  286 return key;
265    }
266   
267    /**
268    * Get Modulename.
269    *
270    * @return modulename as String
271    */
 
272  2 toggle public String getModulName() {
273  2 return modulName;
274    }
275   
276    /**
277    * Get the UUID.
278    *
279    * @return UUID as String
280    */
 
281  85 toggle public String getUuid() {
282  85 return uuid;
283    }
284   
285    /**
286    * Get value.
287    *
288    * @return value as String
289    */
 
290  122 toggle public String getValue() {
291  122 return value;
292    }
293   
294    /**
295    * Get module version.
296    *
297    * @return moduleversion as String
298    */
 
299  8 toggle public String getVersion() {
300  8 return version;
301    }
302    //</editor-fold>
303   
 
304  23 toggle @Override
305    public boolean equals(final Object obj) {
306   
307  23 boolean success = false;
308  23 if (obj != null && obj instanceof ConfigurationDO) {
309   
310  21 if (this == obj) {
311  1 success = true;
312    } else {
313   
314  20 final ConfigurationDO other = (ConfigurationDO) obj;
315  20 if (Objects.equals(this.key, other.key)
316    && Objects.equals(this.modulName, other.modulName)
317    && Objects.equals(this.version, other.version)) {
318  7 success = true;
319    }
320    }
321    }
322  23 return success;
323    }
324   
 
325  6 toggle @Override
326    public int hashCode() {
327  6 int hash = Objects.hashCode(this.key);
328  6 hash += Objects.hashCode(this.modulName);
329  6 hash += Objects.hashCode(this.version);
330  6 return hash;
331    }
332   
 
333  41 toggle @Override
334    public String toString() {
335  41 return "ConfigurationDO{" + "uuid=" + uuid
336    + ", key=" + key
337    + ", value=" + value
338    + ", defaultValue=" + defaultValue
339    + ", modulName=" + modulName
340    + ", configurationSet=" + configurationSet
341    + ", version=" + version
342    + ", deprecated=" + deprecated
343    + ", mandatory=" + mandatory
344    + ", comment=" + comment + '}';
345    }
346    }