[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1018: Fixed the database internationalisation. Applying translations through AOP.

revision-diff.txt (16.8 KB)

This was a tricky one. Previously a Hibernate PostLoadEventListener was used to inspect and translate objects provided by Hibernate. The event listener was previously registered with the HibernateConfigurationProvider with a MethodInvokingFactoryBean. We now use Spring’s LocalSessionFactoryBean, which makes this approach unusable since the LocalSessionFactoryBean gets initialized before the MethodInvokingFactoryBean gets to do its stuff (since there are no dependencies in that direction). We now have a standard AOP approach where get-methods returning i18n-enabled objects are matched and advised by the I18nTranslationInterceptor in dhis-i18n-db. I have also tested and made the code in I18nService and TranslationService more compact, although there was nothing wrong in there.

···

On Tue, Nov 10, 2009 at 12:47 PM, noreply@launchpad.net wrote:


revno: 1018

committer: Lars Helge Oeverland larshelge@gmail.com

branch nick: trunk

timestamp: Tue 2009-11-10 12:45:58 +0100

message:

Fixed the database internationalisation. Applying translations through AOP.

removed:

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java

added:

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java

modified:

dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java

dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml

dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml

dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java

dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/indicator/IndicatorServiceTest.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/organisationunit/OrganisationUnitService.java’

— dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2009-10-01 09:24:46 +0000

+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2009-11-10 11:45:58 +0000

@@ -217,6 +217,12 @@

  */

 int getNumberOfOrganisationalLevels();
  • /**

  • * Set parent of OrganisationUnit.
    
  • *
    
  • * @param organisationUnitId the identifier of the child OrganisationUnit.
    
  • * @param parentId the identifier of the parent OrganisationUnit.
    
  • */
    

    void updateOrganisationUnitParent( int organisationUnitId, int parentId );

    // -------------------------------------------------------------------------

=== modified file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-11-10 01:44:26 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-11-10 11:45:58 +0000

@@ -30,8 +30,8 @@

import static org.hisp.dhis.system.util.ReflectionUtils.getClassName;

import static org.hisp.dhis.system.util.ReflectionUtils.getId;

import static org.hisp.dhis.system.util.ReflectionUtils.getProperty;

+import static org.hisp.dhis.system.util.ReflectionUtils.isCollection;

import static org.hisp.dhis.system.util.ReflectionUtils.setProperty;

-import static org.hisp.dhis.system.util.ReflectionUtils.isCollection;

import java.util.ArrayList;

import java.util.Collection;

@@ -143,11 +143,16 @@

 private void internationaliseCollection( Collection<?> intObjects )

 {
  •    if ( intObjects == null || intObjects.size() == 0 )
    
  •    {
    
  •        return;
    
  •    }
    
     I18nObject i18nObject = isI18nObject( intObjects.iterator().next() );



     Locale locale = localeManager.getCurrentLocale();
  •    if ( i18nObject != null && locale != null && intObjects != null )
    
  •    if ( i18nObject != null && locale != null )
    
       {
    
           Collection<Translation> allTranslations = translationService.getTranslations( i18nObject.getClassName(), locale );
    

@@ -443,7 +448,7 @@

             }

         }
  •        log.warn( "Object not enabled for i18n: " + object );
    
  •        log.debug( "Object not enabled for i18n: " + object );
    
       }
    
    
    
       return null;
    

=== removed file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java 2009-03-09 22:33:48 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java 1970-01-01 00:00:00 +0000

@@ -1,50 +0,0 @@

-package org.hisp.dhis.i18n.hibernate;

-/*

    • 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 org.hibernate.event.PostLoadEventListener;

-import org.hibernate.event.PostLoadEvent;

-import org.hisp.dhis.i18n.I18nService;

-/**

    • @author Oyvind Brucker
  • */

-public class HibernateI18nPostLoadEventListener implements PostLoadEventListener

-{

  • private I18nService i18nService;

  • public void setI18nService( I18nService i18nService )

  • {

  •    this.i18nService = i18nService;
    
  • }

  • public void onPostLoad( PostLoadEvent postLoadEvent )

  • {

  •    i18nService.internationalise( postLoadEvent.getEntity() );
    
  • }

-}

=== added file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java 1970-01-01 00:00:00 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java 2009-11-10 11:45:58 +0000

@@ -0,0 +1,53 @@

+package org.hisp.dhis.i18n.interceptor;

+/*

    • 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 org.hisp.dhis.common.IdentifiableObject;

+import org.hisp.dhis.i18n.I18nService;

+import org.hisp.dhis.system.util.TimeUtils;

+import org.aspectj.lang.JoinPoint;

+/**

    • @author Lars Helge Overland
    • @version $Id$
  • */

+public class I18nTranslationInterceptor

+{

  • private I18nService i18nService;

  • public void setI18nService( I18nService i18nService )

  • {

  •    this.i18nService = i18nService;
    
  • }

  • public void intercept( JoinPoint joinPoint, Object object )

  • {

  •    i18nService.internationalise( object );
    
  • }

+}

=== 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-09 22:14:51 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml 2009-11-10 11:45:58 +0000

@@ -8,33 +8,6 @@

 <property name="systemLocale" value="en_GB"/>
  • <bean id=“I18nDataElement”

@@ -179,16 +152,6 @@

 </property>
  • <bean id=“I18nDataElementCategoryOption”

  • class=“org.hisp.dhis.i18n.I18nObject”>

  •  <list>
    
  •    <value>name</value>
    
  •  </list>
    

<bean id=“org.hisp.dhis.i18n.I18nService”

@@ -214,7 +177,6 @@

     <ref bean="I18nOrganisationUnitGroupSet"/>

     <ref bean="I18nDataSet"/>

     <ref bean="I18nDataElementCategory"/>
  •    <ref bean="I18nDataElementCategoryOption"/>
    
     </list>
    

@@ -240,11 +202,11 @@

   ref="org.hisp.dhis.i18n.I18nService"/>

Good work!

Look forward to having internationalised data sets available on the demo for download and use.
Perhaps we could start off with an MDG indicator group and an associated data set for that?
And later expand to include the full WHO core indicator set with corresponding data elements and data set.

Combined with SDMX-DH export functionality that would be a great package to provide to countries implementing DHIS and other related systems.

Ola Hodne Titlestad |Technical Officer|
Health Metrics Network (HMN) | World Health Organization

Avenue Appia 20 |1211 Geneva 27, Switzerland | Email: titlestado@who.int|Tel: +41 788216897
Website: www.healthmetricsnetwork.org

Better Information. Better Decisions. Better Health.

···

2009/11/10 Lars Helge Øverland larshelge@gmail.com

This was a tricky one. Previously a Hibernate PostLoadEventListener was used to inspect and translate objects provided by Hibernate. The event listener was previously registered with the HibernateConfigurationProvider with a MethodInvokingFactoryBean. We now use Spring’s LocalSessionFactoryBean, which makes this approach unusable since the LocalSessionFactoryBean gets initialized before the MethodInvokingFactoryBean gets to do its stuff (since there are no dependencies in that direction). We now have a standard AOP approach where get-methods returning i18n-enabled objects are matched and advised by the I18nTranslationInterceptor in dhis-i18n-db. I have also tested and made the code in I18nService and TranslationService more compact, although there was nothing wrong in there.

On Tue, Nov 10, 2009 at 12:47 PM, noreply@launchpad.net wrote:


revno: 1018

committer: Lars Helge Oeverland larshelge@gmail.com

branch nick: trunk

timestamp: Tue 2009-11-10 12:45:58 +0100

message:

Fixed the database internationalisation. Applying translations through AOP.

removed:

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java

added:

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java

modified:

dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java

dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml

dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml

dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java

dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/indicator/IndicatorServiceTest.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/organisationunit/OrganisationUnitService.java’

— dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2009-10-01 09:24:46 +0000

+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2009-11-10 11:45:58 +0000

@@ -217,6 +217,12 @@

  */

 int getNumberOfOrganisationalLevels();
  • /**

  • * Set parent of OrganisationUnit.
    
  • *
    
  • * @param organisationUnitId the identifier of the child OrganisationUnit.
    
  • * @param parentId the identifier of the parent OrganisationUnit.
    
  • */
    

    void updateOrganisationUnitParent( int organisationUnitId, int parentId );

    // -------------------------------------------------------------------------

=== modified file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-11-10 01:44:26 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-11-10 11:45:58 +0000

@@ -30,8 +30,8 @@

import static org.hisp.dhis.system.util.ReflectionUtils.getClassName;

import static org.hisp.dhis.system.util.ReflectionUtils.getId;

import static org.hisp.dhis.system.util.ReflectionUtils.getProperty;

+import static org.hisp.dhis.system.util.ReflectionUtils.isCollection;

import static org.hisp.dhis.system.util.ReflectionUtils.setProperty;

-import static org.hisp.dhis.system.util.ReflectionUtils.isCollection;

import java.util.ArrayList;

import java.util.Collection;

@@ -143,11 +143,16 @@

 private void internationaliseCollection( Collection<?> intObjects )

 {
  •    if ( intObjects == null || intObjects.size() == 0 )
    
  •    {
    
  •        return;
    
  •    }
    
     I18nObject i18nObject = isI18nObject( intObjects.iterator().next() );



     Locale locale = localeManager.getCurrentLocale();
  •    if ( i18nObject != null && locale != null && intObjects != null )
    
  •    if ( i18nObject != null && locale != null )
    
       {
    
           Collection<Translation> allTranslations = translationService.getTranslations( i18nObject.getClassName(), locale );
    

@@ -443,7 +448,7 @@

             }

         }
  •        log.warn( "Object not enabled for i18n: " + object );
    
  •        log.debug( "Object not enabled for i18n: " + object );
    
       }
    
    
    
       return null;
    

=== removed file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java 2009-03-09 22:33:48 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java 1970-01-01 00:00:00 +0000

@@ -1,50 +0,0 @@

-package org.hisp.dhis.i18n.hibernate;

-/*

    • 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 org.hibernate.event.PostLoadEventListener;

-import org.hibernate.event.PostLoadEvent;

-import org.hisp.dhis.i18n.I18nService;

-/**

    • @author Oyvind Brucker
  • */

-public class HibernateI18nPostLoadEventListener implements PostLoadEventListener

-{

  • private I18nService i18nService;

  • public void setI18nService( I18nService i18nService )

  • {

  •    this.i18nService = i18nService;
    
  • }

  • public void onPostLoad( PostLoadEvent postLoadEvent )

  • {

  •    i18nService.internationalise( postLoadEvent.getEntity() );
    
  • }

-}

=== added file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java 1970-01-01 00:00:00 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java 2009-11-10 11:45:58 +0000

@@ -0,0 +1,53 @@

+package org.hisp.dhis.i18n.interceptor;

+/*

    • 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 org.hisp.dhis.common.IdentifiableObject;

+import org.hisp.dhis.i18n.I18nService;

+import org.hisp.dhis.system.util.TimeUtils;

+import org.aspectj.lang.JoinPoint;

+/**

    • @author Lars Helge Overland
    • @version $Id$
  • */

+public class I18nTranslationInterceptor

+{

  • private I18nService i18nService;

  • public void setI18nService( I18nService i18nService )

  • {

  •    this.i18nService = i18nService;
    
  • }

  • public void intercept( JoinPoint joinPoint, Object object )

  • {

  •    i18nService.internationalise( object );
    
  • }

+}

=== 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-09 22:14:51 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml 2009-11-10 11:45:58 +0000

@@ -8,33 +8,6 @@

 <property name="systemLocale" value="en_GB"/>
  • <bean id=“I18nDataElement”

@@ -179,16 +152,6 @@

 </property>
  • <bean id=“I18nDataElementCategoryOption”

  • class=“org.hisp.dhis.i18n.I18nObject”>

  •  <list>
    
  •    <value>name</value>
    
  •  </list>
    

<bean id=“org.hisp.dhis.i18n.I18nService”

@@ -214,7 +177,6 @@

     <ref bean="I18nOrganisationUnitGroupSet"/>

     <ref bean="I18nDataSet"/>

     <ref bean="I18nDataElementCategory"/>
  •    <ref bean="I18nDataElementCategoryOption"/>
    
     </list>
    

@@ -240,11 +202,11 @@

   ref="org.hisp.dhis.i18n.I18nService"/>

Very good news indeed - thanks for fixing this, Lars!

Knut

···

2009/11/10 Ola Hodne Titlestad olatitle@gmail.com

Good work!

Look forward to having internationalised data sets available on the demo for download and use.
Perhaps we could start off with an MDG indicator group and an associated data set for that?

And later expand to include the full WHO core indicator set with corresponding data elements and data set.

Combined with SDMX-DH export functionality that would be a great package to provide to countries implementing DHIS and other related systems.

Ola Hodne Titlestad |Technical Officer|
Health Metrics Network (HMN) | World Health Organization

Avenue Appia 20 |1211 Geneva 27, Switzerland | Email: titlestado@who.int|Tel: +41 788216897
Website: www.healthmetricsnetwork.org

Better Information. Better Decisions. Better Health.

2009/11/10 Lars Helge Øverland larshelge@gmail.com

This was a tricky one. Previously a Hibernate PostLoadEventListener was used to inspect and translate objects provided by Hibernate. The event listener was previously registered with the HibernateConfigurationProvider with a MethodInvokingFactoryBean. We now use Spring’s LocalSessionFactoryBean, which makes this approach unusable since the LocalSessionFactoryBean gets initialized before the MethodInvokingFactoryBean gets to do its stuff (since there are no dependencies in that direction). We now have a standard AOP approach where get-methods returning i18n-enabled objects are matched and advised by the I18nTranslationInterceptor in dhis-i18n-db. I have also tested and made the code in I18nService and TranslationService more compact, although there was nothing wrong in there.

On Tue, Nov 10, 2009 at 12:47 PM, noreply@launchpad.net wrote:


revno: 1018

committer: Lars Helge Oeverland larshelge@gmail.com

branch nick: trunk

timestamp: Tue 2009-11-10 12:45:58 +0100

message:

Fixed the database internationalisation. Applying translations through AOP.

removed:

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java

added:

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java

modified:

dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java

dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java

dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml

dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml

dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java

dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/indicator/IndicatorServiceTest.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/organisationunit/OrganisationUnitService.java’

— dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2009-10-01 09:24:46 +0000

+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2009-11-10 11:45:58 +0000

@@ -217,6 +217,12 @@

  */

 int getNumberOfOrganisationalLevels();
  • /**

  • * Set parent of OrganisationUnit.
    
  • *
    
  • * @param organisationUnitId the identifier of the child OrganisationUnit.
    
  • * @param parentId the identifier of the parent OrganisationUnit.
    
  • */
    

    void updateOrganisationUnitParent( int organisationUnitId, int parentId );

    // -------------------------------------------------------------------------

=== modified file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-11-10 01:44:26 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-11-10 11:45:58 +0000

@@ -30,8 +30,8 @@

import static org.hisp.dhis.system.util.ReflectionUtils.getClassName;

import static org.hisp.dhis.system.util.ReflectionUtils.getId;

import static org.hisp.dhis.system.util.ReflectionUtils.getProperty;

+import static org.hisp.dhis.system.util.ReflectionUtils.isCollection;

import static org.hisp.dhis.system.util.ReflectionUtils.setProperty;

-import static org.hisp.dhis.system.util.ReflectionUtils.isCollection;

import java.util.ArrayList;

import java.util.Collection;

@@ -143,11 +143,16 @@

 private void internationaliseCollection( Collection<?> intObjects )

 {
  •    if ( intObjects == null || intObjects.size() == 0 )
    
  •    {
    
  •        return;
    
  •    }
    
     I18nObject i18nObject = isI18nObject( intObjects.iterator().next() );



     Locale locale = localeManager.getCurrentLocale();
  •    if ( i18nObject != null && locale != null && intObjects != null )
    
  •    if ( i18nObject != null && locale != null )
    
       {
    
           Collection<Translation> allTranslations = translationService.getTranslations( i18nObject.getClassName(), locale );
    

@@ -443,7 +448,7 @@

             }

         }
  •        log.warn( "Object not enabled for i18n: " + object );
    
  •        log.debug( "Object not enabled for i18n: " + object );
    
       }
    
    
    
       return null;
    

=== removed file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java 2009-03-09 22:33:48 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/hibernate/HibernateI18nPostLoadEventListener.java 1970-01-01 00:00:00 +0000

@@ -1,50 +0,0 @@

-package org.hisp.dhis.i18n.hibernate;

-/*

    • 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 org.hibernate.event.PostLoadEventListener;

-import org.hibernate.event.PostLoadEvent;

-import org.hisp.dhis.i18n.I18nService;

-/**

    • @author Oyvind Brucker
  • */

-public class HibernateI18nPostLoadEventListener implements PostLoadEventListener

-{

  • private I18nService i18nService;

  • public void setI18nService( I18nService i18nService )

  • {

  •    this.i18nService = i18nService;
    
  • }

  • public void onPostLoad( PostLoadEvent postLoadEvent )

  • {

  •    i18nService.internationalise( postLoadEvent.getEntity() );
    
  • }

-}

=== added file ‘dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java’

— dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java 1970-01-01 00:00:00 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/interceptor/I18nTranslationInterceptor.java 2009-11-10 11:45:58 +0000

@@ -0,0 +1,53 @@

+package org.hisp.dhis.i18n.interceptor;

+/*

    • 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 org.hisp.dhis.common.IdentifiableObject;

+import org.hisp.dhis.i18n.I18nService;

+import org.hisp.dhis.system.util.TimeUtils;

+import org.aspectj.lang.JoinPoint;

+/**

    • @author Lars Helge Overland
    • @version $Id$
  • */

+public class I18nTranslationInterceptor

+{

  • private I18nService i18nService;

  • public void setI18nService( I18nService i18nService )

  • {

  •    this.i18nService = i18nService;
    
  • }

  • public void intercept( JoinPoint joinPoint, Object object )

  • {

  •    i18nService.internationalise( object );
    
  • }

+}

=== 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-09 22:14:51 +0000

+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/resources/META-INF/dhis/beans.xml 2009-11-10 11:45:58 +0000

@@ -8,33 +8,6 @@

 <property name="systemLocale" value="en_GB"/>
  • <bean id=“I18nDataElement”

@@ -179,16 +152,6 @@

 </property>
  • <bean id=“I18nDataElementCategoryOption”

  • class=“org.hisp.dhis.i18n.I18nObject”>

  •  <list>
    
  •    <value>name</value>
    
  •  </list>
    

<bean id=“org.hisp.dhis.i18n.I18nService”

@@ -214,7 +177,6 @@

     <ref bean="I18nOrganisationUnitGroupSet"/>

     <ref bean="I18nDataSet"/>

     <ref bean="I18nDataElementCategory"/>
  •    <ref bean="I18nDataElementCategoryOption"/>
    
     </list>
    

@@ -240,11 +202,11 @@

   ref="org.hisp.dhis.i18n.I18nService"/>