------------------------------------------------------------ revno: 20698 committer: Lars Helge Overland <larshe...@gmail.com> branch nick: dhis2 timestamp: Wed 2015-10-14 13:29:47 +0200 message: System settings, more caching modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/Setting.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultTranslateSystemSettingManager.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/Setting.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/Setting.java 2015-10-13 09:22:30 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/Setting.java 2015-10-14 11:29:47 +0000 @@ -108,7 +108,8 @@ DATE_FORMAT( "keyDateFormat", "yyyy-MM-dd", String.class ), APP_FOLDER_PATH( "appFolderPath" ), APP_BASE_URL( "appBaseUrl" ), - APP_STORE_URL( "appStoreUrl", "http://www.dhis2.org/appstore", String.class ); + APP_STORE_URL( "appStoreUrl", "http://www.dhis2.org/appstore", String.class ), + STYLE( "currentStyle", "light_blue", String.class ); private final String name; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2015-10-14 09:35:22 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2015-10-14 11:29:47 +0000 @@ -130,8 +130,6 @@ Serializable getSystemSetting( String name ); - Serializable getSystemSetting( String name, Serializable defaultValue ); - Serializable getSystemSetting( Setting setting ); Serializable getSystemSetting( Setting setting, Serializable defaultValue ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java 2015-09-10 16:35:55 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java 2015-10-14 11:29:47 +0000 @@ -35,15 +35,11 @@ /** * @author Lars Helge Overland - * @version $Id$ */ public class DefaultStyleManager implements StyleManager { - private static final String SETTING_NAME_STYLE = "currentStyle"; - private static final String SEPARATOR = "/"; - private static final String SYSTEM_SEPARATOR = File.separator; // ------------------------------------------------------------------------- @@ -64,13 +60,6 @@ this.userSettingService = userSettingService; } - private String defaultStyle; - - public void setDefaultStyle( String defaultStyle ) - { - this.defaultStyle = defaultStyle; - } - /** * Map for styles. The key refers to the user setting key and the value refers * to the path to the CSS file of the style relative to /dhis-web-commons/. @@ -89,19 +78,19 @@ @Override public void setSystemStyle( String style ) { - systemSettingManager.saveSystemSetting( SETTING_NAME_STYLE, style ); + systemSettingManager.saveSystemSetting( Setting.STYLE.getName(), style ); } @Override public void setUserStyle( String style ) { - userSettingService.saveUserSetting( SETTING_NAME_STYLE, style ); + userSettingService.saveUserSetting( Setting.STYLE.getName(), style ); } @Override public String getCurrentStyle() { - String style = (String) userSettingService.getUserSetting( SETTING_NAME_STYLE ); + String style = (String) userSettingService.getUserSetting( Setting.STYLE.getName() ); if ( style != null ) { @@ -114,7 +103,7 @@ @Override public String getSystemStyle() { - return (String) systemSettingManager.getSystemSetting( SETTING_NAME_STYLE, styles.get( defaultStyle ) ); + return (String) systemSettingManager.getSystemSetting( Setting.STYLE ); } @Override === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2015-10-14 09:35:22 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java 2015-10-14 11:29:47 +0000 @@ -57,7 +57,7 @@ /** * Cache for system settings. Does not accept nulls. */ - private static Cache<String, Serializable> SETTING_CACHE = CacheBuilder.newBuilder() + private static Cache<String, Optional<Serializable>> SETTING_CACHE = CacheBuilder.newBuilder() .expireAfterAccess( 15, TimeUnit.MINUTES ) .initialCapacity( 200 ) .maximumSize( 400 ) @@ -143,37 +143,31 @@ } @Override - public Serializable getSystemSetting( String name, Serializable defaultValue ) - { - SystemSetting setting = systemSettingStore.getByName( name ); - - return setting != null && setting.hasValue() ? setting.getValue() : defaultValue; - } - - @Override public Serializable getSystemSetting( Setting setting ) { - if ( setting.hasDefaultValue() ) - { - try - { - return SETTING_CACHE.get( setting.getName(), () -> getSystemSetting( setting.getName(), setting.getDefaultValue() ) ); - } - catch ( ExecutionException ignored ) - { - return null; - } - } - else - { - return getSystemSetting( setting.getName(), setting.getDefaultValue() ); - } + try + { + Optional<Serializable> value = SETTING_CACHE.get( setting.getName(), () -> getSystemSettingOptional( setting.getName(), setting.getDefaultValue() ) ); + + return value.orElse( null ); + } + catch ( ExecutionException ignored ) + { + return null; + } } @Override public Serializable getSystemSetting( Setting setting, Serializable defaultValue ) { - return getSystemSetting( setting.getName(), defaultValue ); + return getSystemSettingOptional( setting.getName(), defaultValue ).orElse( null ); + } + + private Optional<Serializable> getSystemSettingOptional( String name, Serializable defaultValue ) + { + SystemSetting setting = systemSettingStore.getByName( name ); + + return setting != null && setting.hasValue() ? Optional.of( setting.getValue() ) : Optional.ofNullable( defaultValue ); } @Override @@ -186,6 +180,7 @@ public Map<String, Serializable> getSystemSettingsAsMap() { Map<String, Serializable> settingsMap = new HashMap<>(); + Collection<SystemSetting> systemSettings = getAllSystemSettings(); for ( SystemSetting systemSetting : systemSettings ) === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultTranslateSystemSettingManager.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultTranslateSystemSettingManager.java 2015-10-06 18:24:42 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultTranslateSystemSettingManager.java 2015-10-14 11:29:47 +0000 @@ -31,6 +31,8 @@ import java.util.Hashtable; import java.util.Map; +import org.hisp.dhis.util.ObjectUtils; + /** * @author James Chang */ @@ -70,10 +72,14 @@ { Map<String, String> translations = new Hashtable<>(); - translations.put( Setting.APPLICATION_TITLE.getDefaultValue().toString(), systemSettingManager.getSystemSetting( Setting.APPLICATION_TITLE.getDefaultValue().toString() + localeStr, Setting.APPLICATION_TITLE.getDefaultValue().toString() ).toString() ); - translations.put( Setting.APPLICATION_INTRO.getDefaultValue().toString(), systemSettingManager.getSystemSetting( Setting.APPLICATION_INTRO.getDefaultValue().toString() + localeStr, "" ).toString() ); - translations.put( Setting.APPLICATION_NOTIFICATION.getDefaultValue().toString(), systemSettingManager.getSystemSetting( Setting.APPLICATION_NOTIFICATION.getDefaultValue().toString() + localeStr, "" ).toString() ); - translations.put( Setting.APPLICATION_FOOTER.getDefaultValue().toString(), systemSettingManager.getSystemSetting( Setting.APPLICATION_FOOTER.getDefaultValue().toString() + localeStr, "" ).toString() ); + translations.put( Setting.APPLICATION_TITLE.getDefaultValue().toString(), ObjectUtils.firstNonNull( + systemSettingManager.getSystemSetting( Setting.APPLICATION_TITLE.getDefaultValue().toString() + localeStr ), Setting.APPLICATION_TITLE.getDefaultValue().toString() ).toString() ); + translations.put( Setting.APPLICATION_INTRO.getDefaultValue().toString(), ObjectUtils.firstNonNull( + systemSettingManager.getSystemSetting( Setting.APPLICATION_INTRO.getDefaultValue().toString() + localeStr ), "" ).toString() ); + translations.put( Setting.APPLICATION_NOTIFICATION.getDefaultValue().toString(), ObjectUtils.firstNonNull( + systemSettingManager.getSystemSetting( Setting.APPLICATION_NOTIFICATION.getDefaultValue().toString() + localeStr ), "" ).toString() ); + translations.put( Setting.APPLICATION_FOOTER.getDefaultValue().toString(), ObjectUtils.firstNonNull( + systemSettingManager.getSystemSetting( Setting.APPLICATION_FOOTER.getDefaultValue().toString() + localeStr ), "" ).toString() ); return translations; } @@ -86,11 +92,11 @@ { String settingValue = ""; - String keyWithLocale = (String) systemSettingManager.getSystemSetting( keyName + localeStr, "" ); + String keyWithLocale = (String) ObjectUtils.firstNonNull( systemSettingManager.getSystemSetting( keyName + localeStr ), "" ); if ( keyWithLocale.isEmpty() ) { - settingValue = (String) systemSettingManager.getSystemSetting( keyName, defaultValue ); + settingValue = (String) ObjectUtils.firstNonNull( systemSettingManager.getSystemSetting( keyName ), defaultValue ); } else { === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2015-10-14 10:36:42 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2015-10-14 11:29:47 +0000 @@ -224,7 +224,7 @@ { UserSetting setting = userSettingStore.getUserSetting( user, name ); - return setting != null && setting.getValue() != null ? Optional.of( setting.getValue() ) : Optional.empty(); + return setting != null ? Optional.ofNullable( setting.getValue() ) : Optional.empty(); } @Override === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2015-10-13 22:07:31 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2015-10-14 11:29:47 +0000 @@ -1001,7 +1001,6 @@ <bean id="org.hisp.dhis.setting.StyleManager" class="org.hisp.dhis.setting.DefaultStyleManager"> <property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" /> <property name="userSettingService" ref="org.hisp.dhis.user.UserSettingService" /> - <property name="defaultStyle" value="light_blue" /> <property name="styles"> <map> <entry>
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp