dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20508
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9383: Analytics, more formats
------------------------------------------------------------
revno: 9383
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-12-21 10:56:32 +0100
message:
Analytics, more formats
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2012-12-18 16:01:44 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2012-12-21 09:56:32 +0000
@@ -54,34 +54,79 @@
@Autowired
private ContextUtils contextUtils;
- @RequestMapping( method = RequestMethod.GET, consumes = { "application/json" }, produces = { "application/json" } )
- public String getJson( InputStream in,
+ //TODO URL only requests
+
+ @RequestMapping( method = RequestMethod.GET, consumes = { "application/json" }, produces = { "application/json", "application/javascript" } )
+ public String getJson( InputStream in, // JSON, JSONP
Model model,
HttpServletResponse response ) throws Exception
{
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE ); //TODO
-
DataQueryParams params = JacksonUtils.fromJson( in, DataQueryParams.class );
- Grid grid = analyticsService.getAggregatedDataValues( params );
+ if ( params == null || params.getDimensions().isEmpty() )
+ {
+ ContextUtils.conflictResponse( response, "At least one dimension must be specified" );
+ return null;
+ }
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE ); //TODO
+ Grid grid = analyticsService.getAggregatedDataValues( params );
model.addAttribute( "model", grid );
- model.addAttribute( "viewClass", "detailed" );
-
+ model.addAttribute( "viewClass", "detailed" );
return "grid";
}
- @RequestMapping( method = RequestMethod.GET, consumes = { "application/json" }, produces = { "application/xml" } )
+ @RequestMapping( method = RequestMethod.GET, consumes = { "application/json" } )
public void getXml( InputStream in,
Model model,
HttpServletResponse response ) throws Exception
{
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE ); //TODO
-
DataQueryParams params = JacksonUtils.fromJson( in, DataQueryParams.class );
+
+ if ( params == null || params.getDimensions().isEmpty() )
+ {
+ ContextUtils.conflictResponse( response, "At least one dimension must be specified" );
+ return;
+ }
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE ); //TODO
Grid grid = analyticsService.getAggregatedDataValues( params );
-
GridUtils.toXml( grid, response.getOutputStream() );
}
+
+ @RequestMapping( method = RequestMethod.GET, consumes = { "application/json" } )
+ public void getCsv( InputStream in,
+ Model model,
+ HttpServletResponse response ) throws Exception
+ {
+ DataQueryParams params = JacksonUtils.fromJson( in, DataQueryParams.class );
+
+ if ( params == null || params.getDimensions().isEmpty() )
+ {
+ ContextUtils.conflictResponse( response, "At least one dimension must be specified" );
+ return;
+ }
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.NO_CACHE ); //TODO
+ Grid grid = analyticsService.getAggregatedDataValues( params );
+ GridUtils.toCsv( grid, response.getOutputStream() );
+ }
+
+ @RequestMapping( method = RequestMethod.GET, consumes = { "application/json" } )
+ public void getHtml( InputStream in,
+ Model model,
+ HttpServletResponse response ) throws Exception
+ {
+ DataQueryParams params = JacksonUtils.fromJson( in, DataQueryParams.class );
+
+ if ( params == null || params.getDimensions().isEmpty() )
+ {
+ ContextUtils.conflictResponse( response, "At least one dimension must be specified" );
+ return;
+ }
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.NO_CACHE ); //TODO
+ Grid grid = analyticsService.getAggregatedDataValues( params );
+ GridUtils.toHtml( grid, response.getWriter() );
+ }
}