dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13995
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4601: made api render jsonp when .jsonp extensio is used
------------------------------------------------------------
revno: 4601
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-09-16 12:22:02 +0200
message:
made api render jsonp when .jsonp extensio is used
removed:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResourceP.java
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.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/web/api/HtmlPromotingUriConnegFilter.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java 2011-09-12 08:29:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java 2011-09-16 10:22:02 +0000
@@ -21,6 +21,7 @@
mediaExtentions.put( "xml", MediaType.APPLICATION_XML_TYPE );
mediaExtentions.put( "html", MediaType.TEXT_HTML_TYPE );
mediaExtentions.put( "json", MediaType.APPLICATION_JSON_TYPE );
+ mediaExtentions.put( "jsonp", new MediaType( "application", "javascript" ) );
}
public HtmlPromotingUriConnegFilter()
@@ -33,16 +34,16 @@
{
String accept = request.getHeaderValue( ACCEPT );
- if ( accept == null || accept.trim().isEmpty())
+ if ( accept == null || accept.trim().isEmpty() )
{
request.getRequestHeaders().putSingle( ACCEPT, MediaType.TEXT_HTML );
}
- else
+ else
{
- accept = preferHtml(accept);
+ accept = preferHtml( accept );
request.getRequestHeaders().putSingle( ACCEPT, accept );
- }
-
+ }
+
request = super.filter( request );
return request;
@@ -71,7 +72,7 @@
}
int end = accept.indexOf( ',', i );
-
+
if ( end != -1 )
{
if ( result.equals( "" ) )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 2011-09-13 11:10:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 2011-09-16 10:22:02 +0000
@@ -1,9 +1,11 @@
package org.hisp.dhis.web.api.resources;
+import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
@@ -14,16 +16,38 @@
import org.hisp.dhis.web.api.UrlResourceListener;
import org.springframework.beans.factory.annotation.Required;
+import com.sun.jersey.api.json.JSONWithPadding;
+
@Path( "dataSets/{uuid}" )
public class DataSetResource
{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
private DataSetService dataSetService;
+ @Required
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
+ @Required
+ public void setVelocityManager( VelocityManager velocityManager )
+ {
+ this.velocityManager = velocityManager;
+ }
+
private VelocityManager velocityManager;
@Context
private UriInfo uriInfo;
+ // -------------------------------------------------------------------------
+ // JSONP
+ // -------------------------------------------------------------------------
+
@GET
@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } )
public org.hisp.dhis.importexport.dxf2.model.DataSet getDataSetXml( @PathParam( "uuid" ) String uuid )
@@ -41,6 +65,23 @@
}
@GET
+ @Produces( { "application/javascript" } )
+ public JSONWithPadding getDataSet( @PathParam("uuid") String uuid, @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
+ {
+ DataSet dataSet = dataSetService.getDataSet( uuid );
+
+ if ( dataSet == null )
+ {
+ throw new IllegalArgumentException( "No dataset with uuid " + uuid );
+ }
+
+ org.hisp.dhis.importexport.dxf2.model.DataSet dxfDataSet = new DataSetMapper().convert( dataSet );
+ new UrlResourceListener( uriInfo ).beforeMarshal( dxfDataSet );
+
+ return new JSONWithPadding( dxfDataSet, callback );
+ }
+
+ @GET
@Produces( MediaType.TEXT_HTML )
public String getDataSet( @PathParam( "uuid" ) String uuid )
{
@@ -50,19 +91,7 @@
{
throw new IllegalArgumentException( "No dataset with uuid " + uuid );
}
-
+
return velocityManager.render( dataSet, "dataSet" );
}
-
- @Required
- public void setDataSetService( DataSetService dataSetService )
- {
- this.dataSetService = dataSetService;
- }
-
- @Required
- public void setVelocityManager( VelocityManager velocityManager )
- {
- this.velocityManager = velocityManager;
- }
}
=== 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-13 11:10:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java 2011-09-16 10:22:02 +0000
@@ -1,12 +1,21 @@
package org.hisp.dhis.web.api.resources;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.importexport.dxf2.model.DataSetLinks;
import org.hisp.dhis.importexport.dxf2.service.LinkBuilder;
@@ -14,27 +23,74 @@
import org.hisp.dhis.web.api.UrlResourceListener;
import org.springframework.beans.factory.annotation.Required;
+import com.sun.jersey.api.json.JSONWithPadding;
+
@Path( "dataSets" )
public class DataSetsResource
{
- private LinkBuilder linkBuilder = new LinkBuilderImpl();
-
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
private DataSetService dataSetService;
+ @Required
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
+ @Required
+ public void setVelocityManager( VelocityManager velocityManager )
+ {
+ this.velocityManager = velocityManager;
+ }
+
private VelocityManager velocityManager;
+ private LinkBuilder linkBuilder = new LinkBuilderImpl();
+
@Context
private UriInfo uriInfo;
+ // -------------------------------------------------------------------------
+ // JSONP
+ // -------------------------------------------------------------------------
+
@GET
@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } )
- public DataSetLinks getDataSetLinks()
+ public DataSetLinks getDataSetLinks()
{
DataSetLinks dataSetLinks = new DataSetLinks( linkBuilder.getLinks( dataSetService.getAllDataSets() ) );
new UrlResourceListener( uriInfo ).beforeMarshal( dataSetLinks );
return dataSetLinks;
}
-
+
+ @GET
+ @Produces( { "application/javascript" } )
+ public JSONWithPadding getDataSets( @QueryParam( "callback" ) @DefaultValue( "callback" )
+ String callback )
+ {
+ Collection<DataSet> dataSets = dataSetService.getAllDataSets();
+ Map<String, Object> dataSetOutput = new HashMap<String, Object>();
+
+ List<Map<String, Object>> dataSetsArray = new ArrayList<Map<String, Object>>();
+
+ for ( DataSet dataSet : dataSets )
+ {
+ Map<String, Object> dataSetMap = new HashMap<String, Object>();
+ dataSetMap.put( "id", dataSet.getUuid() );
+ dataSetMap.put( "href", uriInfo.getAbsolutePath().toASCIIString() + "/" + dataSet.getUuid() );
+ dataSetMap.put( "name", dataSet.getName() );
+
+ dataSetsArray.add( dataSetMap );
+ }
+
+ dataSetOutput.put( "dataSets", dataSetsArray );
+
+ return new JSONWithPadding( dataSetOutput, callback );
+ }
+
@GET
@Produces( MediaType.TEXT_HTML )
public String getDataSetList()
@@ -43,16 +99,4 @@
new UrlResourceListener( uriInfo ).beforeMarshal( dataSetLinks );
return velocityManager.render( dataSetLinks.getDataSet(), "dataSets" );
}
-
- @Required
- public void setDataSetService( DataSetService dataSetService )
- {
- this.dataSetService = dataSetService;
- }
-
- @Required
- public void setVelocityManager( VelocityManager velocityManager )
- {
- this.velocityManager = velocityManager;
- }
}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResourceP.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResourceP.java 2011-09-15 14:25:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResourceP.java 1970-01-01 00:00:00 +0000
@@ -1,92 +0,0 @@
-package org.hisp.dhis.web.api.resources;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.UriInfo;
-
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.importexport.dxf2.service.DataSetMapper;
-import org.hisp.dhis.importexport.dxf2.service.LinkBuilder;
-import org.hisp.dhis.importexport.dxf2.service.LinkBuilderImpl;
-import org.hisp.dhis.web.api.UrlResourceListener;
-import org.springframework.beans.factory.annotation.Required;
-
-import com.sun.jersey.api.json.JSONWithPadding;
-
-@Path( "jsonp" )
-public class DataSetsResourceP
-{
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private DataSetService dataSetService;
-
- @Required
- public void setDataSetService( DataSetService dataSetService )
- {
- this.dataSetService = dataSetService;
- }
-
- @Context
- private UriInfo uriInfo;
-
- // -------------------------------------------------------------------------
- // JSONP
- // -------------------------------------------------------------------------
-
- @GET
- @Path("dataSets")
- @Produces( { "application/x-javascript" } )
- public JSONWithPadding getDataSets( @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
- {
- Collection<DataSet> dataSets = dataSetService.getAllDataSets();
- Map<String, Object> dataSetOutput = new HashMap<String, Object>();
-
- List<Map<String, Object>> dataSetsArray = new ArrayList<Map<String,Object>>();
-
- for(DataSet dataSet : dataSets)
- {
- Map<String, Object> dataSetMap = new HashMap<String, Object>();
- dataSetMap.put( "id", dataSet.getUuid() );
- dataSetMap.put( "href", uriInfo.getAbsolutePath().toASCIIString() + "/" + dataSet.getUuid() );
- dataSetMap.put( "name", dataSet.getName() );
-
- dataSetsArray.add( dataSetMap );
- }
-
- dataSetOutput.put( "dataSets", dataSetsArray );
-
- return new JSONWithPadding( dataSetOutput, callback );
- }
-
- @GET
- @Path("dataSets/{uuid}")
- @Produces( { "application/x-javascript" } )
- public JSONWithPadding getDataSet( @PathParam("uuid") String uuid, @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
- {
- DataSet dataSet = dataSetService.getDataSet( uuid );
-
- if ( dataSet == null )
- {
- throw new IllegalArgumentException( "No dataset with uuid " + uuid );
- }
-
- org.hisp.dhis.importexport.dxf2.model.DataSet dxfDataSet = new DataSetMapper().convert( dataSet );
- new UrlResourceListener( uriInfo ).beforeMarshal( dxfDataSet );
-
- return new JSONWithPadding( dxfDataSet, callback );
- }
-}