=== 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 @@ - + { @Autowired private DashboardService dashboardService; - @RequestMapping( value = "/q/{query}", method = RequestMethod.GET ) - public String search( @PathVariable String query, @RequestParam( required = false ) Set max, + @RequestMapping(value = "/q/{query}", method = RequestMethod.GET) + public String search( @PathVariable String query, @RequestParam(required = false) Set 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 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