← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12088: User settings, centralization

 

------------------------------------------------------------
revno: 12088
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-09-14 20:27:14 +0200
message:
  User settings, centralization
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/locale/LocaleManager.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java
  dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java
  dhis-2/dhis-services/dhis-service-i18n/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/LocaleUtils.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/SetGeneralSettingsAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java


--
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/i18n/locale/LocaleManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/locale/LocaleManager.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/locale/LocaleManager.java	2013-09-14 18:27:14 +0000
@@ -48,4 +48,6 @@
     List<Locale> getLocalesOrderedByPriority();
 
     Locale getFallbackLocale();
+    
+    List<Locale> getAvailableLocales();
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSetting.java	2013-09-14 18:27:14 +0000
@@ -54,6 +54,17 @@
 
     private Serializable value;
 
+    public UserSetting()
+    {
+    }
+    
+    public UserSetting( User user, String name, Serializable value )
+    {
+        this.user = user;
+        this.name = name;
+        this.value = value;
+    }
+    
     // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java	2013-09-06 15:53:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java	2013-09-14 18:27:14 +0000
@@ -50,6 +50,7 @@
     final String KEY_STYLE_DIRECTORY = "stylesheetDirectory";
     final String KEY_MESSAGE_EMAIL_NOTIFICATION = "keyMessageEmailNotification";
     final String KEY_MESSAGE_SMS_NOTIFICATION = "keyMessageSmsNotification";
+    final String KEY_UI_LOCALE = "currentLocale";
     final String KEY_DB_LOCALE = "keyLocaleUserSetting";
     final String KEY_GENERATE_REPORT_INTERFACE = "keyGenerateReportInterface";
     final String KEY_ANALYSIS_DISPLAY_PROPERTY = "keyAnalysisDisplayProperty";

=== modified file 'dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java'
--- dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java	2013-09-14 18:27:14 +0000
@@ -32,6 +32,8 @@
 import java.util.List;
 import java.util.Locale;
 
+import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager;
+import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManagerException;
 import org.hisp.dhis.user.UserSettingService;
 
 /**
@@ -42,13 +44,6 @@
 public class UserSettingLocaleManager
     implements LocaleManager
 {
-    private String userSettingKey;
-
-    public void setUserSettingKey( String userSettingKey )
-    {
-        this.userSettingKey = userSettingKey;
-    }
-
     private Locale defaultLocale;
 
     public void setDefaultLocale( Locale defaultLocale )
@@ -66,6 +61,13 @@
     {
         this.userSettingService = userSettingService;
     }
+    
+    private ResourceBundleManager resourceBundleManager;
+
+    public void setResourceBundleManager( ResourceBundleManager resourceBundleManager )
+    {
+        this.resourceBundleManager = resourceBundleManager;
+    }
 
     // -------------------------------------------------------------------------
     // LocaleManager implementation
@@ -90,7 +92,7 @@
 
     public void setCurrentLocale( Locale locale )
     {
-        userSettingService.saveUserSetting( userSettingKey, locale );
+        userSettingService.saveUserSetting( UserSettingService.KEY_UI_LOCALE, locale );
     }
 
     public List<Locale> getLocalesOrderedByPriority()
@@ -111,11 +113,23 @@
 
     private Locale getUserSelectedLocale()
     {
-        return (Locale) userSettingService.getUserSetting( userSettingKey, null );
+        return (Locale) userSettingService.getUserSetting( UserSettingService.KEY_UI_LOCALE, null );
     }
 
     public Locale getFallbackLocale()
     {
         return DHIS_STANDARD_LOCALE;
     }
+    
+    public List<Locale> getAvailableLocales()
+    {
+        try
+        {
+            return resourceBundleManager.getAvailableLocales();
+        }
+        catch ( ResourceBundleManagerException ex )
+        {
+            throw new RuntimeException( ex );
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-i18n/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-i18n/src/main/resources/META-INF/dhis/beans.xml	2013-07-02 15:58:13 +0000
+++ dhis-2/dhis-services/dhis-service-i18n/src/main/resources/META-INF/dhis/beans.xml	2013-09-14 18:27:14 +0000
@@ -4,7 +4,7 @@
 
   <bean id="org.hisp.dhis.i18n.locale.LocaleManager" class="org.hisp.dhis.i18n.locale.UserSettingLocaleManager">
     <property name="userSettingService" ref="org.hisp.dhis.user.UserSettingService" />
-    <property name="userSettingKey" value="currentLocale" />
+    <property name="resourceBundleManager" ref="org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager" />
     <property name="defaultLocale" value="en" />
   </bean>
 

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/LocaleUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/LocaleUtils.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/LocaleUtils.java	2013-09-14 18:27:14 +0000
@@ -38,12 +38,17 @@
     /**
      * Creates a Locale object based on the input String
      *
-     * @param localestr String to parse
+     * @param localeStr String to parse
      * @return A locale object or null if not valid
      */
-    public static Locale getLocale( String localestr ) 
+    public static Locale getLocale( String localeStr ) 
     {
-        String[] parts = localestr.split( "_" );
+        if ( localeStr == null )
+        {
+            return null;
+        }
+        
+        String[] parts = localeStr.split( "_" );
 
         Locale thisLocale;
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java	2013-09-14 17:39:13 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java	2013-09-14 18:27:14 +0000
@@ -34,14 +34,12 @@
 import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_EMAIL_NOTIFICATION;
 import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 import java.util.SortedMap;
 
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.i18n.locale.LocaleManager;
-import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager;
 import org.hisp.dhis.setting.StyleManager;
 import org.hisp.dhis.user.UserSettingService;
 
@@ -57,13 +55,6 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private ResourceBundleManager resourceBundleManager;
-
-    public void setResourceBundleManager( ResourceBundleManager resourceBundleManager )
-    {
-        this.resourceBundleManager = resourceBundleManager;
-    }
-
     private I18nService i18nService;
 
     public void setI18nService( I18nService i18nService )
@@ -177,15 +168,15 @@
         // Get available UI locales
         // ---------------------------------------------------------------------
 
-        availableLocales = new ArrayList<Locale>( resourceBundleManager.getAvailableLocales() );
+        availableLocales = localeManager.getAvailableLocales();
 
         currentLocale = localeManager.getCurrentLocale();
-
+                
         // ---------------------------------------------------------------------
         // Get available DB locales
         // ---------------------------------------------------------------------
 
-        availableLocalesDb = new ArrayList<Locale>( i18nService.getAvailableLocales() );
+        availableLocalesDb = i18nService.getAvailableLocales();
 
         currentLocaleDb = i18nService.getCurrentLocale();
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/SetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/SetGeneralSettingsAction.java	2013-09-06 15:53:07 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/SetGeneralSettingsAction.java	2013-09-14 18:27:14 +0000
@@ -28,14 +28,17 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.user.UserSettingService.*;
-
-import java.util.Locale;
+import static org.hisp.dhis.user.UserSettingService.KEY_ANALYSIS_DISPLAY_PROPERTY;
+import static org.hisp.dhis.user.UserSettingService.KEY_DB_LOCALE;
+import static org.hisp.dhis.user.UserSettingService.KEY_DISPLAY_OPTION_SET_AS_RADIO_BUTTON;
+import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_EMAIL_NOTIFICATION;
+import static org.hisp.dhis.user.UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION;
 
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.locale.LocaleManager;
 import org.hisp.dhis.setting.StyleManager;
+import org.hisp.dhis.system.util.LocaleUtils;
 import org.hisp.dhis.user.UserSettingService;
 
 import com.opensymphony.xwork2.Action;
@@ -146,10 +149,9 @@
     public String execute()
         throws Exception
     {
-        localeManager.setCurrentLocale( getRespectiveLocale( currentLocale ) );
+        localeManager.setCurrentLocale( LocaleUtils.getLocale( StringUtils.trimToNull( currentLocale ) ) );
 
-        userSettingService.saveUserSetting( KEY_DB_LOCALE,
-            getRespectiveLocale( StringUtils.trimToNull( currentLocaleDb ) ) );
+        userSettingService.saveUserSetting( KEY_DB_LOCALE, LocaleUtils.getLocale( StringUtils.trimToNull( currentLocaleDb ) ) );
 
         styleManager.setUserStyle( currentStyle );
 
@@ -165,38 +167,4 @@
 
         return SUCCESS;
     }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private Locale getRespectiveLocale( String locale )
-    {
-        if ( locale == null )
-        {
-            return null;
-        }
-
-        String[] tokens = locale.split( "_" );
-        Locale newLocale = null;
-
-        switch ( tokens.length )
-        {
-        case 1:
-            newLocale = new Locale( tokens[0] );
-            break;
-
-        case 2:
-            newLocale = new Locale( tokens[0], tokens[1] );
-            break;
-
-        case 3:
-            newLocale = new Locale( tokens[0], tokens[1], tokens[2] );
-            break;
-
-        default:
-        }
-
-        return newLocale;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2013-09-03 18:28:38 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2013-09-14 18:27:14 +0000
@@ -580,7 +580,6 @@
   <bean id="org.hisp.dhis.settings.user.action.GetGeneralSettingsAction"
     class="org.hisp.dhis.settings.user.action.GetGeneralSettingsAction"
     scope="prototype">
-    <property name="resourceBundleManager" ref="org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager" />
     <property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
     <property name="localeManager" ref="org.hisp.dhis.i18n.locale.LocaleManager" />
     <property name="userSettingService" ref="org.hisp.dhis.user.UserSettingService" />

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java	2013-09-14 18:27:14 +0000
@@ -189,8 +189,7 @@
     public String execute()
     {
         systemSettingManager.saveSystemSetting( KEY_CACHE_STRATEGY, cacheStrategy );
-        systemSettingManager.saveSystemSetting( KEY_OMIT_INDICATORS_ZERO_NUMERATOR_DATAMART,
-            omitIndicatorsZeroNumeratorDataMart );
+        systemSettingManager.saveSystemSetting( KEY_OMIT_INDICATORS_ZERO_NUMERATOR_DATAMART, omitIndicatorsZeroNumeratorDataMart );
         systemSettingManager.saveSystemSetting( KEY_FACTOR_OF_DEVIATION, factorDeviation );
         systemSettingManager.saveSystemSetting( KEY_COMPLETENESS_OFFSET, completenessOffset );
         systemSettingManager.saveSystemSetting( KEY_PHONE_NUMBER_AREA_CODE, phoneNumberAreaCode );