dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17940
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7349: made meta-data export controller a bit more robust
------------------------------------------------------------
revno: 7349
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-06-22 18:40:52 +0300
message:
made meta-data export controller a bit more robust
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml
--
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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-06-06 12:57:47 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-06-22 15:40:52 +0000
@@ -48,12 +48,11 @@
import java.util.Map;
import java.util.zip.*;
-import static org.hisp.dhis.api.utils.ContextUtils.*;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Controller
+@RequestMapping( method = RequestMethod.GET )
public class MetaDataController
{
public static final String RESOURCE_PATH = "/metaData";
@@ -71,7 +70,7 @@
// Export
//--------------------------------------------------------------------------
- @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.GET )
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH )
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
public String export( @RequestParam Map<String, String> parameters, Model model )
{
@@ -84,39 +83,51 @@
return "export";
}
- @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".xml", method = RequestMethod.GET, produces = { "application/xml", "text/*" } )
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".xml", produces = "*/*" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
public void exportXml( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
{
WebOptions options = new WebOptions( parameters );
MetaData metaData = exportService.getMetaData( options );
- contextUtils.configureResponse( response, CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, "metaData.xml", true );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, "metaData.xml", true );
JacksonUtils.toXmlWithView( response.getOutputStream(), metaData, ExportView.class );
}
- @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".json", method = RequestMethod.GET, produces = { "application/json" } )
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".json", produces = "*/*" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
public void exportJson( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
{
WebOptions options = new WebOptions( parameters );
MetaData metaData = exportService.getMetaData( options );
- contextUtils.configureResponse( response, CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE, "metaData.json", true );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE, "metaData.json", true );
JacksonUtils.toXmlWithView( response.getOutputStream(), metaData, ExportView.class );
}
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".xml.zip" }, method = RequestMethod.GET, produces = { "application/xml", "text/*" } )
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip" }, produces = "*/*" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void exportZipped( @RequestParam Map<String, String> parameters, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ if ( request.getHeader( "Accept" ).equalsIgnoreCase( "application/json" ) )
+ {
+ exportZippedJSON( parameters, response );
+ }
+
+ exportZippedXML( parameters, response );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".xml.zip" }, produces = "*/*" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
public void exportZippedXML( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
{
WebOptions options = new WebOptions( parameters );
MetaData metaData = exportService.getMetaData( options );
- contextUtils.configureResponse( response, CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metaData.xml.zip", true );
- response.addHeader( HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metaData.xml.zip", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
zip.putNextEntry( new ZipEntry( "metaData.xml" ) );
@@ -124,15 +135,15 @@
JacksonUtils.toXmlWithView( zip, metaData, ExportView.class );
}
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".json.zip" }, method = RequestMethod.GET, produces = "application/json" )
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".json.zip" }, produces = "*/*" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
public void exportZippedJSON( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
{
WebOptions options = new WebOptions( parameters );
MetaData metaData = exportService.getMetaData( options );
- contextUtils.configureResponse( response, CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metaData.json.zip", true );
- response.addHeader( HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metaData.json.zip", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
zip.putNextEntry( new ZipEntry( "metaData.json" ) );
@@ -140,29 +151,41 @@
JacksonUtils.toJsonWithView( zip, metaData, ExportView.class );
}
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".xml.gz" }, method = RequestMethod.GET, produces = { "application/xml", " text/*" } )
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz" }, produces = "*/*" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void exportGZipped( @RequestParam Map<String, String> parameters, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ if ( request.getHeader( "Accept" ).equalsIgnoreCase( "application/json" ) )
+ {
+ exportGZippedJSON( parameters, response );
+ }
+
+ exportGZippedXML( parameters, response );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".xml.gz" }, produces = "*/*" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
public void exportGZippedXML( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
{
WebOptions options = new WebOptions( parameters );
MetaData metaData = exportService.getMetaData( options );
- contextUtils.configureResponse( response, CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metaData.xml.gz", true );
- response.addHeader( HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metaData.xml.gz", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
JacksonUtils.toXmlWithView( gzip, metaData, ExportView.class );
}
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".json.gz"} , method = RequestMethod.GET, produces = { "application/json" } )
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".json.gz" }, method = RequestMethod.GET, produces = "*/*" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
public void exportGZippedJSON( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
{
WebOptions options = new WebOptions( parameters );
MetaData metaData = exportService.getMetaData( options );
- contextUtils.configureResponse( response, CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metaData.json.gz", true );
- response.addHeader( HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metaData.json.gz", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
JacksonUtils.toJsonWithView( gzip, metaData, ExportView.class );
@@ -241,7 +264,7 @@
JacksonUtils.toXml( response.getOutputStream(), summary );
}
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".json.gz"}, method = RequestMethod.POST, consumes = "application/json" )
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".json.gz" }, method = RequestMethod.POST, consumes = "application/json" )
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
public void importGZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
{
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2012-03-28 12:18:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2012-06-22 15:40:52 +0000
@@ -25,9 +25,9 @@
<property name="order" value="1" />
<property name="mediaTypes">
<map>
+ <entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
<entry key="jsonp" value="application/javascript" />
- <entry key="xml" value="application/xml" />
<entry key="html" value="text/html" />
<entry key="png" value="image/png" />
</map>