← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1691: Fixed Bug - Validate on while adding the duplicated name or short name of object

 

------------------------------------------------------------
revno: 1691
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-03-25 11:15:30 +0700
message:
  Fixed Bug - Validate on while adding the duplicated name or short name of object
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/translate.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/GetTranslationsAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/I18nAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/TranslateAction.java
  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/dhis-web-commons.xml
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties


--
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-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/translate.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/translate.vm	2010-03-18 10:55:32 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/i18n/translate.vm	2010-03-25 04:15:30 +0000
@@ -73,6 +73,10 @@
 
 <script type="text/javascript">
 
+	#if ( $message )
+		setMessage( '$i18n.getString("$message")' );
+	#end
+
     var propNames = new Array()
     #set( $count = 0 )
     #foreach ($propertyName in $propertyNames )

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/GetTranslationsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/GetTranslationsAction.java	2009-08-20 08:17:49 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/GetTranslationsAction.java	2010-03-25 04:15:30 +0000
@@ -38,6 +38,7 @@
 /**
  * @author Oyvind Brucker
  */
+@SuppressWarnings("serial")
 public class GetTranslationsAction 
     extends ActionSupport
 {

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/I18nAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/I18nAction.java	2009-11-09 22:48:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/I18nAction.java	2010-03-25 04:15:30 +0000
@@ -40,8 +40,11 @@
 
 /**
  * @author Oyvind Brucker
+ * @version $Id$
+ * @modifier Dang Duy Hieu
+ * @since 2010-03-24
  */
-public class I18nAction 
+public class I18nAction
     implements Action
 {
     private String className;
@@ -50,6 +53,8 @@
 
     private String returnUrl;
 
+    private String message;
+
     private Map<String, String> translations = new Hashtable<String, String>();
 
     private Map<String, String> referenceTranslations = new Hashtable<String, String>();
@@ -107,12 +112,21 @@
         return objectId;
     }
 
-
     public String getReturnUrl()
     {
         return returnUrl;
     }
 
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public void setMessage( String message )
+    {
+        this.message = message;
+    }
+
     public Collection<Locale> getAvailableLocales()
         throws Exception
     {
@@ -160,7 +174,8 @@
 
         translations = i18nService.getTranslations( className, Integer.parseInt( objectId ), getCurrentLocale() );
 
-        referenceTranslations = i18nService.getTranslations( className, Integer.parseInt( objectId ), getCurrentRefLocale() );
+        referenceTranslations = i18nService.getTranslations( className, Integer.parseInt( objectId ),
+            getCurrentRefLocale() );
 
         /**
          * Fill in empty strings for null values
@@ -177,7 +192,8 @@
                 referenceTranslations.put( property, "" );
             }
         }
-        
+
         return SUCCESS;
     }
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/TranslateAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/TranslateAction.java	2009-08-20 08:17:49 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/TranslateAction.java	2010-03-25 04:15:30 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Locale;
@@ -36,20 +38,29 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.i18n.util.LocaleUtils;
+import org.hisp.dhis.translation.Translation;
+import org.hisp.dhis.translation.TranslationService;
 
-import org.apache.struts2.ServletActionContext;
 import com.opensymphony.xwork2.Action;
 
 /**
  * @author Oyvind Brucker
+ * @version $Id$
+ * @modifier Dang Duy Hieu
+ * @since 2010-03-24
  */
-public class TranslateAction 
+public class TranslateAction
     implements Action
 {
+    private static final String PROPERTY_NAME = "name";
+
+    private static final String PROPERTY_SHORTNAME = "shortname";
+
     private static final Log log = LogFactory.getLog( TranslateAction.class );
-    
+
     private String className;
 
     private String id;
@@ -58,6 +69,10 @@
 
     private String returnUrl;
 
+    private String message;
+
+    private String objectId;
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -69,6 +84,13 @@
         this.i18nService = i18nService;
     }
 
+    private TranslationService translationService;
+
+    public void setTranslationService( TranslationService translationService )
+    {
+        this.translationService = translationService;
+    }
+
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------
@@ -93,10 +115,20 @@
         this.returnUrl = returnUrl;
     }
 
+    public String getObjectId()
+    {
+        return objectId;
+    }
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
 
+    public String getMessage()
+    {
+        return message;
+    }
+
     public String getClassName()
     {
         return className;
@@ -125,7 +157,29 @@
         throws Exception
     {
         log.info( "Classname: " + className + ", id: " + id + ", loc: " + loc );
-        
+
+        this.objectId = this.id;
+
+        Locale thisLocale = LocaleUtils.getLocale( loc );
+
+        // ---------------------------------------------------------------------
+        // Gets collection of the available translations AND
+        // collection of the translating translations if any
+        // ---------------------------------------------------------------------
+
+        Collection<Translation> availableTranslations = new HashSet<Translation>( translationService.getTranslations(
+            className, thisLocale ) );
+
+        Collection<Translation> translatedTranslations = new HashSet<Translation>( translationService.getTranslations(
+            className, Integer.parseInt( id ), thisLocale ) );
+
+        // -------------------------------------------------------------
+        // Removes all the translating translation objects
+        // from the available translation collection
+        // -------------------------------------------------------------
+
+        availableTranslations.removeAll( translatedTranslations );
+
         HttpServletRequest request = ServletActionContext.getRequest();
 
         Map<String, String> translations = new Hashtable<String, String>();
@@ -138,13 +192,33 @@
 
             if ( translation != null && translation.length > 0 && translation[0].length() > 0 )
             {
+                // -------------------------------------------------------------
+                // Checking duplicated name or short name
+                // -------------------------------------------------------------
+
+                message = checkDuplicatedNameOrShortname( availableTranslations, propertyName, translation[0] );
+
+                if ( message != null )
+                {
+                    if ( message.equalsIgnoreCase( PROPERTY_NAME ) )
+                    {
+                        message = "translation_duplicated_name";
+
+                        return INPUT;
+                    }
+                    else if ( message.equalsIgnoreCase( PROPERTY_SHORTNAME ) )
+                    {
+                        message = "translation_duplicated_shortname";
+
+                        return INPUT;
+                    }
+                }
+
                 translations.put( propertyName, translation[0] );
             }
         }
 
         log.info( "Translations: " + translations );
-        
-        Locale thisLocale = LocaleUtils.getLocale( loc );
 
         if ( thisLocale != null && !loc.equals( "heading" ) )
         {
@@ -153,4 +227,27 @@
 
         return SUCCESS;
     }
+
+    // -------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------
+
+    private String checkDuplicatedNameOrShortname( Collection<Translation> translations, String propertyName,
+        String value )
+    {
+        if ( propertyName.equalsIgnoreCase( PROPERTY_NAME ) || propertyName.equalsIgnoreCase( PROPERTY_SHORTNAME ) )
+        {
+            for ( Translation curTranslation : translations )
+            {
+                if ( curTranslation.getProperty().equals( propertyName )
+                    && curTranslation.getValue().equalsIgnoreCase( value.toLowerCase() ) )
+                {
+                    return propertyName;
+                }
+            }
+        }
+
+        return null;
+    }
+
 }

=== 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	2010-03-06 17:02:42 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2010-03-25 04:15:30 +0000
@@ -489,10 +489,14 @@
 		</property>
 	</bean>
 
-	<bean id="org.hisp.dhis.i18n.action.TranslateAction" class="org.hisp.dhis.i18n.action.TranslateAction">
+	<bean id="org.hisp.dhis.i18n.action.TranslateAction" 
+		class="org.hisp.dhis.i18n.action.TranslateAction">
 		<property name="i18nService">
 			<ref bean="org.hisp.dhis.i18n.I18nService" />
 		</property>
+		<property name="translationService">
+			<ref bean="org.hisp.dhis.translation.TranslationService" />
+		</property>
 	</bean>
 
 	<!-- DataElement Order -->

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2010-03-17 14:24:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2010-03-25 04:15:30 +0000
@@ -246,10 +246,10 @@
 		</action>
 
 		<action name="translate" class="org.hisp.dhis.i18n.action.TranslateAction">
-			<result name="success" type="velocity">/dhis-web-commons/i18n/goback.vm
-			</result>
+			<result name="success" type="velocity">/dhis-web-commons/i18n/goback.vm</result>
+			<result name="input" type="chain">i18n</result>
 		</action>
-
+		
 		<action name="getTranslations" class="org.hisp.dhis.i18n.action.GetTranslationsAction">
 			<result name="success" type="velocity">
 				/dhis-web-commons/i18n/responseTranslations.vm</result>

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2010-03-09 10:10:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2010-03-25 04:15:30 +0000
@@ -182,12 +182,14 @@
 translation_add = Add
 translation_locale = Locale
 translation_reference = Reference
-translation_language_must_be_two_chars = Language must be two characters
-translation_country_must_be_two_chars = Country must be two characters
-translation_variant_must_be_specified = Variant must be specified
-translation_locale_already_exists = Locale already exists
-translation_shortname_wellformed  = Please verify Letters, Numbers and Underscore for short name only
-translation_shortname_length      = Shortname's maximum length of 25 charaters
+translation_language_must_be_two_chars  = Language must be two characters
+translation_country_must_be_two_chars   = Country must be two characters
+translation_variant_must_be_specified   = Variant must be specified
+translation_locale_already_exists       = Locale already exists
+translation_shortname_wellformed        = Please verify Letters, Numbers and Underscore for short name only
+translation_shortname_length            = Shortname's maximum length of 25 charaters
+translation_duplicated_name             = Sorry! You verified a duplicated name
+translation_duplicated_shortname        = Sorry! You verified a duplicated short name
 
 #-- About ----------------------------------------------------------------------#
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties	2010-03-09 08:30:08 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties	2010-03-25 04:15:30 +0000
@@ -174,7 +174,10 @@
 translation_variant_must_be_specified 				= Bi\u1ebfn kh\u00f4ng \u0111\u01b0\u1ee3c b\u1ecf tr\u1ed1ng
 translation_locale_already_exists 					= V\u00f9ng n\u00e0y \u0111\u00e3 t\u1ed3n t\u1ea1i
 translation_shortname_wellformed                    = T\u00ean vi\u1ebft t\u1eaft ch\u1ec9 ch\u1ee9a c\u00e1c k\u00fd t\u1ef1 Alphabet(a-z), s\u1ed1(0-9) v\u00e0 d\u1ea5u g\u1ea1ch d\u01b0\u1edbi(_)
-translation_shortname_length                        = \u0110\u1ed9 d\u00e0i t\u1ed1i \u0111a c\u1ee7a t\u00ean vi\u1ebft t\u1eaft l\u00e0 25 k\u00fd t\u1ef1 
+translation_shortname_length                        = \u0110\u1ed9 d\u00e0i t\u1ed1i \u0111a c\u1ee7a t\u00ean vi\u1ebft t\u1eaft l\u00e0 25 k\u00fd t\u1ef1
+translation_duplicated_name                         = Vui l\u00f2ng nh\u1eadp t\u00ean kh\u00e1c. L\u00fd do: Tr\u00f9ng l\u1eb7p.
+translation_duplicated_shortname                    = Xin l\u1ed7i! T\u00ean vi\u1ebft t\u1eaft n\u00e0y \u0111\u00e3 c\u00f3 trong H\u1ec7 th\u1ed1ng
+
 
 #-- About ----------------------------------------------------------------------#