← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13222: check for dashboarditem.reports/resources/reportTables in deletionhandlers/stores

 

------------------------------------------------------------
revno: 13222
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-12-13 13:47:24 +0100
message:
  check for dashboarditem.reports/resources/reportTables in deletionhandlers/stores
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.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/DashboardItemDeletionHandler.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.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/DashboardItemStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.java	2013-12-13 12:02:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemStore.java	2013-12-13 12:47:24 +0000
@@ -30,7 +30,9 @@
 
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.document.Document;
 import org.hisp.dhis.mapping.Map;
+import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportTable;
 
 /**
@@ -44,4 +46,8 @@
     int countChartDashboardItems( Chart chart );
 
     int countReportTableDashboardItems( ReportTable reportTable );
+
+    int countReportDashboardItems( Report report );
+
+    int countDocumentDashboardItems( Document document );
 }

=== 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	2013-12-13 12:02:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2013-12-13 12:47:24 +0000
@@ -1,8 +1,10 @@
 package org.hisp.dhis.dashboard;
 
 import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.document.Document;
 import org.hisp.dhis.interpretation.Interpretation;
 import org.hisp.dhis.mapping.Map;
+import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.user.User;
 
@@ -72,4 +74,8 @@
     int countChartDashboardItems( Chart chart );
 
     int countReportTableDashboardItems( ReportTable reportTable );
+
+    int countReportDashboardItems( Report report );
+
+    int countDocumentDashboardItems( Document document );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardItemDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardItemDeletionHandler.java	2013-12-13 12:02:13 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/DashboardItemDeletionHandler.java	2013-12-13 12:47:24 +0000
@@ -29,7 +29,9 @@
  */
 
 import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.document.Document;
 import org.hisp.dhis.mapping.Map;
+import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -65,4 +67,16 @@
     {
         return dashboardService.countReportTableDashboardItems( reportTable ) == 0 ? null : ERROR;
     }
+
+    @Override
+    public String allowDeleteReport( Report report )
+    {
+        return dashboardService.countReportDashboardItems( report ) == 0 ? null : ERROR;
+    }
+
+    @Override
+    public String allowDeleteDocument( Document document )
+    {
+        return dashboardService.countDocumentDashboardItems( document ) == 0 ? null : ERROR;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java	2013-12-13 12:02:13 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/hibernate/HibernateDashboardItemStore.java	2013-12-13 12:47:24 +0000
@@ -33,7 +33,9 @@
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.dashboard.DashboardItem;
 import org.hisp.dhis.dashboard.DashboardItemStore;
+import org.hisp.dhis.document.Document;
 import org.hisp.dhis.mapping.Map;
+import org.hisp.dhis.report.Report;
 import org.hisp.dhis.reporttable.ReportTable;
 
 /**
@@ -45,7 +47,7 @@
     @Override
     public int countMapDashboardItems( Map map )
     {
-        Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where c.map=:map" );
+        Query query = getQuery( "select count(distinct c) from DashboardItem c where c.map=:map" );
         query.setEntity( "map", map );
 
         return ((Long) query.uniqueResult()).intValue();
@@ -54,7 +56,7 @@
     @Override
     public int countChartDashboardItems( Chart chart )
     {
-        Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where c.chart=:chart" );
+        Query query = getQuery( "select count(distinct c) from DashboardItem c where c.chart=:chart" );
         query.setEntity( "chart", chart );
 
         return ((Long) query.uniqueResult()).intValue();
@@ -63,9 +65,28 @@
     @Override
     public int countReportTableDashboardItems( ReportTable reportTable )
     {
-        Query query = getQuery( "select count(distinct c) from " + clazz.getName() + " c where c.reportTable=:reportTable" );
+        Query query = getQuery( "select count(distinct c) from DashboardItem c where c.reportTable=:reportTable" +
+            " or :reportTable in elements(c.reportTables)" );
         query.setEntity( "reportTable", reportTable );
 
         return ((Long) query.uniqueResult()).intValue();
     }
+
+    @Override
+    public int countReportDashboardItems( Report report )
+    {
+        Query query = getQuery( "select count(distinct c) from DashboardItem c where :report in elements(c.reports)" );
+        query.setEntity( "report", report );
+
+        return ((Long) query.uniqueResult()).intValue();
+    }
+
+    @Override
+    public int countDocumentDashboardItems( Document document )
+    {
+        Query query = getQuery( "select count(distinct c) from DashboardItem c where :document in elements(c.resources)" );
+        query.setEntity( "document", document );
+
+        return ((Long) query.uniqueResult()).intValue();
+    }
 }

=== 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	2013-12-13 12:02:13 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2013-12-13 12:47:24 +0000
@@ -288,6 +288,18 @@
         return dashboardItemStore.countReportTableDashboardItems( reportTable );
     }
 
+    @Override
+    public int countReportDashboardItems( Report report )
+    {
+        return dashboardItemStore.countReportDashboardItems( report );
+    }
+
+    @Override
+    public int countDocumentDashboardItems( Document document )
+    {
+        return dashboardItemStore.countDocumentDashboardItems( document );
+    }
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------