dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23587
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11488: Impl DELETE of dashboards in web api
------------------------------------------------------------
revno: 11488
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-07-23 12:10:48 +0200
message:
Impl DELETE of dashboards in web api
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/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-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java 2013-07-23 09:55:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java 2013-07-23 10:10:48 +0000
@@ -33,6 +33,7 @@
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.document.Document;
import org.hisp.dhis.mapping.Map;
import org.hisp.dhis.report.Report;
@@ -195,4 +196,26 @@
{
this.resources = resources;
}
+
+ // -------------------------------------------------------------------------
+ // Merge with
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void mergeWith( IdentifiableObject other )
+ {
+ super.mergeWith( other );
+
+ if ( other.getClass().isInstance( this ) )
+ {
+ DashboardItem item = (DashboardItem) other;
+
+ chart = item.getChart() == null ? chart : item.getChart();
+ map = item.getMap() == null ? map : item.getMap();
+ users = item.getUsers() == null ? users : item.getUsers();
+ reportTables = item.getReportTables() == null ? reportTables : item.getReportTables();
+ reports = item.getReports() == null ? reports : item.getReports();
+ resources = item.getResources() == null ? resources : item.getResources();
+ }
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java 2013-07-23 09:55:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java 2013-07-23 10:10:48 +0000
@@ -39,12 +39,14 @@
import org.hisp.dhis.dashboard.DashboardService;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
/**
* @author Lars Helge Overland
@@ -83,9 +85,40 @@
ContextUtils.createdResponse( response, "Dashboard created", RESOURCE_PATH + "/" + dashboard.getUid() );
}
+
+ @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
+ {
+ Dashboard dashboard = dashboardService.getDashboard( uid );
+
+ if ( dashboard == null )
+ {
+ ContextUtils.notFoundResponse( response, "Dashboard does not exist: " + uid );
+ return;
+ }
+
+ Dashboard newDashboard = JacksonUtils.fromJson( input, Dashboard.class );
+
+ dashboard.setName( newDashboard.getName() ); // TODO Name only for now
+
+ dashboardService.updateDashboard( dashboard );
+ }
+
+ @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
+ @ResponseStatus( value = HttpStatus.NO_CONTENT )
+ public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws Exception
+ {
+ Dashboard dashboard = dashboardService.getDashboard( uid );
+
+ dashboardService.deleteDashboard( dashboard );
+
+ ContextUtils.okResponse( response, "Dashboard deleted" );
+ }
@RequestMapping( value = "/{uid}/items", method = RequestMethod.POST, consumes = "application/json" )
- public void addItem( HttpServletResponse response, HttpServletRequest request,
+ public void postJsonItem( HttpServletResponse response, HttpServletRequest request,
InputStream input, @PathVariable String uid ) throws Exception
{
Dashboard dashboard = dashboardService.getDashboard( uid );