← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1606: User settings behaves weird

 

------------------------------------------------------------
revno: 1606
committer: Tran Thanh Tri <Tran Thanh Tri@compaq>
branch nick: trunk
timestamp: Wed 2010-03-10 16:10:48 +0700
message:
  User settings behaves weird
added:
  dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/locale/DatabaseLocaleManager.java
modified:
  dhis-2/dhis-i18n/dhis-i18n-db/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.
=== added file 'dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/locale/DatabaseLocaleManager.java'
--- dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/locale/DatabaseLocaleManager.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/locale/DatabaseLocaleManager.java	2010-03-10 09:10:48 +0000
@@ -0,0 +1,133 @@
+package org.hisp.dhis.i18n.locale;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.hisp.dhis.user.NoCurrentUserException;
+import org.hisp.dhis.user.UserSettingService;
+
+/**
+ * @author Tran Thanh Tri
+ * @version $Id
+ */
+public class DatabaseLocaleManager
+    implements LocaleManager
+{
+
+    private String userSettingKey;
+
+    public void setUserSettingKey( String userSettingKey )
+    {
+        this.userSettingKey = userSettingKey;
+    }
+
+    private Locale defaultLocale;
+
+    public void setDefaultLocale( Locale defaultLocale )
+    {
+        this.defaultLocale = defaultLocale;
+    }
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private UserSettingService userSettingService;
+
+    public void setUserSettingService( UserSettingService userSettingService )
+    {
+        this.userSettingService = userSettingService;
+    }
+
+    // -------------------------------------------------------------------------
+    // LocaleManager implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public Locale getCurrentLocale()
+    {
+        Locale locale = getUserSelectedDBLocale();
+
+        if ( locale != null )
+        {
+            return locale;
+        }
+
+        if ( defaultLocale != null )
+        {
+            return defaultLocale;
+        }
+
+        return DHIS_STANDARD_LOCALE;
+    }
+
+    @Override
+    public void setCurrentLocale( Locale locale )
+    {
+        try
+        {
+            userSettingService.saveUserSetting( userSettingKey, locale );
+        }
+        catch ( NoCurrentUserException e )
+        {
+            // Just ignore for now. No change compared to previous behaviour.
+        }
+    }
+
+    @Override
+    public List<Locale> getLocalesOrderedByPriority()
+    {
+        List<Locale> locales = new ArrayList<Locale>();
+
+        Locale userLocale = getUserSelectedDBLocale();
+
+        if ( userLocale != null )
+        {
+            locales.add( userLocale );
+        }
+
+        locales.add( DHIS_STANDARD_LOCALE );
+
+        return locales;
+    }
+
+    @Override
+    public Locale getFallbackLocale()
+    {
+        return DHIS_STANDARD_LOCALE;
+    }
+
+    private Locale getUserSelectedDBLocale()
+    {
+        return (Locale) userSettingService.getUserSetting( this.userSettingKey, null );
+    }
+
+}

=== modified file 'dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml	2009-11-12 17:59:58 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml	2010-03-10 09:10:48 +0000
@@ -1,209 +1,204 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans";
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-       xsi:schemaLocation="
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+	xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd";>
 
-  <bean id="org.hisp.dhis.i18n.locale.LocaleManagerDb" class="org.hisp.dhis.i18n.locale.SessionLocaleManager">
-    <property name="systemLocale" value="en_GB"/>
-  </bean>
-
-  <!-- I18n object definitions -->
-
-  <bean id="I18nDataElement"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="DataElement"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-        <value>shortName</value>
-        <value>description</value>
-      </list>
-    </property>
-  </bean>
-
-  <bean id="I18nDataElementGroup"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="DataElementGroup"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-      </list>
-    </property>
-  </bean>
-  
-   <bean id="I18nDataElementGroupSet"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="DataElementGroupSet"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-      </list>
-    </property>
-  </bean>
-
-
-  <bean id="I18nIndicator"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="Indicator"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-        <value>shortName</value>
-        <value>description</value>
-        <value>numeratorDescription</value>
-        <value>denominatorDescription</value>
-      </list>
-    </property>
-  </bean>
-
-  <bean id="I18nIndicatorType"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="IndicatorType"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-      </list>
-    </property>
-  </bean>
-
-  <bean id="I18nIndicatorGroup"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="IndicatorGroup"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-      </list>
-    </property>
-  </bean>
-  
-   <bean id="I18nIndicatorGroupSet"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="IndicatorGroupSet"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-      </list>
-    </property>
-  </bean>
-  
-  <bean id="I18nDataDictionary"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="DataDictionary"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-        <value>description</value>
-        <value>region</value>
-      </list>
-    </property>
-  </bean>
-
-  <bean id="I18nOrganisationUnit"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="OrganisationUnit"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-        <value>shortName</value>
-        <value>comment</value>
-      </list>
-    </property>
-  </bean>
-
-  <bean id="I18nOrganisationUnitGroup"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="OrganisationUnitGroup"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-      </list>
-    </property>
-  </bean>
-
-  <bean id="I18nOrganisationUnitGroupSet"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="OrganisationUnitGroupSet"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-        <value>description</value>
-      </list>
-    </property>
-  </bean>
-
-  <bean id="I18nDataSet"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="DataSet"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-      </list>
-    </property>
-  </bean>
-
-  <bean id="I18nDataElementCategory"
-    class="org.hisp.dhis.i18n.I18nObject">
-    <property name="className" value="DataElementCategory"/>
-    <property name="propertyNames">
-      <list>
-        <value>name</value>
-      </list>
-    </property>
-  </bean>
-  
-  <!-- I18nService -->
-  
-  <bean id="org.hisp.dhis.i18n.I18nService"
-        class="org.hisp.dhis.i18n.DefaultI18nService">
-    <property name="localeManager">
-      <ref bean="org.hisp.dhis.i18n.locale.LocaleManagerDb"/>
-    </property>
-    <property name="translationService">
-      <ref bean="org.hisp.dhis.translation.TranslationService"/>
-    </property>
-    <property name="objects">
-      <list>
-        <ref bean="I18nDataElement"/>
-        <ref bean="I18nDataElementGroup"/>
-        <ref bean="I18nDataElementGroupSet"/>
-        <ref bean="I18nDataDictionary"/>
-        <ref bean="I18nIndicator"/>
-        <ref bean="I18nIndicatorType"/>
-        <ref bean="I18nIndicatorGroup"/>
-        <ref bean="I18nIndicatorGroupSet"/>
-        <ref bean="I18nDataSet"/>
-        <ref bean="I18nOrganisationUnit"/>
-      </list>
-    </property>
-  </bean>
-  
-  <!-- Translation -->
-  
-  <bean id="org.hisp.dhis.translation.TranslationStore"
-    class="org.hisp.dhis.translation.hibernate.HibernateTranslationStore">
-    <property name="sessionFactory" ref="sessionFactory"/>
-  </bean>
-
-  <bean id="org.hisp.dhis.translation.TranslationService"
-    class="org.hisp.dhis.translation.impl.DefaultTranslationService">
-    <property name="translationStore"
-      ref="org.hisp.dhis.translation.TranslationStore"/>
-  </bean>
-  
-  <!-- I81n AOP definitions -->
-  <!--
-  <bean id="i18nObjectInterceptor"
-    class="org.hisp.dhis.i18n.interceptor.I18nObjectInterceptor">
-    <property name="i18nService"
-      ref="org.hisp.dhis.i18n.I18nService"/>  
-  </bean>
-  -->
-  <!--
-  <bean id="i18nTranslationInterceptor"
-    class="org.hisp.dhis.i18n.interceptor.I18nTranslationInterceptor">
-    <property name="i18nService"
-      ref="org.hisp.dhis.i18n.I18nService"/>
-  </bean>
-  -->
+	<bean id="org.hisp.dhis.i18n.locale.LocaleManagerSession" class="org.hisp.dhis.i18n.locale.SessionLocaleManager">
+		<property name="systemLocale" value="en_GB" />
+	</bean>
+
+	<bean id="org.hisp.dhis.i18n.locale.LocaleManagerDb" class="org.hisp.dhis.i18n.locale.DatabaseLocaleManager">
+		<property name="userSettingService">
+			<ref bean="org.hisp.dhis.user.UserSettingService" />
+		</property>
+		<property name="userSettingKey">
+			<value>currentLocaleDB</value>
+		</property>
+		<property name="defaultLocale">
+			<value>en_GB</value>
+		</property>
+	</bean>
+
+	<!-- I18n object definitions -->
+
+	<bean id="I18nDataElement" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="DataElement" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+				<value>shortName</value>
+				<value>description</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nDataElementGroup" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="DataElementGroup" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nDataElementGroupSet" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="DataElementGroupSet" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+			</list>
+		</property>
+	</bean>
+
+
+	<bean id="I18nIndicator" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="Indicator" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+				<value>shortName</value>
+				<value>description</value>
+				<value>numeratorDescription</value>
+				<value>denominatorDescription</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nIndicatorType" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="IndicatorType" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nIndicatorGroup" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="IndicatorGroup" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nIndicatorGroupSet" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="IndicatorGroupSet" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nDataDictionary" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="DataDictionary" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+				<value>description</value>
+				<value>region</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nOrganisationUnit" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="OrganisationUnit" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+				<value>shortName</value>
+				<value>comment</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nOrganisationUnitGroup" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="OrganisationUnitGroup" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nOrganisationUnitGroupSet" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="OrganisationUnitGroupSet" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+				<value>description</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nDataSet" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="DataSet" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+			</list>
+		</property>
+	</bean>
+
+	<bean id="I18nDataElementCategory" class="org.hisp.dhis.i18n.I18nObject">
+		<property name="className" value="DataElementCategory" />
+		<property name="propertyNames">
+			<list>
+				<value>name</value>
+			</list>
+		</property>
+	</bean>
+
+	<!-- I18nService -->
+
+	<bean id="org.hisp.dhis.i18n.I18nService" class="org.hisp.dhis.i18n.DefaultI18nService">
+		<property name="localeManager">
+			<ref bean="org.hisp.dhis.i18n.locale.LocaleManagerDb" />
+		</property>
+		<property name="translationService">
+			<ref bean="org.hisp.dhis.translation.TranslationService" />
+		</property>
+		<property name="objects">
+			<list>
+				<ref bean="I18nDataElement" />
+				<ref bean="I18nDataElementGroup" />
+				<ref bean="I18nDataElementGroupSet" />
+				<ref bean="I18nDataDictionary" />
+				<ref bean="I18nIndicator" />
+				<ref bean="I18nIndicatorType" />
+				<ref bean="I18nIndicatorGroup" />
+				<ref bean="I18nIndicatorGroupSet" />
+				<ref bean="I18nDataSet" />
+				<ref bean="I18nOrganisationUnit" />
+			</list>
+		</property>
+	</bean>
+
+	<!-- Translation -->
+
+	<bean id="org.hisp.dhis.translation.TranslationStore"
+		class="org.hisp.dhis.translation.hibernate.HibernateTranslationStore">
+		<property name="sessionFactory" ref="sessionFactory" />
+	</bean>
+
+	<bean id="org.hisp.dhis.translation.TranslationService"
+		class="org.hisp.dhis.translation.impl.DefaultTranslationService">
+		<property name="translationStore" ref="org.hisp.dhis.translation.TranslationStore" />
+	</bean>
+
+	<!-- I81n AOP definitions -->
+	<!--
+		<bean id="i18nObjectInterceptor"
+		class="org.hisp.dhis.i18n.interceptor.I18nObjectInterceptor">
+		<property name="i18nService" ref="org.hisp.dhis.i18n.I18nService"/>
+		</bean>
+	-->
+	<!--
+		<bean id="i18nTranslationInterceptor"
+		class="org.hisp.dhis.i18n.interceptor.I18nTranslationInterceptor">
+		<property name="i18nService" ref="org.hisp.dhis.i18n.I18nService"/>
+		</bean>
+	-->
 </beans>