From 3bc290dd9e587e287f971134748d4348e9c34b46 Mon Sep 17 00:00:00 2001 From: Levente Gal Date: Thu, 19 Dec 2024 10:19:27 +0200 Subject: [PATCH] #13204 RSV disease variants - fix values without disease --- .../customizableenum/CustomizableEnumConverter.java | 10 +++++++--- .../customizableenum/CustomizableEnumFacadeEjb.java | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumConverter.java b/sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumConverter.java index 3cd1d2238cb..3a7ecfd3f88 100644 --- a/sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumConverter.java +++ b/sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumConverter.java @@ -18,9 +18,10 @@ import javax.naming.InitialContext; import javax.naming.NamingException; -import de.symeda.sormas.api.Disease; import org.apache.commons.lang3.StringUtils; +import de.symeda.sormas.api.Disease; + /** * JPA Converter that converts a JSON String stored in the database to an instance of {@link CustomizableEnum} and vice versa. * Uses the cache built in {@link CustomizableEnumFacadeEjb} to retrieve the internationalized caption based on the user's language @@ -41,7 +42,6 @@ public CustomizableEnumConverter(Class enumClass) { this.enumClass = enumClass; } - public String convertToDatabaseColumn(T enumValue) { return enumValue != null ? enumValue.getValue() : null; } @@ -61,7 +61,11 @@ public T convertToEntityAttribute(Disease disease, String enumString) { throw new RuntimeException("No CustomizableEnumType for given enumClass " + enumClass + "found"); } - return customizableEnumFacade.getEnumValue(CustomizableEnumType.getByEnumClass(enumClass), disease, enumString); + T enumValue = customizableEnumFacade.getEnumValue(enumType, disease, enumString); + if (enumValue == null && disease != null) { + enumValue = customizableEnumFacade.getEnumValue(enumType, null, enumString); + } + return enumValue; } catch (NamingException e) { throw new RuntimeException(e); } diff --git a/sormas-backend/src/main/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjb.java b/sormas-backend/src/main/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjb.java index 8d9c529393f..9de113916a6 100644 --- a/sormas-backend/src/main/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjb.java +++ b/sormas-backend/src/main/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjb.java @@ -446,7 +446,7 @@ public void loadData() { String value = customizableEnumValue.getValue(); Set diseases = customizableEnumValue.getDiseases(); - if (diseases == null){ + if (diseases == null) { diseases = Collections.singleton(null); } for (Disease disease : diseases) { @@ -478,7 +478,9 @@ public void loadData() { } private CustomizableEnumCacheInfo getEnumInfo(CustomizableEnumType type, Disease disease, String value) { - return enumInfo.get(type).getOrDefault(disease, Collections.emptyMap()).get(value); + return enumInfo.get(type) + .getOrDefault(disease, Collections.emptyMap()) + .getOrDefault(value, disease != null ? getEnumInfo(type, null, value) : null); } public CustomizableEnumValueDto toDto(CustomizableEnumValue source) {