Search in sources :

Example 1 with InvalidCustomizationException

use of de.symeda.sormas.api.utils.InvalidCustomizationException in project SORMAS-Project by hzi-braunschweig.

the class CustomizableEnumFacadeEjb method loadData.

@PostConstruct
@Override
public void loadData() {
    enumValueEntities.clear();
    enumValues.clear();
    enumValuesByLanguage.clear();
    enumValuesByDisease.clear();
    enumProperties.clear();
    for (CustomizableEnumType enumType : CustomizableEnumType.values()) {
        enumValueEntities.putIfAbsent(enumType, new ArrayList<>());
        enumValues.putIfAbsent(enumType, new ArrayList<>());
    }
    // Build list of customizable enums mapped by their enum type; other caches are built on-demand
    for (CustomizableEnumValue customizableEnumValue : service.getAll()) {
        CustomizableEnumType enumType = customizableEnumValue.getDataType();
        enumValueEntities.get(enumType).add(customizableEnumValue);
        String value = customizableEnumValue.getValue();
        if (enumValues.get(enumType).contains(value)) {
            throw new InvalidCustomizationException("Enum value " + value + " for customizable enum type " + enumType.toString() + " is not unique");
        }
        enumValues.get(enumType).add(value);
        enumProperties.putIfAbsent(enumType, new HashMap<>());
        enumProperties.get(enumType).putIfAbsent(customizableEnumValue.getValue(), customizableEnumValue.getProperties());
    }
    for (CustomizableEnumType enumType : CustomizableEnumType.values()) {
        Class<? extends CustomizableEnum> enumClass = enumType.getEnumClass();
        // access to contains has to be thread-safe
        enumValuesByLanguage.putIfAbsent(enumClass, new ConcurrentHashMap<>());
        enumValuesByDisease.putIfAbsent(enumClass, new ConcurrentHashMap<>());
        // Always add values for no disease because they are relevant in all cases
        fillDiseaseCache(enumType, enumClass, Optional.empty());
    }
}
Also used : CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) InvalidCustomizationException(de.symeda.sormas.api.utils.InvalidCustomizationException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

CustomizableEnumType (de.symeda.sormas.api.customizableenum.CustomizableEnumType)1 InvalidCustomizationException (de.symeda.sormas.api.utils.InvalidCustomizationException)1 PostConstruct (javax.annotation.PostConstruct)1