Skip to content

Commit

Permalink
#13204 RSV disease variants - fix values without disease
Browse files Browse the repository at this point in the history
  • Loading branch information
Levente Gal committed Dec 19, 2024
1 parent 0bf7d5c commit 3bc290d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,7 +42,6 @@ public CustomizableEnumConverter(Class<T> enumClass) {
this.enumClass = enumClass;
}


public String convertToDatabaseColumn(T enumValue) {
return enumValue != null ? enumValue.getValue() : null;
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public void loadData() {
String value = customizableEnumValue.getValue();
Set<Disease> diseases = customizableEnumValue.getDiseases();

if (diseases == null){
if (diseases == null) {
diseases = Collections.singleton(null);
}
for (Disease disease : diseases) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3bc290d

Please sign in to comment.