← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9875: Category option UI, added code uniqueness validation

 

------------------------------------------------------------
revno: 9875
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-02-22 09:14:27 +0100
message:
  Category option UI, added code uniqueness validation
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryOptionForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryOptionForm.vm


--
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/dataelement/DataElementCategoryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java	2013-02-19 16:12:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java	2013-02-22 08:14:27 +0000
@@ -169,6 +169,14 @@
     DataElementCategoryOption getDataElementCategoryOptionByName( String name );
 
     /**
+     * Retrieves the DataElementCategoryOption with the given code.
+     *
+     * @param code the code.
+     * @return the DataElementCategoryOption with the given code.
+     */
+    DataElementCategoryOption getDataElementCategoryOptionByCode( String code );
+
+    /**
      * Returns all DataElementCategoryOptions.
      *
      * @return a collection of all DataElementCategoryOptions, or an empty collection if there

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2013-02-22 14:58:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2013-02-22 08:14:27 +0000
@@ -194,15 +194,12 @@
 
     public DataElementCategoryOption getDataElementCategoryOptionByName( String name )
     {
-        List<DataElementCategoryOption> dataElementCategoryOptions = new ArrayList<DataElementCategoryOption>(
-            dataElementCategoryOptionStore.getAllEqName( name ) );
-
-        if ( dataElementCategoryOptions.isEmpty() )
-        {
-            return null;
-        }
-
-        return i18n( i18nService, dataElementCategoryOptions.get( 0 ) );
+        return i18n( i18nService, dataElementCategoryOptionStore.getByName( name ) );
+    }
+
+    public DataElementCategoryOption getDataElementCategoryOptionByCode( String code )
+    {
+        return i18n( i18nService, dataElementCategoryOptionStore.getByCode( code ) );
     }
 
     public Collection<DataElementCategoryOption> getDataElementCategoryOptions( final Collection<Integer> identifiers )
@@ -274,15 +271,7 @@
 
     public DataElementCategoryCombo getDataElementCategoryComboByName( String name )
     {
-        List<DataElementCategoryCombo> dataElementCategoryCombos = new ArrayList<DataElementCategoryCombo>(
-            dataElementCategoryComboStore.getAllEqName( name ) );
-
-        if ( dataElementCategoryCombos.isEmpty() )
-        {
-            return null;
-        }
-
-        return i18n( i18nService, dataElementCategoryCombos.get( 0 ) );
+        return i18n( i18nService, dataElementCategoryComboStore.getByName( name ) );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java	2013-02-22 08:14:27 +0000
@@ -69,6 +69,13 @@
         this.name = name;
     }
 
+    private String code;
+
+    public void setCode( String code )
+    {
+        this.code = code;
+    }
+
     private Integer id;
 
     public void setId( Integer id )
@@ -105,6 +112,18 @@
             }
         }
 
+        if ( code != null )
+        {
+            DataElementCategoryOption match = dataElementCategoryService.getDataElementCategoryOptionByCode( code );
+
+            if ( match != null && (id == null || match.getId() != id) )
+            {
+                message = i18n.getString( "code_in_use" );
+
+                return ERROR;
+            }
+        }
+
         message = "ok";
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2013-02-22 14:58:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties	2013-02-22 08:14:27 +0000
@@ -63,7 +63,7 @@
 confirm_delete_indicator_type=Are you sure you want to delete this indicator type?
 confirm_delete_data_dictionary=Are you sure you want to delete this data dictionary?
 name_in_use=The name is already in use. Please choose a different name
-code_in_use=The data element code is already in use. Please choose a different data element code
+code_in_use=The code is already in use. Please choose a different code
 short_name_in_use=The short name is already in use. Please choose a different short name
 everything_is_ok=Everything is OK
 adding_data_element_group_failed=Adding the data element group failed with the following message

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryOptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryOptionForm.vm	2013-02-22 15:07:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryOptionForm.vm	2013-02-22 08:14:27 +0000
@@ -4,7 +4,8 @@
 		form.submit();
 	});
 
-		checkValueIsExist( "name", "validateDataElementCategoryOption.action");	
+		checkValueIsExist( "name", "validateDataElementCategoryOption.action" );	
+        checkValueIsExist( "code", "validateDataElementCategoryOption.action" ); 
 	});
 
     var i18n_specify_category_option_name = '$encoder.jsEscape( $i18n.getString( "specify_category_option_name" ) , "'")';

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryOptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryOptionForm.vm	2013-02-22 15:07:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryOptionForm.vm	2013-02-22 08:14:27 +0000
@@ -5,7 +5,8 @@
 			'rules': getValidationRules("dateElementCategoryOption")
 		}); 
 
-		checkValueIsExist( "name", "validateDataElementCategoryOption.action", {id: $dataElementCategoryOption.id});		
+		checkValueIsExist( "name", "validateDataElementCategoryOption.action", {id: $dataElementCategoryOption.id} );
+        checkValueIsExist( "code", "validateDataElementCategoryOption.action", {id: $dataElementCategoryOption.code} );
 	});
 
     var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_data_element_category_option" ) , "'")';