=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GridHeader.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GridHeader.java 2012-04-26 07:56:54 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GridHeader.java 2012-05-11 19:04:25 +0000 @@ -27,19 +27,17 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.Arrays; +import java.util.List; + +import org.hisp.dhis.common.view.DetailedView; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonView; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; -import org.hisp.dhis.common.view.DetailedView; - -import java.util.Arrays; -import java.util.List; /** * @author Lars Helge Overland */ -@JacksonXmlRootElement( localName = "header", namespace = Dxf2Namespace.NAMESPACE ) public class GridHeader { private static final List NUMERIC_TYPES = Arrays.asList( Float.class.getName(), Double.class.getName(), Long.class.getName(), Integer.class.getName() ); @@ -97,7 +95,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( isAttribute = true ) public String getName() { return name; @@ -110,7 +107,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public String getColumn() { return column; @@ -123,7 +119,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public String getType() { return type; @@ -136,7 +131,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public boolean isHidden() { return hidden; @@ -149,7 +143,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public boolean isMeta() { return meta; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonRowDataSerializer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonRowDataSerializer.java 2012-04-26 10:56:58 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonRowDataSerializer.java 2012-05-11 19:04:25 +0000 @@ -27,47 +27,38 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.io.IOException; +import java.util.List; + import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import java.io.IOException; -import java.util.List; - /** * @author Morten Olav Hansen */ public class JacksonRowDataSerializer extends JsonSerializer>> { - private static final String ROW_NAME = "row"; - private static final String FIELD_NAME = "field"; private static final String EMPTY = ""; @Override public void serialize( List> values, JsonGenerator jgen, SerializerProvider provider ) throws IOException { - boolean b = true; - - for ( List value : values ) + jgen.writeStartArray(); + + for ( List row : values ) { - if ( !b ) - { - jgen.writeFieldName( ROW_NAME ); - } - - b = false; - - jgen.writeStartObject(); - - for ( Object object : value ) - { - object = object == null ? EMPTY : object; - - jgen.writeStringField( FIELD_NAME, String.valueOf( object ) ); - } - - jgen.writeEndObject(); + jgen.writeStartArray(); + + for ( Object field : row ) + { + jgen.writeString( field != null ? String.valueOf( field ) : EMPTY ); + } + + jgen.writeEndArray(); } + + jgen.writeEndArray(); } } === modified file 'dhis-2/dhis-support/dhis-support-system/pom.xml' --- dhis-2/dhis-support/dhis-support-system/pom.xml 2012-05-10 09:57:03 +0000 +++ dhis-2/dhis-support/dhis-support-system/pom.xml 2012-05-11 19:04:25 +0000 @@ -29,6 +29,10 @@ org.hisp.dhis dhis-support-test + + org.hisp.dhis + dhis-support-xml + === modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2012-03-09 11:46:58 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2012-05-11 19:04:25 +0000 @@ -59,6 +59,8 @@ import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; +import org.amplecode.staxwax.factory.XMLFactory; +import org.amplecode.staxwax.writer.XMLWriter; import org.apache.commons.lang.StringUtils; import org.apache.velocity.VelocityContext; import org.hisp.dhis.common.Grid; @@ -99,8 +101,25 @@ private static final String KEY_GRID = "grid"; private static final String KEY_ENCODER = "encoder"; private static final String KEY_PARAMS = "params"; - private static final String TEMPLATE = "grid.vm"; + private static final String JASPER_TEMPLATE = "grid.vm"; + private static final String HTML_TEMPLATE = "grid-html.vm"; + private static final String ATTR_GRID = "grid"; + private static final String ATTR_TITLE = "title"; + private static final String ATTR_SUBTITLE = "subtitle"; + private static final String ATTR_WIDTH = "width"; + private static final String ATTR_HEIGHT = "height"; + private static final String ATTR_HEADERS = "headers"; + private static final String ATTR_HEADER = "header"; + private static final String ATTR_NAME = "name"; + private static final String ATTR_COLUMN = "column"; + private static final String ATTR_TYPE = "type"; + private static final String ATTR_HIDDEN = "hidden"; + private static final String ATTR_META = "meta"; + private static final String ATTR_ROWS = "rows"; + private static final String ATTR_ROW = "row"; + private static final String ATTR_FIELD = "field"; + /** * Writes a PDF representation of the given Grid to the given OutputStream. */ @@ -321,7 +340,7 @@ final StringWriter writer = new StringWriter(); - render( grid, params, writer ); + render( grid, params, writer, JASPER_TEMPLATE ); String report = writer.toString(); @@ -338,9 +357,58 @@ public static void toJrxml( Grid grid, Map params, Writer writer ) throws Exception { - render( grid, params, writer ); + render( grid, params, writer, JASPER_TEMPLATE ); } + /** + * Writes a JRXML (Jasper Reports XML) representation of the given Grid to the given Writer. + */ + public static void toHtml( Grid grid, Writer writer ) + throws Exception + { + render( grid, null, writer, HTML_TEMPLATE ); + } + + /** + * Writes an XML representation of the given Grid to the given OutputStream. + */ + public static void toXml( Grid grid, OutputStream out ) + { + XMLWriter writer = XMLFactory.getXMLWriter( out ); + + writer.openDocument(); + writer.openElement( ATTR_GRID, ATTR_TITLE, grid.getTitle(), ATTR_SUBTITLE, grid.getSubtitle(), + ATTR_WIDTH, String.valueOf( grid.getWidth() ), ATTR_HEIGHT, String.valueOf( grid.getHeight() ) ); + + writer.openElement( ATTR_HEADERS ); + + for ( GridHeader header : grid.getHeaders() ) + { + writer.writeElement( ATTR_HEADER, null, ATTR_NAME, header.getName(), ATTR_COLUMN, header.getColumn(), + ATTR_TYPE, header.getType(), ATTR_HIDDEN, String.valueOf( header.isHidden() ), ATTR_META, String.valueOf( header.isMeta() ) ); + } + + writer.closeElement(); + writer.openElement( ATTR_ROWS ); + + for ( List row : grid.getRows() ) + { + writer.openElement( ATTR_ROW ); + + for ( Object field : row ) + { + writer.writeElement( ATTR_FIELD, field != null ? String.valueOf( field ) : EMPTY ); + } + + writer.closeElement(); + } + + writer.closeElement(); + writer.closeElement(); + + writer.closeDocument(); + } + // ------------------------------------------------------------------------- // Supportive methods // ------------------------------------------------------------------------- @@ -348,7 +416,7 @@ /** * Render using Velocity. */ - private static void render( Grid grid, Map params, Writer writer ) + private static void render( Grid grid, Map params, Writer writer, String template ) throws Exception { final VelocityContext context = new VelocityContext(); @@ -357,7 +425,7 @@ context.put( KEY_ENCODER, ENCODER ); context.put( KEY_PARAMS, params ); - new VelocityManager().getEngine().getTemplate( TEMPLATE ).merge( context, writer ); + new VelocityManager().getEngine().getTemplate( template ).merge( context, writer ); } /** === 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-05-01 14:21:21 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2012-05-11 19:04:25 +0000 @@ -27,34 +27,36 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonView; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import static org.hisp.dhis.system.util.MathUtils.getRounded; + +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRField; + import org.apache.commons.math.stat.regression.SimpleRegression; -import org.hisp.dhis.common.Dxf2Namespace; import org.hisp.dhis.common.Grid; import org.hisp.dhis.common.GridHeader; import org.hisp.dhis.common.adapter.JacksonRowDataSerializer; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.system.util.MathUtils; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.*; - -import static org.hisp.dhis.system.util.MathUtils.getRounded; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; /** * @author Lars Helge Overland * @version $Id$ */ -@JacksonXmlRootElement( localName = "grid", namespace = Dxf2Namespace.NAMESPACE ) public class ListGrid implements Grid { @@ -117,7 +119,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public String getTitle() { return title; @@ -132,7 +133,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public String getSubtitle() { return subtitle; @@ -147,7 +147,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public String getTable() { return table; @@ -171,8 +170,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlElementWrapper( localName = "headers", namespace = Dxf2Namespace.NAMESPACE ) - @JacksonXmlProperty( localName = "header", namespace = Dxf2Namespace.NAMESPACE ) public List getHeaders() { return headers; @@ -195,7 +192,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public int getHeight() { return (grid != null && grid.size() > 0) ? grid.size() : 0; @@ -203,7 +199,6 @@ @JsonProperty @JsonView( {DetailedView.class} ) - @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE ) public int getWidth() { verifyGridState(); @@ -242,8 +237,6 @@ @JsonProperty @JsonSerialize( using = JacksonRowDataSerializer.class ) @JsonView( {DetailedView.class} ) - @JacksonXmlElementWrapper( localName = "rows", namespace = Dxf2Namespace.NAMESPACE ) - @JacksonXmlProperty( localName = "row", namespace = Dxf2Namespace.NAMESPACE ) public List> getRows() { return grid; === added file 'dhis-2/dhis-support/dhis-support-system/src/main/resources/grid-html.vm' --- dhis-2/dhis-support/dhis-support-system/src/main/resources/grid-html.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/resources/grid-html.vm 2012-05-11 19:04:25 +0000 @@ -0,0 +1,39 @@ + + +

$!encoder.htmlEncode( $grid.title )

+ +

$!encoder.htmlEncode( $grid.subtitle )

+ + + + + +#foreach( $header in $grid.getVisibleHeaders() ) + +#end + + + + +#foreach( $row in $grid.getVisibleRows() ) + +#foreach( $col in $row ) +#set( $index = ( $velocityCount - 1 ) ) +#if( $grid.getVisibleHeaders().get( $index ).meta ) + +#else + +#end +#end + +#end + + +
$!encoder.htmlEncode( $header.name )
$!encoder.htmlEncode( $col )$!encoder.htmlEncode( $col )
\ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2012-04-25 20:43:17 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2012-05-11 19:04:25 +0000 @@ -163,6 +163,52 @@ return "grid"; } + @RequestMapping( value = "/{uid}/data.html", method = RequestMethod.GET ) + public void getReportTableHtml( @PathVariable( "uid" ) String uid, + @RequestParam( value = "ou", required = false ) String organisationUnitUid, + @RequestParam( value = "pe", required = false ) String period, + HttpServletResponse response ) throws Exception + { + ReportTable reportTable = reportTableService.getReportTable( uid ); + + if ( organisationUnitUid == null && reportTable.hasReportParams() && reportTable.getReportParams().isOrganisationUnitSet() ) + { + organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid(); + } + + Date date = period != null ? DateUtils.getMediumDate( period ) : new Cal().now().subtract( Calendar.MONTH, 1 ).time(); + + Grid grid = reportTableService.getReportTableGrid( uid, i18nManager.getI18nFormat(), date, organisationUnitUid ); + + String filename = filenameEncode( grid.getTitle() ) + ".html"; + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, false ); + + GridUtils.toHtml( grid, response.getWriter() ); + } + + @RequestMapping( value = "/{uid}/data.xml", method = RequestMethod.GET ) + public void getReportTableXml( @PathVariable( "uid" ) String uid, + @RequestParam( value = "ou", required = false ) String organisationUnitUid, + @RequestParam( value = "pe", required = false ) String period, + HttpServletResponse response ) throws Exception + { + ReportTable reportTable = reportTableService.getReportTable( uid ); + + if ( organisationUnitUid == null && reportTable.hasReportParams() && reportTable.getReportParams().isOrganisationUnitSet() ) + { + organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid(); + } + + Date date = period != null ? DateUtils.getMediumDate( period ) : new Cal().now().subtract( Calendar.MONTH, 1 ).time(); + + Grid grid = reportTableService.getReportTableGrid( uid, i18nManager.getI18nFormat(), date, organisationUnitUid ); + + String filename = filenameEncode( grid.getTitle() ) + ".xml"; + contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, false ); + + GridUtils.toXml( grid, response.getOutputStream() ); + } + @RequestMapping( value = "/{uid}/data.pdf", method = RequestMethod.GET ) public void getReportTablePdf( @PathVariable( "uid" ) String uid, @RequestParam( value = "ou", required = false ) String organisationUnitUid, === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/grid.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/grid.xsl 2012-04-26 07:56:54 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/grid.xsl 1970-01-01 00:00:00 +0000 @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -
-

- -

-

- -

- - - - - - - - - -
-
-
- -
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl 2012-05-01 09:53:59 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl 2012-05-11 19:04:25 +0000 @@ -48,7 +48,6 @@ - === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl 2012-04-26 08:33:26 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl 2012-05-11 19:04:25 +0000 @@ -11,8 +11,9 @@ - + +
Resource Datahtmlhtml xmljson pdf xls csv