← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9912: Web API, impl PUT and DELETE of report table

 

------------------------------------------------------------
revno: 9912
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-02-27 11:13:13 +0100
message:
  Web API, impl PUT and DELETE of report table
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.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/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2013-02-26 19:53:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2013-02-27 10:13:13 +0000
@@ -225,6 +225,7 @@
     /**
      * The list of DataElementGroups the ReportTable contains.
      */
+    @Scanned
     private List<DataElementGroup> dataElementGroups = new ArrayList<DataElementGroup>();
     
     /**
@@ -304,8 +305,14 @@
     // Presentation properties
     // -------------------------------------------------------------------------
 
+    /**
+     * Map of data element group set uids and data element groups.
+     */
     private Map<String, List<DataElementGroup>> dataElementGroupSets = new HashMap<String, List<DataElementGroup>>();
     
+    /**
+     * Map of organisation unit group uids and organisation unit groups.
+     */
     private Map<String, List<OrganisationUnitGroup>> organisationUnitGroupSets = new HashMap<String, List<OrganisationUnitGroup>>();
     
     // -------------------------------------------------------------------------
@@ -864,6 +871,11 @@
         organisationUnits.clear();
     }
 
+    public void removeAllDataElementGroups()
+    {
+        dataElementGroups.clear();
+    }
+    
     public void removeAllOrganisationUnitGroups()
     {
         organisationUnitGroups.clear();
@@ -1325,9 +1337,9 @@
     // Get- and set-methods for presentation properties
     // -------------------------------------------------------------------------
 
-    @JsonProperty
+    @JsonProperty( value = "dataElementGroupSets" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
     @JsonView( {DetailedView.class, ExportView.class} )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public Map<String, List<DataElementGroup>> getDataElementGroupSets()
     {
         return dataElementGroupSets;
@@ -1338,9 +1350,9 @@
         this.dataElementGroupSets = dataElementGroupSets;
     }
 
-    @JsonProperty
+    @JsonProperty( value = "organisationUnitGroupSets" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
     @JsonView( {DetailedView.class, ExportView.class} )
-    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public Map<String, List<OrganisationUnitGroup>> getOrganisationUnitGroupSets()
     {
         return organisationUnitGroupSets;
@@ -1499,9 +1511,20 @@
             reportParams = reportTable.getReportParams() == null ? reportParams : reportTable.getReportParams();
             sortOrder = reportTable.getSortOrder() == null ? sortOrder : reportTable.getSortOrder();
             topLimit = reportTable.getTopLimit() == null ? topLimit : reportTable.getTopLimit();
-
-            removeAllOrganisationUnitGroups();
-            organisationUnitGroups.addAll( reportTable.getOrganisationUnitGroups() );
+            subtotals = reportTable.isSubtotals();
+            displayDensity = reportTable.getDisplayDensity();
+            fontSize = reportTable.getFontSize();
+            userOrganisationUnit = reportTable.isUserOrganisationUnit();
+            userOrganisationUnitChildren = reportTable.isUserOrganisationUnitChildren();
+
+            removeAllDataElements();
+            dataElements.addAll( reportTable.getDataElements() );
+
+            removeAllIndicators();
+            indicators.addAll( reportTable.getIndicators() );
+
+            removeAllDataSets();
+            dataSets.addAll( reportTable.getDataSets() );
 
             removeAllOrganisationUnits();
             organisationUnits.addAll( reportTable.getOrganisationUnits() );
@@ -1509,14 +1532,11 @@
             removeAllPeriods();
             periods.addAll( reportTable.getPeriods() );
 
-            removeAllDataSets();
-            dataSets.addAll( reportTable.getDataSets() );
-
-            removeAllIndicators();
-            indicators.addAll( reportTable.getIndicators() );
-
-            removeAllDataElements();
-            dataElements.addAll( reportTable.getDataElements() );
+            removeAllDataElementGroups();
+            dataElementGroups.addAll( reportTable.getDataElementGroups() );
+            
+            removeAllOrganisationUnitGroups();
+            organisationUnitGroups.addAll( reportTable.getOrganisationUnitGroups() );
         }
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2013-02-26 20:18:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java	2013-02-27 10:13:13 +0000
@@ -62,12 +62,14 @@
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.user.UserService;
 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 Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -116,6 +118,7 @@
     // CRUD
     //--------------------------------------------------------------------------
 
+    @Override
     @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
     public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
     {
@@ -131,6 +134,46 @@
     }
     
     @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
+    {
+        ReportTable reportTable = reportTableService.getReportTable( uid );
+        
+        if ( reportTable == null )
+        {
+            ContextUtils.notFoundResponse( response, "Report table does not exist: " + uid );
+            return;
+        }        
+
+        ReportTable newReportTable = JacksonUtils.fromJson( input, ReportTable.class );
+        
+        newReportTable.readPresentationProps();
+        
+        mergeReportTable( newReportTable );
+
+        reportTable.mergeWith( newReportTable );
+        
+        reportTableService.updateReportTable( reportTable );
+    }
+    
+    @Override
+    @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws Exception
+    {
+        ReportTable reportTable = reportTableService.getReportTable( uid );
+        
+        if ( reportTable == null )
+        {
+            ContextUtils.notFoundResponse( response, "Report table does not exist: " + uid );
+            return;
+        }
+        
+        reportTableService.deleteReportTable( reportTable );
+    }
+    
+    @Override
     protected void postProcessEntity( ReportTable reportTable )
     {
         reportTable.populatePresentationProps();
@@ -414,8 +457,6 @@
     // Supportive methods
     //--------------------------------------------------------------------------
 
-    // TODO use generic import service
-    
     private void mergeReportTable( ReportTable reportTable )
     {
         reportTable.setDataElements( dataElementService.getDataElementsByUid( getUids( reportTable.getDataElements() ) ) );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java	2012-11-03 14:18:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/mapping/MapController.java	2013-02-27 10:13:13 +0000
@@ -92,6 +92,7 @@
     // CRUD
     //--------------------------------------------------------------------------
 
+    @Override
     @RequestMapping( method = RequestMethod.POST, consumes = "application/json" )
     @PreAuthorize( "hasRole('F_GIS_ADMIN') or hasRole('ALL')" )
     public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
@@ -111,7 +112,8 @@
         
         ContextUtils.createdResponse( response, "Map created", RESOURCE_PATH + "/" + map.getUid() );
     }
-    
+
+    @Override
     @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
     @ResponseStatus( value = HttpStatus.NO_CONTENT )
     @PreAuthorize( "hasRole('F_GIS_ADMIN') or hasRole('ALL')" )
@@ -154,7 +156,8 @@
         
         mappingService.updateMap( map );
     }
-    
+
+    @Override
     @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
     @ResponseStatus( value = HttpStatus.NO_CONTENT )
     @PreAuthorize( "hasRole('F_GIS_ADMIN') or hasRole('ALL')" )