← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16711: switch from all-delete-orphan to save-update cascade in dashboard.items, updated service/controll...

 

------------------------------------------------------------
revno: 16711
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-09-13 18:44:57 +0700
message:
  switch from all-delete-orphan to save-update cascade in dashboard.items, updated service/controller to do explicit delete of items
modified:
  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/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.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/dashboard/impl/DefaultDashboardService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2014-09-11 06:39:30 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2014-09-13 11:44:57 +0000
@@ -28,21 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_CHART;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_EVENT_CHART;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_MAP;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_MESSAGES;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORTS;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORT_TABLE;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORT_TABLES;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_RESOURCES;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_USERS;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
@@ -60,6 +45,12 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
+import static org.hisp.dhis.dashboard.DashboardItem.*;
+
 /**
  * Note: The remove associations methods must be altered if caching is introduced.
  *
@@ -177,7 +168,7 @@
             {
                 item.getResources().add( objectManager.get( Document.class, contentUid ) );
             }
-            
+
             if ( availableItem == null )
             {
                 dashboard.getItems().add( 0, item );
@@ -216,7 +207,7 @@
         {
             item.setEventChart( objectManager.get( EventChart.class, item.getEventChart().getUid() ) );
         }
-        
+
         if ( item.getMap() != null )
         {
             item.setMap( objectManager.get( Map.class, item.getMap().getUid() ) );
@@ -264,6 +255,11 @@
     public void deleteDashboard( Dashboard dashboard )
     {
         dashboardStore.delete( dashboard );
+
+        for ( DashboardItem dashboardItem : dashboard.getItems() )
+        {
+            dashboardItemStore.delete( dashboardItem );
+        }
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml	2014-06-17 10:29:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml	2014-09-13 11:44:57 +0000
@@ -17,7 +17,7 @@
 
     <property name="name" column="name" not-null="true" unique="false" length="230" />
 
-    <list name="items" table="dashboard_items" cascade="all-delete-orphan">
+    <list name="items" table="dashboard_items" cascade="save-update">
       <key column="dashboardid" foreign-key="fk_dashboard_items_dashboardid" />
       <list-index column="sort_order" base="0" />
       <many-to-many column="dashboarditemid" class="org.hisp.dhis.dashboard.DashboardItem"

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java	2014-08-12 05:22:04 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DashboardController.java	2014-09-13 11:44:57 +0000
@@ -34,11 +34,13 @@
 import org.hisp.dhis.dashboard.DashboardSearchResult;
 import org.hisp.dhis.dashboard.DashboardService;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import org.hisp.dhis.hibernate.exception.DeleteAccessDeniedException;
 import org.hisp.dhis.schema.descriptors.DashboardSchemaDescriptor;
 import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.hisp.dhis.webapi.webdomain.WebOptions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -50,6 +52,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.InputStream;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -59,15 +62,15 @@
  * @author Lars Helge Overland
  */
 @Controller
-@RequestMapping( value = DashboardSchemaDescriptor.API_ENDPOINT )
+@RequestMapping(value = DashboardSchemaDescriptor.API_ENDPOINT)
 public class DashboardController
     extends AbstractCrudController<Dashboard>
 {
     @Autowired
     private DashboardService dashboardService;
 
-    @RequestMapping( value = "/q/{query}", method = RequestMethod.GET )
-    public String search( @PathVariable String query, @RequestParam( required = false ) Set<String> max,
+    @RequestMapping(value = "/q/{query}", method = RequestMethod.GET)
+    public String search( @PathVariable String query, @RequestParam(required = false) Set<String> max,
         Model model, HttpServletResponse response ) throws Exception
     {
         DashboardSearchResult result = dashboardService.search( query, max );
@@ -78,7 +81,7 @@
     }
 
     @Override
-    @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
+    @RequestMapping(method = RequestMethod.POST, consumes = "application/json")
     public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
     {
         Dashboard dashboard = JacksonUtils.fromJson( input, Dashboard.class );
@@ -90,9 +93,9 @@
     }
 
     @Override
-    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
-    @ResponseStatus( value = HttpStatus.NO_CONTENT )
-    public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
+    @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json")
+    @ResponseStatus(value = HttpStatus.NO_CONTENT)
+    public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream input ) throws Exception
     {
         Dashboard dashboard = dashboardService.getDashboard( uid );
 
@@ -109,6 +112,27 @@
         dashboardService.updateDashboard( dashboard );
     }
 
+    @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid )
+        throws Exception
+    {
+        List<Dashboard> objects = getEntity( uid );
+
+        if ( objects.isEmpty() )
+        {
+            ContextUtils.conflictResponse( response, getEntityName() + " does not exist: " + uid );
+            return;
+        }
+
+        if ( !aclService.canDelete( currentUserService.getCurrentUser(), objects.get( 0 ) ) )
+        {
+            throw new DeleteAccessDeniedException( "You don't have the proper permissions to delete this object." );
+        }
+
+        dashboardService.deleteDashboard( objects.get( 0 ) );
+    }
+
     @RequestMapping( value = "/{uid}/items", method = RequestMethod.POST, consumes = "application/json" )
     public void postJsonItem( HttpServletResponse response, HttpServletRequest request,
         InputStream input, @PathVariable String uid ) throws Exception