use of de.symeda.sormas.api.Language in project SORMAS-Project by hzi-braunschweig.
the class CustomizableEnumValueDao method getEnumValues.
@SuppressWarnings("unchecked")
public <T extends CustomizableEnum> List<T> getEnumValues(CustomizableEnumType type, Disease disease) {
if (customizableEnumsByType.isEmpty()) {
loadData();
}
Language language = I18nProperties.getUserLanguage();
Class<T> enumClass = (Class<T>) type.getEnumClass();
initCaches(type, language);
// Always add values for no disease because they are relevant in all cases
if (!enumValuesByDisease.get(enumClass).containsKey(null)) {
addValuesByDisease(type, enumClass, null);
}
if (!enumValuesByDisease.get(enumClass).containsKey(disease)) {
addValuesByDisease(type, enumClass, disease);
}
List<T> enumValues = new ArrayList<>();
enumValuesByLanguage.get(enumClass).get(language).forEach((value, caption) -> {
T enumValue;
try {
enumValue = enumClass.newInstance();
enumValue.setValue(value);
enumValue.setCaption(caption);
enumValue.setProperties(enumProperties.get(type).get(value));
enumValues.add(enumValue);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
});
return enumValues.stream().filter(e -> enumValuesByDisease.get(enumClass).get(disease).contains(e.getValue()) || enumValuesByDisease.get(enumClass).get(null).contains(e.getValue())).collect(Collectors.toList());
}
Aggregations