← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4260: Implemented deletion handler for category option combos properly. Trying to delete a category com...

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4260 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-08-05 17:00:00 +0200
message:
  Implemented deletion handler for category option combos properly. Trying to delete a category combo or category with category option combos associated with data values will now be denied before any deletion takes place.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/ExpressionDeletionHandler.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm
  resources/sql/integritychecks.sql


--
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/dataelement/DataElementCategoryOptionComboDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java	2011-07-07 20:49:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java	2011-08-05 14:06:08 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Iterator;
+
 import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.springframework.jdbc.core.JdbcTemplate;
 
@@ -59,6 +61,8 @@
     // DeletionHandler implementation
     // -------------------------------------------------------------------------
 
+    //TODO expressionoptioncombo
+    
     @Override
     public String getClassName()
     {
@@ -68,50 +72,50 @@
     @Override
     public boolean allowDeleteDataElementCategoryOption( DataElementCategoryOption categoryOption )
     {
-        for ( DataElementCategoryOptionCombo categoryOptionCombo : 
-            categoryService.getAllDataElementCategoryOptionCombos() )
-        {
-            if ( categoryOptionCombo.getCategoryOptions().contains( categoryOption ) )
-            {
-                return false;
-            }
-        }
+        final String sql =
+            "select count(*) from datavalue dv " +
+            "where dv.categoryoptioncomboid in ( " +
+                "select cc.categoryoptioncomboid from categoryoptioncombos_categoryoptions cc " +
+                "where cc.categoryoptionid = " + categoryOption.getId() + " );";
         
-        return true;
+        return jdbcTemplate.queryForInt( sql ) == 0;
+    }
+    
+    @Override
+    public boolean allowDeleteDataElementCategory( DataElementCategory category )
+    {
+        final String sql =
+            "select count(*) from datavalue dv " +
+            "where dv.categoryoptioncomboid in ( " +
+              "select cc.categoryoptioncomboid from categoryoptioncombos_categoryoptions cc, categories_categoryoptions co " +
+              "where cc.categoryoptionid = co.categoryoptionid " +
+              "and co.categoryid=" + category.getId() + " );";        
+
+        return jdbcTemplate.queryForInt( sql ) == 0;
     }
     
     @Override
     public boolean allowDeleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
     {
-        for ( DataElementCategoryOptionCombo eachOptionCombo : categoryCombo.getOptionCombos() )
-        {
-            String sql = "SELECT COUNT(*) FROM datavalue where categoryoptioncomboid=" + eachOptionCombo.getId();
-            
-            if ( jdbcTemplate.queryForInt( sql ) > 0 )
-            {
-                return false;
-            }
-            
-            sql = "SELECT COUNT(*) FROM expressionoptioncombo where categoryoptioncomboid=" + eachOptionCombo.getId();
-            
-            if ( jdbcTemplate.queryForInt( sql ) > 0 )
-            {
-                return false;
-            }
-        }
+        final String sql =
+            "select count(*) from datavalue dv " +
+            "where dv.categoryoptioncomboid in ( " +
+              "select co.categoryoptioncomboid from categorycombos_optioncombos co " +
+              "where co.categorycomboid=" + categoryCombo.getId() + " );";
         
-        return true;
+        return jdbcTemplate.queryForInt( sql ) == 0;
     }
     
     @Override
     public void deleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
     {
-        for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryService.getAllDataElementCategoryOptionCombos() )
+        Iterator<DataElementCategoryOptionCombo> iterator = categoryCombo.getOptionCombos().iterator();
+        
+        while ( iterator.hasNext() )
         {
-            if ( categoryOptionCombo.getCategoryCombo().equals( categoryCombo ) )
-            {
-                categoryService.deleteDataElementCategoryOptionCombo( categoryOptionCombo );
-            }
+            DataElementCategoryOptionCombo optionCombo = iterator.next();
+            iterator.remove();
+            categoryService.deleteDataElementCategoryOptionCombo( optionCombo );
         }
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/ExpressionDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/ExpressionDeletionHandler.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/ExpressionDeletionHandler.java	2011-08-05 14:56:15 +0000
@@ -28,6 +28,7 @@
  */
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 
 /**
@@ -65,6 +66,20 @@
         {
             if ( expression.getDataElementsInExpression().remove( dataElement ) )
             {
+                expression.setExpression( "1" );
+                expressionService.updateExpression( expression );
+            }
+        }
+    }
+    
+    @Override
+    public void deleteDataElementCategoryOptionCombo( DataElementCategoryOptionCombo optionCombo )
+    {
+        for ( Expression expression : expressionService.getAllExpressions() )
+        {
+            if ( expression.getOptionCombosInExpression().remove( optionCombo ) )
+            {
+                expression.setExpression( "1" );
                 expressionService.updateExpression( expression );
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm	2011-08-02 18:48:02 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm	2011-08-05 14:45:27 +0000
@@ -1,4 +1,6 @@
 #set( $tabIndex = 1 )
+#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )
+
 #foreach( $categoryCombo in $orderedCategoryCombos )
 <table style="border:1px solid #c0c0c0; padding:10px;" cellspacing="0">
   #set( $colCount = $numberOfTotalColumns.get( $categoryCombo.id )  ) 
@@ -39,13 +41,13 @@
   #set( $dataEntryId = "${dataElement.id}-${optionCombo.id}-val" )	    
   <td>
   #if( $dataElement.type == "bool" )
-  <select name="entryselect" id="$dataEntryId" #if( !$auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )disabled="disabled"#end tabindex="$tabIndex" #if( $locked )disabled="disabled"#end>
+  <select name="entryselect" id="$dataEntryId" #if( !$hasAccess )disabled="disabled"#end tabindex="$tabIndex" #if( $locked )disabled="disabled"#end>
     <option value="">[$i18n.getString( "no_value" )]</option>
     <option value="true">$i18n.getString( "yes" )</option>
     <option value="false">$i18n.getString( "no" )</option>
   </select>
   #else
-  <input name="entryfield" id="$dataEntryId" type="text" #if( !$auth.hasAccess( "dhis-web-dataentry", "saveValue") )disabled="disabled"#end tabindex="$tabIndex" #if( $locked )disabled="disabled"#end>
+  <input name="entryfield" id="$dataEntryId" type="text" #if( !$hasAccess )disabled="disabled"#end tabindex="$tabIndex" #if( $locked )disabled="disabled"#end>
   #end
   </td>
   #set( $tabIndex = $tabIndex + 1 )

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-08-02 18:48:02 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2011-08-05 14:45:27 +0000
@@ -49,6 +49,12 @@
 		var optionComboId = id.split( '-' )[1];
 		var type = dataElements[dataElementId].type;
     	
+    	$( this ).unbind( 'focus' );
+    	$( this ).unbind( 'blur' );
+    	$( this ).unbind( 'change' );
+    	$( this ).unbind( 'dblclick' );
+    	$( this ).unbind( 'keyup' );
+    	
     	$( this ).focus( valueFocus );
     	
     	$( this ).blur( valueBlur );
@@ -80,6 +86,9 @@
 		var dataElementId = id.split( '-' )[0];
 		var optionComboId = id.split( '-' )[1];	
 		
+    	$( this ).unbind( 'focus' );
+    	$( this ).unbind( 'change' );
+    	
     	$( this ).focus( valueFocus );
     	
     	$( this ).change( function() {

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm	2011-08-02 18:48:02 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm	2011-08-05 14:45:27 +0000
@@ -1,5 +1,6 @@
 #set( $marker = 0 )
 #set( $tabIndex = 1 )
+#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )
 
 #foreach( $section in $sections )
 
@@ -58,13 +59,13 @@
     #set( $greyedField = false )
     #set( $greyedField = $greyedFields.get( "$dataElement.id:$optionCombo.id" ) )        
     #if( $dataElement.type == "bool" )
-    <td><select name="entryselect" id="$dataEntryId" #if( !$auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )disabled="disabled"#end tabindex="$tabIndex" #if( $locked || $greyedField )disabled="disabled"#end>
+    <td><select name="entryselect" id="$dataEntryId" #if( !$hasAccess )disabled="disabled"#end tabindex="$tabIndex" #if( $locked || $greyedField )disabled="disabled"#end>
       <option value="">[$i18n.getString( "no_value" )]</option>
       <option value="true">$i18n.getString( "yes" )</option>
       <option value="false">$i18n.getString( "no" )</option>
     </select></td>
     #else
-    <td><input name="entryfield" id="$dataEntryId" type="text" #if( !$auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )disabled="disabled"#end tabindex="$tabIndex" #if( $locked || $greyedField )class="grey" disabled="disabled"#end></td>
+    <td><input name="entryfield" id="$dataEntryId" type="text" #if( !$hasAccess )disabled="disabled"#end tabindex="$tabIndex" #if( $locked || $greyedField )class="grey" disabled="disabled"#end></td>
     #end
     </td>
     #set( $tabIndex = $tabIndex + 1 )

=== modified file 'resources/sql/integritychecks.sql'
--- resources/sql/integritychecks.sql	2011-07-18 10:22:08 +0000
+++ resources/sql/integritychecks.sql	2011-08-05 14:06:08 +0000
@@ -61,8 +61,6 @@
 create index aggregatedindicatorvalue_index on aggregatedindicatorvalue (indicatorid, periodid, organisationunitid);
 create index aggregateddatasetcompleteness_index on aggregateddatasetcompleteness  (datasetid, periodid, organisationunitid);
 
-select * from categoryoptioncombo where categoryoptioncomboid not in (select distinct categoryoptioncomboid from datavalue);
-
 -- Get category option combos without category options
 
 select * from categoryoptioncombo where categoryoptioncomboid not in (select distinct categoryoptioncomboid from categoryoptioncombos_categoryoptions);
@@ -97,3 +95,8 @@
 select count(categoryoptionid) from categories_categoryoptions where categoryoptionid=cc.categoryoptionid )
 as categorycount from categories_categoryoptions as cc order by categorycount desc;
 
+-- Get category option combos without data values (not an error)
+
+select * from categoryoptioncombo where categoryoptioncomboid not in (select distinct categoryoptioncomboid from datavalue);
+
+