=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java 2010-04-12 21:23:33 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java 2010-05-17 13:40:52 +0000 @@ -51,8 +51,10 @@ private String design; + private String designContent; + private String type; - + private Set reportTables = new HashSet(); private transient String url; @@ -160,6 +162,16 @@ this.design = design; } + public String getDesignContent() + { + return designContent; + } + + public void setDesignContent( String designContent ) + { + this.designContent = designContent; + } + public String getType() { return type; === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/report/hibernate/Report.hbm.xml' --- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/report/hibernate/Report.hbm.xml 2009-09-14 16:00:37 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/report/hibernate/Report.hbm.xml 2010-05-17 13:40:52 +0000 @@ -16,6 +16,8 @@ + + === modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java 2010-05-06 11:38:23 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/StreamUtils.java 2010-05-17 13:40:52 +0000 @@ -31,6 +31,7 @@ import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -40,6 +41,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; +import java.io.UnsupportedEncodingException; import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; @@ -187,6 +189,48 @@ } /** + * Get an InputStream for the String. + * + * @param string the String. + * @return the InputStream. + */ + public static InputStream getInputStream( String string ) + { + try + { + return new BufferedInputStream( new ByteArrayInputStream( string.getBytes( ENCODING_UTF ) ) ); + } + catch ( UnsupportedEncodingException ex ) + { + throw new RuntimeException( ex ); + } + } + + /** + * Returns the content of the File as a String. + * + * @param file the File. + * @return the String. + */ + public static String getContent( File file ) + { + try + { + BufferedInputStream in = new BufferedInputStream( new FileInputStream( file ) ); + + byte[] bytes = new byte[(int)file.length()]; + + in.read( bytes ); + + return new String( bytes, ENCODING_UTF ); + } + catch ( IOException ex ) + { + throw new RuntimeException( ex ); + } + } + + /** * Reads the content of the file to a StringBuffer. Each line is compared to * the keys of the argument map. If a line is matched, the line is replaced * with the keys corresponding value. Passing null as replace map argument skips === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java 2010-04-12 21:23:33 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java 2010-05-17 13:40:52 +0000 @@ -27,13 +27,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.hisp.dhis.system.util.ConversionUtils.getIntegerCollection; +import static org.hisp.dhis.system.util.ConversionUtils.getSet; + import java.io.File; import java.util.Collection; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.hisp.dhis.external.location.LocationManager; import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.report.Report; import org.hisp.dhis.report.ReportManager; @@ -44,8 +46,6 @@ import com.opensymphony.xwork2.ActionSupport; -import static org.hisp.dhis.system.util.ConversionUtils.*; - /** * @author Lars Helge Overland * @version $Id: UploadDesignAction.java 5207 2008-05-22 12:16:36Z larshelg $ @@ -80,13 +80,6 @@ this.reportTableService = reportTableService; } - private LocationManager locationManager; - - public void setLocationManager( LocationManager locationManager ) - { - this.locationManager = locationManager; - } - // ----------------------------------------------------------------------- // I18n // ----------------------------------------------------------------------- @@ -203,6 +196,18 @@ return ERROR; } + // --------------------------------------------------------------------- + // Create report + // --------------------------------------------------------------------- + + Report report = ( id == null ) ? new Report() : reportService.getReport( id ); + + report.setName( name ); + report.setDesign( fileName ); + report.setType( type ); + report.setReportTables( selectedReportTables != null ? getSet( + reportTableService.getReportTables( getIntegerCollection( selectedReportTables ) ) ) : null ); + log.info( "Upload file name: " + fileName + ", content type: " + contentType ); if ( ( type != null && type.equals( Report.TYPE_JASPER ) ) && file != null ) @@ -211,7 +216,7 @@ // Design file upload // ----------------------------------------------------------------- - StreamUtils.write( file, locationManager.getFileForWriting( fileName, Report.TEMPLATE_DIR ) ); + report.setDesignContent( StreamUtils.getContent( file ) ); } else // BIRT { @@ -241,18 +246,6 @@ } } - // --------------------------------------------------------------------- - // Create and save report - // --------------------------------------------------------------------- - - Report report = ( id == null ) ? new Report() : reportService.getReport( id ); - - report.setName( name ); - report.setDesign( fileName ); - report.setType( type ); - report.setReportTables( selectedReportTables != null ? getSet( - reportTableService.getReportTables( getIntegerCollection( selectedReportTables ) ) ) : null ); - reportService.saveReport( report ); return SUCCESS; === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/GetAllReportsAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/GetAllReportsAction.java 2010-04-12 21:23:33 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/GetAllReportsAction.java 2010-05-17 13:40:52 +0000 @@ -104,7 +104,7 @@ { for ( Report report : reportService.getAllReports() ) { - report.setUrl( "renderReport.action?template=" + report.getDesign() ); + report.setUrl( "renderReport.action?id=" + report.getId() ); reports.add( report ); } === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java 2010-04-12 21:23:33 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/RenderReportAction.java 2010-05-17 13:40:52 +0000 @@ -27,7 +27,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.io.File; import java.io.OutputStream; import javax.servlet.http.HttpServletResponse; @@ -37,12 +36,10 @@ import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; -import net.sf.jasperreports.engine.design.JasperDesign; -import net.sf.jasperreports.engine.xml.JRXmlLoader; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hisp.dhis.external.location.LocationManager; +import org.hisp.dhis.report.Report; +import org.hisp.dhis.report.ReportService; +import org.hisp.dhis.system.util.StreamUtils; import org.hisp.dhis.util.StreamActionSupport; import org.springframework.jdbc.core.JdbcTemplate; @@ -53,19 +50,15 @@ public class RenderReportAction extends StreamActionSupport { - private static final Log log = LogFactory.getLog( RenderReportAction.class ); - - private static final String TEMPLATE_DIR = "templates"; - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- - private LocationManager locationManager; - - public void setLocationManager( LocationManager locationManager ) + private ReportService reportService; + + public void setReportService( ReportService reportService ) { - this.locationManager = locationManager; + this.reportService = reportService; } private JdbcTemplate jdbcTemplate; @@ -79,11 +72,11 @@ // Input // ------------------------------------------------------------------------- - private String template; + private Integer id; - public void setTemplate( String template ) + public void setId( Integer id ) { - this.template = template; + this.id = id; } // ------------------------------------------------------------------------- @@ -93,16 +86,12 @@ @Override protected String execute( HttpServletResponse response, OutputStream out ) throws Exception - { - File file = locationManager.getFileForReading( template, TEMPLATE_DIR ); - - log.info( "Report template: " + file ); - - JasperDesign design = JRXmlLoader.load( file ); - - JasperReport report = JasperCompileManager.compileReport( design ); - - JasperPrint print = JasperFillManager.fillReport( report, null, jdbcTemplate.getDataSource().getConnection() ); + { + Report report = reportService.getReport( id ); + + JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report.getDesignContent() ) ); + + JasperPrint print = JasperFillManager.fillReport( jasperReport, null, jdbcTemplate.getDataSource().getConnection() ); JasperExportManager.exportReportToPdfStream( print, out ); === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2010-03-17 06:25:32 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2010-05-17 13:40:52 +0000 @@ -321,8 +321,6 @@ ref="org.hisp.dhis.report.ReportService"/> - - + + ref="jdbcTemplate"/>