← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20242: add method for checking if a certain class have any translations

 

------------------------------------------------------------
revno: 20242
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-09-21 11:35:41 +0700
message:
  add method for checking if a certain class have any translations
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.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/translation/TranslationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationService.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationService.java	2015-09-21 04:35:41 +0000
@@ -42,7 +42,7 @@
 
     /**
      * Adds a Translation.
-     * 
+     *
      * @param translation the Translation.
      */
     void addTranslation( Translation translation );
@@ -56,19 +56,17 @@
 
     /**
      * Updates a Translation.
-     * 
+     *
      * @param translation the Translation.
      */
     void updateTranslation( Translation translation );
 
     /**
      * Retrieves a Translation.
-     * 
-     *
      *
      * @param className the class name.
-     * @param locale the locale.
-     * @param property the property.
+     * @param locale    the locale.
+     * @param property  the property.
      * @param objectUid
      * @return a Translation.
      */
@@ -77,12 +75,10 @@
     /**
      * Retrieves a Translation. Only exact matches on the given
      * Locale will be returned.
-     * 
-     *
      *
      * @param className the class name.
-     * @param locale the locale.
-     * @param property the property.
+     * @param locale    the locale.
+     * @param property  the property.
      * @param objectUid
      * @return a Translation.
      */
@@ -90,10 +86,9 @@
 
     /**
      * Retrieves a Collection of Translations.
-     * 
      *
      * @param className the class name.
-     * @param locale the locale.
+     * @param locale    the locale.
      * @return a List of Translations.
      */
     List<Translation> getTranslations( String className, Locale locale, String objectUid );
@@ -101,11 +96,9 @@
     /**
      * Retrieves a Collection of Translations. Only exact matches on the given
      * Locale will be returned.
-     * 
-     *
      *
      * @param className the class name.
-     * @param locale the locale.
+     * @param locale    the locale.
      * @param objectUid the id.
      * @return a List of Translations.
      */
@@ -113,16 +106,16 @@
 
     /**
      * Retrieves a List of Translations.
-     * 
+     *
      * @param className the class name.
-     * @param locale the locale.
+     * @param locale    the locale.
      * @return a List of Translations.
      */
     List<Translation> getTranslations( String className, Locale locale );
 
     /**
      * Retrieves a List of Translations.
-     * 
+     *
      * @param locale the locale.
      * @return a List of Translations.
      */
@@ -130,14 +123,14 @@
 
     /**
      * Retrieves a List of all Translations.
-     * 
+     *
      * @return a List of all Translations.
      */
     List<Translation> getAllTranslations();
 
     /**
      * Deletes a Translation.
-     * 
+     *
      * @param translation the Translation.
      */
     void deleteTranslation( Translation translation );
@@ -151,4 +144,6 @@
     void deleteTranslations( String className, String objectUid );
 
     void createOrUpdate( Translation translation );
+
+    boolean haveTranslations( String className );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java	2015-09-21 04:35:41 +0000
@@ -28,11 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+
 import java.util.List;
 import java.util.Locale;
 
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
-
 /**
  * @author Oyvind Brucker
  */
@@ -109,4 +109,6 @@
      * @param objectUid the id.
      */
     void deleteTranslations( String className, String objectUid );
+
+    boolean haveTranslations( String className );
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java	2015-09-21 04:35:41 +0000
@@ -28,13 +28,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.system.util.LocaleUtils;
+import org.springframework.transaction.annotation.Transactional;
+
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
 
-import org.hisp.dhis.system.util.LocaleUtils;
-import org.springframework.transaction.annotation.Transactional;
-
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -155,4 +155,10 @@
             deleteTranslation( translationNoFallback );
         }
     }
+
+    @Override
+    public boolean haveTranslations( String className )
+    {
+        return translationStore.haveTranslations( className );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java	2015-09-21 04:35:41 +0000
@@ -28,9 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.List;
-import java.util.Locale;
-
 import org.hibernate.Criteria;
 import org.hibernate.Query;
 import org.hibernate.Session;
@@ -40,6 +37,9 @@
 import org.hisp.dhis.translation.Translation;
 import org.hisp.dhis.translation.TranslationStore;
 
+import java.util.List;
+import java.util.Locale;
+
 /**
  * @author Oyvind Brucker
  */
@@ -176,4 +176,17 @@
             session.delete( object );
         }
     }
+
+    @Override
+    public boolean haveTranslations( String className )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( Translation.class );
+        criteria.add( Restrictions.eq( "className", className ) );
+
+        criteria.setCacheable( true );
+
+        return !criteria.list().isEmpty();
+    }
 }