Skip to content

Commit 5fb23e0

Browse files
feat[backend](updated filters and rules): set null to invalid module name rules
1 parent c6d098f commit 5fb23e0

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

backend/src/main/java/com/park/utmstack/domain/application_modules/UtmModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class UtmModule implements Serializable {
3232
@Column(name = "pretty_name")
3333
private String prettyName;
3434

35-
@Enumerated(EnumType.STRING)
35+
@Convert(converter = com.park.utmstack.domain.application_modules.enums.ModuleNameConverter.class)
3636
@Column(name = "module_name")
3737
private ModuleName moduleName;
3838

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.park.utmstack.domain.application_modules.enums;
2+
3+
import javax.persistence.AttributeConverter;
4+
import javax.persistence.Converter;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
@Converter(autoApply = true)
9+
public class ModuleNameConverter implements AttributeConverter<ModuleName, String> {
10+
private static final Logger log = LoggerFactory.getLogger(ModuleNameConverter.class);
11+
12+
@Override
13+
public String convertToDatabaseColumn(ModuleName attribute) {
14+
return attribute == null ? null : attribute.name();
15+
}
16+
17+
@Override
18+
public ModuleName convertToEntityAttribute(String dbData) {
19+
if (dbData == null) {
20+
return null;
21+
}
22+
try {
23+
return ModuleName.valueOf(dbData);
24+
} catch (IllegalArgumentException e) {
25+
log.warn("Unknown ModuleName in database: '{}'. Mapping to null to prevent crash. ---", dbData);
26+
return null;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)