← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10929: Improved deletion handlers

 

------------------------------------------------------------
revno: 10929
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-05-22 12:27:36 +0200
message:
  Improved deletion handlers
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableDeletionHandler.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-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java	2013-01-16 13:25:48 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java	2013-05-22 10:27:36 +0000
@@ -29,8 +29,12 @@
 
 import java.util.Iterator;
 
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.hisp.dhis.user.User;
@@ -84,11 +88,35 @@
         {
             if ( chart.getIndicators().remove( indicator ) )
             {
-                chartService.addChart( chart );
-            }
-        }
-    }
-
+                chartService.updateChart( chart );
+            }
+        }
+    }
+
+    @Override
+    public void deleteDataElement( DataElement dataElement )
+    {
+        for ( Chart chart : chartService.getAllCharts() )
+        {
+            if ( chart.getDataElements().remove( chart ) )
+            {
+                chartService.updateChart( chart );
+            }
+        }
+    }
+
+    @Override
+    public void deleteDataSet( DataSet dataSet )
+    {
+        for ( Chart chart : chartService.getAllCharts() )
+        {
+            if ( chart.getDataSets().remove( chart ) )
+            {
+                chartService.updateChart( chart );
+            }
+        }
+    }
+    
     @Override
     public void deleteOrganisationUnit( OrganisationUnit unit )
     {
@@ -96,7 +124,7 @@
         {
             if ( chart.getOrganisationUnits().remove( unit ) )
             {
-                chartService.addChart( chart );
+                chartService.updateChart( chart );
             }
         }
     }
@@ -113,4 +141,28 @@
             chartService.deleteChart( chart );
         }
     }
+
+    @Override
+    public void deleteDataElementGroup( DataElementGroup group )
+    {
+        for ( Chart chart : chartService.getAllCharts() )
+        {
+            if ( chart.getDataElementGroups().remove( group ) )
+            {
+                chartService.updateChart( chart );
+            }
+        }
+    }
+    
+    @Override
+    public void deleteOrganisationUnitGroup( OrganisationUnitGroup group )
+    {
+        for ( Chart chart : chartService.getAllCharts() )
+        {
+            if ( chart.getOrganisationUnitGroups().remove( group ) )
+            {
+                chartService.updateChart( chart );
+            }
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableDeletionHandler.java	2013-05-19 18:49:47 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/ReportTableDeletionHandler.java	2013-05-22 10:27:36 +0000
@@ -28,6 +28,7 @@
  */
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -64,45 +65,39 @@
     }
 
     @Override
-    public String allowDeleteDataElement( DataElement dataElement )
-    {
-        for ( ReportTable reportTable : reportTableService.getAllReportTables() )
-        {
-            if ( reportTable.getDataElements().contains( dataElement ) )
-            {
-                return reportTable.getName();
-            }
-        }
-
-        return null;
-    }
-
-    @Override
-    public String allowDeleteIndicator( Indicator indicator )
-    {
-        for ( ReportTable reportTable : reportTableService.getAllReportTables() )
-        {
-            if ( reportTable.getIndicators().contains( indicator ) )
-            {
-                return reportTable.getName();
-            }
-        }
-
-        return null;
-    }
-
-    @Override
-    public String allowDeleteDataSet( DataSet dataSet )
-    {
-        for ( ReportTable reportTable : reportTableService.getAllReportTables() )
-        {
-            if ( reportTable.getDataSets().contains( dataSet ) )
-            {
-                return reportTable.getName();
-            }
-        }
-
-        return null;
+    public void deleteDataElement( DataElement dataElement )
+    {
+        for ( ReportTable reportTable : reportTableService.getAllReportTables() )
+        {
+            if ( reportTable.getDataElements().remove( dataElement ) )
+            {
+                reportTableService.updateReportTable( reportTable );
+            }
+        }
+    }
+
+    @Override
+    public void deleteIndicator( Indicator indicator )
+    {
+        for ( ReportTable reportTable : reportTableService.getAllReportTables() )
+        {
+            if ( reportTable.getIndicators().remove( indicator ) )
+            {
+                reportTableService.updateReportTable( reportTable );
+            }
+        }
+    }
+
+    @Override
+    public void deleteDataSet( DataSet dataSet )
+    {
+        for ( ReportTable reportTable : reportTableService.getAllReportTables() )
+        {
+            if ( reportTable.getDataSets().remove( dataSet ) )
+            {
+                reportTableService.updateReportTable( reportTable );
+            }
+        }
     }
 
     @Override
@@ -132,6 +127,18 @@
     }
 
     @Override
+    public void deleteDataElementGroup( DataElementGroup group )
+    {
+        for ( ReportTable reportTable : reportTableService.getAllReportTables() )
+        {
+            if ( reportTable.getDataElementGroups().remove( group ) )
+            {
+                reportTableService.updateReportTable( reportTable );
+            }
+        }
+    }
+    
+    @Override
     public void deleteOrganisationUnitGroup( OrganisationUnitGroup group )
     {
         for ( ReportTable reportTable : reportTableService.getAllReportTables() )