← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4051: Fixed bug: Validatation-deletion-categoryoptioncombos ( for Indicators ).

 

------------------------------------------------------------
revno: 4051
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-07-01 12:21:03 +0700
message:
  Fixed bug: Validatation-deletion-categoryoptioncombos ( for Indicators ).
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.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-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java	2011-06-22 06:57:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java	2011-07-01 05:21:03 +0000
@@ -30,6 +30,8 @@
 import java.util.Set;
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 
@@ -93,7 +95,7 @@
             }
         }
     }
-    
+
     @Override
     public void deleteIndicatorGroup( IndicatorGroup group )
     {
@@ -112,14 +114,14 @@
         for ( Indicator indicator : indicatorService.getAllIndicators() )
         {
             Set<DataElement> daels = expressionService.getDataElementsInExpression( indicator.getNumerator() );
-            
+
             if ( daels != null && daels.contains( dataElement ) )
             {
                 return false;
             }
-            
+
             daels = expressionService.getDataElementsInExpression( indicator.getDenominator() );
-            
+
             if ( daels != null && daels.contains( dataElement ) )
             {
                 return false;
@@ -127,5 +129,31 @@
         }
 
         return true;
-    }    
+    }
+
+    @Override
+    public boolean allowDeleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
+    {
+        for ( Indicator indicator : indicatorService.getAllIndicators() )
+        {
+            Set<DataElementCategoryOptionCombo> optionCombos = expressionService.getOptionCombosInExpression( indicator
+                .getNumerator() );
+            optionCombos.retainAll( categoryCombo.getOptionCombos() );
+
+            if ( optionCombos != null && optionCombos.size() > 0 )
+            {
+                return false;
+            }
+
+            optionCombos = expressionService.getOptionCombosInExpression( indicator.getDenominator() );
+            optionCombos.retainAll( categoryCombo.getOptionCombos() );
+
+            if ( optionCombos != null && optionCombos.size() > 0 )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
 }