← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7501: Improved deletion of dashboard content

 

------------------------------------------------------------
revno: 7501
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-07-03 23:19:51 +0200
message:
  Improved deletion of dashboard content
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContentStore.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardContentDeletionHandler.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardContentStore.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.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-api/src/main/java/org/hisp/dhis/dashboard/DashboardContentStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContentStore.java	2012-07-01 07:33:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContentStore.java	2012-07-03 21:19:51 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+
 import org.hisp.dhis.common.GenericStore;
 import org.hisp.dhis.document.Document;
 import org.hisp.dhis.mapping.MapView;
@@ -39,11 +41,11 @@
 public interface DashboardContentStore
     extends GenericStore<DashboardContent>
 {
-    void removeDocumentAssociations( Document document );
-    
-    void removeMapViewAssocations( MapView mapView );
-    
-    void removeReportAssociations( Report report );
-    
-    void removeReportTableAssociations( ReportTable reportTable );
+    Collection<DashboardContent> getByDocument( Document document );
+    
+    Collection<DashboardContent> getByMapView( MapView mapView );
+    
+    Collection<DashboardContent> getByReport( Report report );
+    
+    Collection<DashboardContent> getByReportTable( ReportTable reportTable );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2012-07-01 07:33:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2012-07-03 21:19:51 +0000
@@ -37,7 +37,6 @@
 
 /**
  * @author Lars Helge Overland
- * @version $Id$
  */
 public interface DashboardService
 {
@@ -45,6 +44,8 @@
 
     void saveDashboardContent( DashboardContent dashboardContent );
 
+    void updateDashboardContent( DashboardContent dashboardContent );
+    
     DashboardContent getDashboardContent( int id );
 
     DashboardContent getDashboardContent( User user );
@@ -52,12 +53,12 @@
     Collection<DashboardContent> getAllDashboardContent();
     
     void deleteDashboardContent( DashboardContent content );
-    
-    void removeDocumentAssociations( Document document );
-    
-    void removeMapViewAssocations( MapView mapView );
-    
-    void removeReportAssociations( Report report );
-    
-    void removeReportTableAssociations( ReportTable reportTable );
+
+    Collection<DashboardContent> getByDocument( Document document );
+    
+    Collection<DashboardContent> getByMapView( MapView mapView );
+    
+    Collection<DashboardContent> getByReport( Report report );
+    
+    Collection<DashboardContent> getByReportTable( ReportTable reportTable );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardContentDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardContentDeletionHandler.java	2012-07-01 07:33:25 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardContentDeletionHandler.java	2012-07-03 21:19:51 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+
 import org.hisp.dhis.document.Document;
 import org.hisp.dhis.mapping.MapView;
 import org.hisp.dhis.report.Report;
@@ -60,25 +62,50 @@
     @Override
     public void deleteReport( Report report )
     {
-        dashboardService.removeReportAssociations( report );
+        Collection<DashboardContent> contents = dashboardService.getByReport( report );
+        
+        for ( DashboardContent content : contents )
+        {
+            content.getReports().remove( report );
+            dashboardService.updateDashboardContent( content );
+        }
     }
             
     @Override
     public void deleteDocument( Document document )
     {
-        dashboardService.removeDocumentAssociations( document );
+        Collection<DashboardContent> contents = dashboardService.getByDocument( document );
+        
+        for ( DashboardContent content : contents )
+        {
+            content.getDocuments().remove( document );
+            dashboardService.updateDashboardContent( content );
+            
+        }
     }
     
     @Override
     public void deleteReportTable( ReportTable reportTable )
     {
-        dashboardService.removeReportTableAssociations( reportTable );
+        Collection<DashboardContent> contents = dashboardService.getByReportTable( reportTable );
+        
+        for ( DashboardContent content : contents )
+        {
+            content.getReportTables().remove( reportTable );
+            dashboardService.updateDashboardContent( content );
+        }        
     }
     
     @Override
     public void deleteMapView( MapView mapView )
     {
-        dashboardService.removeMapViewAssocations( mapView );
+        Collection<DashboardContent> contents = dashboardService.getByMapView( mapView );
+        
+        for ( DashboardContent content : contents )
+        {
+            content.getMapViews().remove( mapView );
+            dashboardService.updateDashboardContent( content );
+        }
     }
     
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardContentStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardContentStore.java	2012-07-01 07:33:25 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardContentStore.java	2012-07-03 21:19:51 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+
 import org.hisp.dhis.dashboard.DashboardContent;
 import org.hisp.dhis.dashboard.DashboardContentStore;
 import org.hisp.dhis.document.Document;
@@ -41,27 +43,31 @@
 public class HibernateDashboardContentStore
     extends HibernateGenericStore<DashboardContent> implements DashboardContentStore
 {
-    public void removeDocumentAssociations( Document document )
-    {
-        final String sql = "delete from dashboardcontent_documents where documentid = " + document.getId();
-        jdbcTemplate.execute( sql );
-    }
-    
-    public void removeMapViewAssocations( MapView mapView )
-    {
-        final String sql = "delete from dashboardcontent_mapviews where mapviewid = " + mapView.getId();
-        jdbcTemplate.execute( sql );
-    }
-    
-    public void removeReportAssociations( Report report )
-    {
-        final String sql = "delete from dashboardcontent_reports where reportid = " + report.getId();
-        jdbcTemplate.execute( sql );
-    }
-    
-    public void removeReportTableAssociations( ReportTable reportTable )
-    {
-        final String sql = "delete from dashboardcontent_reporttables where reporttableid = " + reportTable.getId();
-        jdbcTemplate.execute( sql );
+    @SuppressWarnings("unchecked")
+    public Collection<DashboardContent> getByDocument( Document document )
+    {
+        String hql = "from DashboardContent dc where :document in elements(dc.documents)";
+        return getQuery( hql ).setEntity( "document", document ).list();        
+    }
+
+    @SuppressWarnings("unchecked")
+    public Collection<DashboardContent> getByMapView( MapView mapView )
+    {
+        String hql = "from DashboardContent dc where :mapView in elements(dc.mapViews)";
+        return getQuery( hql ).setEntity( "mapView", mapView ).list();
+    }    
+
+    @SuppressWarnings("unchecked")
+    public Collection<DashboardContent> getByReport( Report report )
+    {
+        String hql = "from DashboardContent dc where :report in elements(dc.reports)";
+        return getQuery( hql ).setEntity( "report", report ).list();
+    }
+    
+    @SuppressWarnings("unchecked")
+    public Collection<DashboardContent> getByReportTable( ReportTable reportTable )
+    {
+        String hql = "from DashboardContent dc where :reportTable in elements(dc.reportTables)";
+        return getQuery( hql ).setEntity( "reportTable", reportTable ).list();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2012-07-01 07:33:25 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2012-07-03 21:19:51 +0000
@@ -68,7 +68,11 @@
         dashboardContentStore.save( dashboardContent );
     }
 
-    @Override
+    public void updateDashboardContent( DashboardContent dashboardContent )
+    {
+        dashboardContentStore.update( dashboardContent );
+    }
+    
     public DashboardContent getDashboardContent( int id )
     {
         return dashboardContentStore.get( id );
@@ -91,23 +95,23 @@
         dashboardContentStore.delete( content );
     }
     
-    public void removeDocumentAssociations( Document document )
-    {
-        dashboardContentStore.removeDocumentAssociations( document );
-    }
-    
-    public void removeMapViewAssocations( MapView mapView )
-    {
-        dashboardContentStore.removeMapViewAssocations( mapView );
-    }
-    
-    public void removeReportAssociations( Report report )
-    {
-        dashboardContentStore.removeReportAssociations( report );
-    }
-    
-    public void removeReportTableAssociations( ReportTable reportTable )
-    {
-        dashboardContentStore.removeReportTableAssociations( reportTable );
+    public Collection<DashboardContent> getByDocument( Document document )
+    {
+        return dashboardContentStore.getByDocument( document );
+    }
+    
+    public Collection<DashboardContent> getByMapView( MapView mapView )
+    {
+        return dashboardContentStore.getByMapView( mapView );
+    }
+    
+    public Collection<DashboardContent> getByReport( Report report )
+    {
+        return dashboardContentStore.getByReport( report );
+    }
+    
+    public Collection<DashboardContent> getByReportTable( ReportTable reportTable )
+    {
+        return dashboardContentStore.getByReportTable( reportTable );
     }
 }