=== 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 { - void removeDocumentAssociations( Document document ); - - void removeMapViewAssocations( MapView mapView ); - - void removeReportAssociations( Report report ); - - void removeReportTableAssociations( ReportTable reportTable ); + Collection getByDocument( Document document ); + + Collection getByMapView( MapView mapView ); + + Collection getByReport( Report report ); + + Collection 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 getAllDashboardContent(); void deleteDashboardContent( DashboardContent content ); - - void removeDocumentAssociations( Document document ); - - void removeMapViewAssocations( MapView mapView ); - - void removeReportAssociations( Report report ); - - void removeReportTableAssociations( ReportTable reportTable ); + + Collection getByDocument( Document document ); + + Collection getByMapView( MapView mapView ); + + Collection getByReport( Report report ); + + Collection 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 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 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 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 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 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 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 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 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 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 getByDocument( Document document ) + { + return dashboardContentStore.getByDocument( document ); + } + + public Collection getByMapView( MapView mapView ) + { + return dashboardContentStore.getByMapView( mapView ); + } + + public Collection getByReport( Report report ) + { + return dashboardContentStore.getByReport( report ); + } + + public Collection getByReportTable( ReportTable reportTable ) + { + return dashboardContentStore.getByReportTable( reportTable ); } }