← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12493: I18nLocale, added getI18nLocale(Locale) method

 

------------------------------------------------------------
revno: 12493
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-10-08 10:07:02 +0200
message:
  I18nLocale, added getI18nLocale(Locale) method
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nLocaleStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/i18n/locale/hibernate/I18nLocale.hbm.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/locale/ValidateLocaleAction.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-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java	2013-10-06 10:34:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nLocaleService.java	2013-10-08 08:07:02 +0000
@@ -39,7 +39,6 @@
 import javax.annotation.PostConstruct;
 
 import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.common.comparator.LocaleNameComparator;
@@ -55,9 +54,9 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private GenericIdentifiableObjectStore<I18nLocale> localeStore;
+    private I18nLocaleStore localeStore;
 
-    public void setLocaleStore( GenericIdentifiableObjectStore<I18nLocale> localeStore )
+    public void setLocaleStore( I18nLocaleStore localeStore )
     {
         this.localeStore = localeStore;
     }
@@ -137,7 +136,7 @@
         
         return true;
     }
-    
+        
     public void saveI18nLocale( I18nLocale locale )
     {
         localeStore.save( locale );
@@ -153,6 +152,11 @@
         return localeStore.getByUid( uid );
     }
     
+    public I18nLocale getI18nLocale( Locale locale )
+    {
+        return localeStore.getI18nLocaleByLocale( locale );
+    }
+    
     public void deleteI18nLocale( I18nLocale locale )
     {
         localeStore.delete( locale );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleService.java	2013-10-06 07:45:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleService.java	2013-10-08 08:07:02 +0000
@@ -54,6 +54,8 @@
     
     I18nLocale getI18nLocaleByUid( String uid );
     
+    I18nLocale getI18nLocale( Locale locale );
+    
     void deleteI18nLocale( I18nLocale locale );
     
     int getI18nLocaleCount();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleStore.java	2013-10-01 16:44:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nLocaleStore.java	2013-10-08 08:07:02 +0000
@@ -27,11 +27,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Locale;
+
 import org.hisp.dhis.common.GenericNameableObjectStore;
 import org.hisp.dhis.i18n.locale.I18nLocale;
 
 public interface I18nLocaleStore
     extends GenericNameableObjectStore<I18nLocale>
 {
-    I18nLocale getI18nLocaleByLocale( String language, String country );
+    I18nLocale getI18nLocaleByLocale( Locale locale );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nLocaleStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nLocaleStore.java	2013-08-13 09:24:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nLocaleStore.java	2013-10-08 08:07:02 +0000
@@ -1,5 +1,34 @@
 package org.hisp.dhis.i18n.hibernate;
 
+/*
+ * Copyright (c) 2004-2009, 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.Locale;
+
 import org.hibernate.criterion.Restrictions;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.i18n.I18nLocaleStore;
@@ -10,10 +39,9 @@
     implements I18nLocaleStore
 {
     @Override
-    public I18nLocale getI18nLocaleByLocale( String language, String country )
+    public I18nLocale getI18nLocaleByLocale( Locale locale )
     {
-        return (I18nLocale) getCriteria( Restrictions.eq( "language", language ), Restrictions.eq( "country", country ) )
-            .uniqueResult();
+        return (I18nLocale) getCriteria( Restrictions.eq( "locale", locale.toString() ) ).uniqueResult();
     }
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/i18n/locale/hibernate/I18nLocale.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/i18n/locale/hibernate/I18nLocale.hbm.xml	2013-10-06 10:34:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/i18n/locale/hibernate/I18nLocale.hbm.xml	2013-10-08 08:07:02 +0000
@@ -15,7 +15,7 @@
 
     <property name="name" column="name" length="250" not-null="true" unique="true" />
 
-    <property name="locale" column="locale" length="15" not-null="true" />
+    <property name="locale" column="locale" length="15" not-null="true" unique="true" />
 
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/locale/ValidateLocaleAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/locale/ValidateLocaleAction.java	2013-10-01 16:44:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/locale/ValidateLocaleAction.java	2013-10-08 08:07:02 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Locale;
+
 import org.hisp.dhis.i18n.I18nLocaleService;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -46,13 +48,23 @@
     private I18nLocaleService localeService;
 
     // -------------------------------------------------------------------------
-    // I18n
-    // -------------------------------------------------------------------------
-
-    // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
 
+    private String language;
+
+    public void setLanguage( String language )
+    {
+        this.language = language;
+    }
+
+    private String country;
+
+    public void setCountry( String country )
+    {
+        this.country = country;
+    }
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -70,6 +82,8 @@
 
     public String execute()
     {
+        localeService.getI18nLocale( new Locale( language, country ) );
+        
         return SUCCESS;
     }
 }