use of org.hisp.dhis.system.util.SerializableOptional in project dhis2-core by dhis2.
the class DefaultUserSettingService method getUserSetting.
// -------------------------------------------------------------------------
// Private methods
// -------------------------------------------------------------------------
/**
* Returns a user setting optional. If the user settings does not have a
* value or default value, a corresponding system setting will be looked up.
*
* @param key the user setting key.
* @param user an optional {@link User}.
* @return an optional user setting value.
*/
private SerializableOptional getUserSetting(UserSettingKey key, Optional<User> user) {
if (key == null) {
return SerializableOptional.empty();
}
String username = user.isPresent() ? user.get().getUsername() : currentUserService.getCurrentUsername();
String cacheKey = getCacheKey(key.getName(), username);
SerializableOptional result = userSettingCache.get(cacheKey, c -> getUserSettingOptional(key, username));
if (!result.isPresent() && NAME_SETTING_KEY_MAP.containsKey(key.getName())) {
SettingKey settingKey = NAME_SETTING_KEY_MAP.get(key.getName());
return SerializableOptional.of(systemSettingManager.getSystemSetting(settingKey, settingKey.getClazz()));
} else {
return result;
}
}
Aggregations