Skip to content

Commit dd7cf26

Browse files
committed
#13296 - Code clean-up
1 parent 6e2ac21 commit dd7cf26

19 files changed

Lines changed: 462 additions & 193 deletions

sormas-api/src/main/java/de/symeda/sormas/api/systemconfiguration/SystemConfigurationCategoryDto.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
/**
2828
* Data Transfer Object for System Configuration Category.
29+
* This class represents a category in the system configuration.
2930
*/
3031
public class SystemConfigurationCategoryDto extends EntityDto {
3132

@@ -53,6 +54,26 @@ public static SystemConfigurationCategoryDto build() {
5354
@Size(max = FieldConstraints.CHARACTER_LIMIT_TEXT, message = Validations.textTooLong)
5455
private String caption;
5556

57+
/**
58+
* Default constructor.
59+
*/
60+
public SystemConfigurationCategoryDto() {
61+
// Default constructor
62+
}
63+
64+
/**
65+
* Constructor to initialize the fields.
66+
*
67+
* @param name the name of the system configuration category.
68+
* @param description the description of the system configuration category.
69+
* @param caption the caption of the system configuration category.
70+
*/
71+
public SystemConfigurationCategoryDto(String name, String description, String caption) {
72+
this.name = name;
73+
this.description = description;
74+
this.caption = caption;
75+
}
76+
5677
/**
5778
* Gets the name of the system configuration category.
5879
*

sormas-api/src/main/java/de/symeda/sormas/api/systemconfiguration/SystemConfigurationCategoryFacade.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
import de.symeda.sormas.api.BaseFacade;
2323

24+
/**
25+
* Facade interface for managing System Configuration Categories.
26+
* Provides methods to perform CRUD operations and retrieve specific categories.
27+
*/
2428
@Remote
2529
public interface SystemConfigurationCategoryFacade
2630
extends
@@ -29,8 +33,7 @@ public interface SystemConfigurationCategoryFacade
2933
/**
3034
* Get system configuration categories by their UUIDs.
3135
*
32-
* @param uuids
33-
* the list of UUIDs
36+
* @param uuids the list of UUIDs
3437
* @return the list of matching system configuration category DTOs
3538
*/
3639
List<SystemConfigurationCategoryDto> getByUuids(List<String> uuids);
@@ -50,22 +53,18 @@ public interface SystemConfigurationCategoryFacade
5053
SystemConfigurationCategoryReferenceDto getDefaultCategoryReferenceDto();
5154

5255
/**
53-
* Get a category dto by category name.
54-
*
55-
* @param name
56-
* category name
56+
* Get a category DTO by category name.
5757
*
58-
* @return the default system configuration category reference DTO
58+
* @param name the category name
59+
* @return the system configuration category DTO
5960
*/
6061
SystemConfigurationCategoryDto getCategoryDtoByName(String name);
6162

6263
/**
63-
* Get a category reference dto by category name.
64+
* Get a category reference DTO by category name.
6465
*
65-
* @param name
66-
* category name
67-
*
68-
* @return the default system configuration category reference DTO
66+
* @param name the category name
67+
* @return the system configuration category reference DTO
6968
*/
7069
SystemConfigurationCategoryReferenceDto getCategoryReferenceDtoByName(String name);
7170

sormas-api/src/main/java/de/symeda/sormas/api/systemconfiguration/SystemConfigurationValueBooleanProvider.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@
1818
import java.util.Map;
1919
import java.util.Set;
2020

21-
import javax.annotation.Nonnull;
22-
2321
/**
2422
* Provides boolean values for system configuration.
2523
*/
2624
public class SystemConfigurationValueBooleanProvider implements SystemConfigurationValueDataProvider {
2725

26+
private static final String KEY_V1 = "v1";
27+
private static final String OPTION_TRUE = "true";
28+
private static final String OPTION_FALSE = "false";
29+
2830
/**
2931
* Gets the keys for the boolean values.
3032
*
3133
* @return a set of keys.
3234
*/
3335
@Override
3436
public Set<String> getKeys() {
35-
return Set.of("v1");
37+
return Set.of(KEY_V1);
3638
}
3739

3840
/**
@@ -42,7 +44,7 @@ public Set<String> getKeys() {
4244
*/
4345
@Override
4446
public Map<String, String> getOptions() {
45-
return Map.of("v1", "true", "v2", "false");
47+
return Map.of(KEY_V1, OPTION_TRUE, "v2", OPTION_FALSE);
4648
}
4749

4850
/**
@@ -54,9 +56,11 @@ public Map<String, String> getOptions() {
5456
* the DTO to apply the values to.
5557
*/
5658
@Override
57-
public void applyValues(@Nonnull final Map<String, String> values, @Nonnull final SystemConfigurationValueDto dto) {
58-
59-
if (values.isEmpty()) {
59+
public void applyValues(final Map<String, String> values, final SystemConfigurationValueDto dto) {
60+
if (null == dto) {
61+
return;
62+
}
63+
if (null == values || values.isEmpty()) {
6064
return;
6165
}
6266
values.values().stream().findFirst().ifPresent(dto::setValue);
@@ -70,8 +74,11 @@ public void applyValues(@Nonnull final Map<String, String> values, @Nonnull fina
7074
* @return a map of the values.
7175
*/
7276
@Override
73-
public Map<String, String> getMappedValues(@Nonnull final SystemConfigurationValueDto dto) {
74-
return Map.of("v1", dto.getValue());
77+
public Map<String, String> getMappedValues(final SystemConfigurationValueDto dto) {
78+
if (null == dto) {
79+
return Map.of();
80+
}
81+
return Map.of(KEY_V1, dto.getValue());
7582
}
7683

7784
}

sormas-api/src/main/java/de/symeda/sormas/api/systemconfiguration/SystemConfigurationValueDiseasesProvider.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import java.util.stream.Collectors;
2323
import java.util.stream.Stream;
2424

25-
import javax.annotation.Nonnull;
26-
2725
import de.symeda.sormas.api.Disease;
2826

2927
/**
@@ -67,9 +65,9 @@ public Map<String, String> getOptions() {
6765
* the DTO to apply the values to.
6866
*/
6967
@Override
70-
public void applyValues(@Nonnull final Map<String, String> values, @Nonnull final SystemConfigurationValueDto dto) {
68+
public void applyValues(final Map<String, String> values, final SystemConfigurationValueDto dto) {
7169

72-
if (values.isEmpty()) {
70+
if (null == values || values.isEmpty()) {
7371
return;
7472
}
7573
final String pipeSeparatedValues = values.keySet().stream().collect(Collectors.joining("|"));
@@ -85,9 +83,9 @@ public void applyValues(@Nonnull final Map<String, String> values, @Nonnull fina
8583
* @return a map of disease names with short string.
8684
*/
8785
@Override
88-
public Map<String, String> getMappedValues(@Nonnull final SystemConfigurationValueDto dto) {
86+
public Map<String, String> getMappedValues(final SystemConfigurationValueDto dto) {
8987

90-
if (null == dto.getValue() || dto.getValue().isBlank()) {
88+
if (null == dto || null == dto.getValue() || dto.getValue().isBlank()) {
9189
return Collections.emptyMap();
9290
}
9391

sormas-api/src/main/java/de/symeda/sormas/api/systemconfiguration/SystemConfigurationValueDto.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
import de.symeda.sormas.api.utils.DataHelper;
2424
import de.symeda.sormas.api.utils.FieldConstraints;
2525

26+
/**
27+
* Data Transfer Object for System Configuration Value.
28+
* This class represents a value in the system configuration.
29+
*/
2630
public class SystemConfigurationValueDto extends EntityDto {
2731

2832
private static final long serialVersionUID = 1L;
@@ -65,6 +69,44 @@ public static SystemConfigurationValueDto build() {
6569

6670
private String validationMessage;
6771

72+
/**
73+
* Default constructor.
74+
*/
75+
public SystemConfigurationValueDto() {
76+
// Default constructor
77+
}
78+
79+
/**
80+
* Constructor to initialize the fields.
81+
*
82+
* @param value the value of the system configuration.
83+
* @param key the key of the system configuration.
84+
* @param category the category reference of the system configuration.
85+
* @param optional whether the configuration is optional.
86+
* @param pattern the pattern of the system configuration.
87+
* @param encrypt whether the configuration is encrypted.
88+
* @param dataProvider the data provider for the system configuration.
89+
* @param validationMessage the validation message for the system configuration.
90+
*/
91+
public SystemConfigurationValueDto(
92+
String value,
93+
String key,
94+
SystemConfigurationCategoryReferenceDto category,
95+
Boolean optional,
96+
String pattern,
97+
Boolean encrypt,
98+
SystemConfigurationValueDataProvider dataProvider,
99+
String validationMessage) {
100+
this.value = value;
101+
this.key = key;
102+
this.category = category;
103+
this.optional = optional;
104+
this.pattern = pattern;
105+
this.encrypt = encrypt;
106+
this.dataProvider = dataProvider;
107+
this.validationMessage = validationMessage;
108+
}
109+
68110
public String getValue() {
69111
return value;
70112
}

sormas-api/src/main/java/de/symeda/sormas/api/systemconfiguration/SystemConfigurationValueFacade.java

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
66
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
7+
* (at any later version.
88
* This program is distributed in the hope that it will be useful,
99
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1010
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -29,30 +29,44 @@
2929
*/
3030
@Remote
3131
public interface SystemConfigurationValueFacade
32-
extends
33-
BaseFacade<SystemConfigurationValueDto, SystemConfigurationValueIndexDto, SystemConfigurationValueReferenceDto, SystemConfigurationValueCriteria>,
34-
Serializable {
35-
36-
List<SystemConfigurationValueDto> getByUuids(List<String> uuids);
37-
38-
List<String> getAllUuids();
39-
40-
/**
41-
* Retrieves a configuration value associated with the given key.
42-
* The implementors should assure that propper caching is used.
43-
*
44-
* @param key
45-
* The key of the configuration value to retrieve.
46-
* @return An {@link Optional} containing the value if found, or an empty {@link Optional} if not found.
47-
*/
48-
public String getValue(String key);
49-
50-
51-
public boolean exists(String key);
52-
53-
/**
54-
* Clears the caches and reloads the system configuration values from the database.
55-
* s
56-
*/
57-
void loadData();
32+
extends
33+
BaseFacade<SystemConfigurationValueDto, SystemConfigurationValueIndexDto, SystemConfigurationValueReferenceDto, SystemConfigurationValueCriteria>,
34+
Serializable {
35+
36+
/**
37+
* Retrieves system configuration values by their UUIDs.
38+
*
39+
* @param uuids the list of UUIDs
40+
* @return the list of matching system configuration value DTOs
41+
*/
42+
List<SystemConfigurationValueDto> getByUuids(List<String> uuids);
43+
44+
/**
45+
* Retrieves all UUIDs of system configuration values.
46+
*
47+
* @return the list of all UUIDs
48+
*/
49+
List<String> getAllUuids();
50+
51+
/**
52+
* Retrieves a configuration value associated with the given key.
53+
* The implementors should assure that proper caching is used.
54+
*
55+
* @param key The key of the configuration value to retrieve.
56+
* @return the value of the configuration.
57+
*/
58+
String getValue(String key);
59+
60+
/**
61+
* Checks if a configuration value exists for the given key.
62+
*
63+
* @param key The key to check.
64+
* @return true if the configuration value exists, false otherwise.
65+
*/
66+
boolean exists(String key);
67+
68+
/**
69+
* Clears the caches and reloads the system configuration values from the database.
70+
*/
71+
void loadData();
5872
}

0 commit comments

Comments
 (0)