← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8285: Added method to report resource in web api which allows for updating the design content of a repo...

 

------------------------------------------------------------
revno: 8285
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-09-27 11:28:54 +0200
message:
  Added method to report resource in web api which allows for updating the design content of a report. Added a script that allows you to put the content of a jrxml/ireport file to the API, this means that you can update the report directly avoiding update file-save-reload report routine.
added:
  resources/util/putdesign.sh
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2012-06-10 15:48:16 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2012-09-27 09:28:54 +0000
@@ -515,7 +515,8 @@
             {
                 addHeader( new GridHeader( rsmd.getColumnLabel( i ), false, false ) );
             }
-        } catch ( SQLException ex )
+        } 
+        catch ( SQLException ex )
         {
             throw new RuntimeException( ex );
         }
@@ -538,7 +539,8 @@
                     addValue( rs.getObject( i ) );
                 }
             }
-        } catch ( SQLException ex )
+        } 
+        catch ( SQLException ex )
         {
             throw new RuntimeException( ex );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java	2012-09-24 12:52:15 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportController.java	2012-09-27 09:28:54 +0000
@@ -42,6 +42,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -86,6 +87,23 @@
     {
         getReport( uid, organisationUnitUid, period, response, "xls", ContextUtils.CONTENT_TYPE_EXCEL, true );
     }
+    
+    @RequestMapping( value = "/{uid}/design", method = RequestMethod.PUT )
+    public void updateReportDesign( @PathVariable( "uid" ) String uid, 
+        @RequestBody String designContent,
+        HttpServletResponse response ) throws Exception
+    {
+        Report report = reportService.getReport( uid );
+        
+        if ( report == null )
+        {
+            ContextUtils.notFoundResponse( response, "Report not found for identifier: " + uid );
+            return;
+        }
+        
+        report.setDesignContent( designContent );        
+        reportService.saveReport( report );
+    }
 
     // -------------------------------------------------------------------------
     // Supportive methods

=== added file 'resources/util/putdesign.sh'
--- resources/util/putdesign.sh	1970-01-01 00:00:00 +0000
+++ resources/util/putdesign.sh	2012-09-27 09:28:54 +0000
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# Requires cURL
+
+# Set these variables to your environment
+
+REPORT_UID="MoIMRSiNqHR" # UID on server, look up in Web API
+REPORT_FILENAME="report.jrxml" # On filesystem in same directory
+BASE_URL="http://localhost:8080"; # To DHIS instance
+USER="admin" # DHIS username
+PWD="Admin123" # DHIS password
+
+# Constants, do not change
+
+URL="${BASE_URL}/api/reports/${REPORT_UID}/design"
+
+echo "Using URL: ${URL}"
+
+# PUT to server
+
+`curl -d @${REPORT_FILENAME} "${URL}" -H "Content-Type:application/xml" -u ${USER}:${PWD} -X PUT -v`
+
+echo "Done"