dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14008
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4607: Added ChartResource to web api
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4607 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-09-16 18:05:52 +0200
message:
Added ChartResource to web api
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java
modified:
dhis-2/dhis-web/dhis-web-api/pom.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.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/pom.xml'
--- dhis-2/dhis-web/dhis-web-api/pom.xml 2011-09-02 10:40:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/pom.xml 2011-09-16 15:59:35 +0000
@@ -72,6 +72,10 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-reporting</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-support-test</artifactId>
<scope>test</scope>
</dependency>
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java 2011-09-16 15:59:35 +0000
@@ -0,0 +1,53 @@
+package org.hisp.dhis.web.api.resources;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.StreamingOutput;
+
+import org.hisp.dhis.chart.ChartService;
+import org.hisp.dhis.i18n.I18nManager;
+import org.hisp.dhis.util.ContextUtils;
+import org.jfree.chart.ChartUtilities;
+import org.jfree.chart.JFreeChart;
+
+@Path( "/chart/{id}" )
+public class ChartResource
+{
+ private ChartService chartService;
+
+ public void setChartService( ChartService chartService )
+ {
+ this.chartService = chartService;
+ }
+
+ private I18nManager i18nManager;
+
+ public void setI18nManager( I18nManager manager )
+ {
+ i18nManager = manager;
+ }
+
+ @GET
+ @Produces( ContextUtils.CONTENT_TYPE_PNG )
+ public StreamingOutput getChart( @PathParam("id") Integer id )
+ throws Exception
+ {
+ final JFreeChart chart = chartService.getJFreeChart( id, i18nManager.getI18nFormat() );
+
+ return new StreamingOutput()
+ {
+ @Override
+ public void write( OutputStream out )
+ throws IOException, WebApplicationException
+ {
+ ChartUtilities.writeChartAsPNG( out, chart, 600, 400 );
+ }
+ };
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java 2011-09-16 10:44:02 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java 2011-09-16 15:59:35 +0000
@@ -20,6 +20,7 @@
import org.hisp.dhis.importexport.dxf2.model.DataSetLinks;
import org.hisp.dhis.importexport.dxf2.service.LinkBuilder;
import org.hisp.dhis.importexport.dxf2.service.LinkBuilderImpl;
+import org.hisp.dhis.util.ContextUtils;
import org.hisp.dhis.web.api.UrlResourceListener;
import org.springframework.beans.factory.annotation.Required;
@@ -40,14 +41,14 @@
this.dataSetService = dataSetService;
}
+ private VelocityManager velocityManager;
+
@Required
public void setVelocityManager( VelocityManager velocityManager )
{
this.velocityManager = velocityManager;
}
- private VelocityManager velocityManager;
-
private LinkBuilder linkBuilder = new LinkBuilderImpl();
@Context
@@ -67,7 +68,7 @@
}
@GET
- @Produces( { "application/javascript" } )
+ @Produces( ContextUtils.CONTENT_TYPE_JAVASCRIPT )
public JSONWithPadding getDataSets( @QueryParam( "callback" ) @DefaultValue( "callback" )
String callback )
{
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-09-16 13:47:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-09-16 16:05:52 +0000
@@ -37,6 +37,14 @@
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
</bean>
+ <bean id="org.hisp.dhis.web.api.resources.ChartResource" class="org.hisp.dhis.web.api.resources.ChartResource"
+ scope="prototype">
+ <property name="chartService" ref="org.hisp.dhis.chart.ChartService"/>
+ <property name="i18nManager" ref="org.hisp.dhis.i18n.I18nManager"/>
+ </bean>
+
+ <!-- Marshallers -->
+
<bean id="JacksonJaxbJsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" scope="singleton" />
<!-- ImportDataValue -->
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java 2011-05-05 21:15:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java 2011-09-16 15:59:35 +0000
@@ -52,6 +52,7 @@
public static final String CONTENT_TYPE_CSV = "application/csv";
public static final String CONTENT_TYPE_PNG = "image/png";
public static final String CONTENT_TYPE_EXCEL = "application/vnd.ms-excel";
+ public static final String CONTENT_TYPE_JAVASCRIPT = "application/javascript";
private static final String SEPARATOR = "/";
private static final String PORT_SEPARATOR = ":";