=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2015-06-16 05:11:29 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/expression/ExpressionService.java 2015-06-18 06:57:14 +0000 @@ -126,7 +126,7 @@ List getAllExpressions(); Double getIndicatorValue( Indicator indicator, Period period, Map valueMap, - Map constantMap, Map orgUnitCountMap, Integer days ); + Map constantMap, Map orgUnitCountMap ); /** * Generates the calculated value for the given expression base on the values === modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java' --- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-06-18 06:21:45 +0000 +++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-06-18 06:57:14 +0000 @@ -340,7 +340,7 @@ Map orgUnitCountMap = permutationOrgUnitTargetMap != null ? permutationOrgUnitTargetMap.get( ou ) : null; - Double value = expressionService.getIndicatorValue( indicator, period, valueMap, constantMap, orgUnitCountMap, period.getDaysInPeriod() ); + Double value = expressionService.getIndicatorValue( indicator, period, valueMap, constantMap, orgUnitCountMap ); if ( value != null ) { === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2015-06-16 05:11:29 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2015-06-18 06:57:14 +0000 @@ -167,13 +167,15 @@ @Override public Double getIndicatorValue( Indicator indicator, Period period, Map valueMap, - Map constantMap, Map orgUnitCountMap, Integer days ) + Map constantMap, Map orgUnitCountMap ) { if ( indicator == null || indicator.getExplodedNumeratorFallback() == null || indicator.getExplodedDenominatorFallback() == null ) { return null; } + Integer days = period != null ? period.getDaysInPeriod() : null; + final String denominatorExpression = generateExpression( indicator.getExplodedDenominatorFallback(), valueMap, constantMap, orgUnitCountMap, days, NEVER_SKIP ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java' --- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java 2015-06-16 05:11:29 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/expression/ExpressionServiceTest.java 2015-06-18 06:57:14 +0000 @@ -498,7 +498,7 @@ Map constantMap = new HashMap<>(); constantMap.put( constantA.getUid(), 2.0 ); - assertEquals( 200d, expressionService.getIndicatorValue( indicatorA, period, valueMap, constantMap, null, null ), DELTA ); + assertEquals( 200d, expressionService.getIndicatorValue( indicatorA, period, valueMap, constantMap, null ), DELTA ); } // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2015-06-16 18:35:12 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2015-06-18 06:57:14 +0000 @@ -28,15 +28,36 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.hisp.dhis.commons.util.ConversionUtils.getIdentifiers; +import static org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString; + +import java.io.OutputStream; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.sql.DataSource; + import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; + +import org.apache.commons.io.IOUtils; import org.apache.velocity.VelocityContext; import org.hisp.dhis.calendar.Calendar; import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.common.Grid; import org.hisp.dhis.common.IdentifiableObjectUtils; +import org.hisp.dhis.commons.filter.Filter; +import org.hisp.dhis.commons.filter.FilterUtils; +import org.hisp.dhis.commons.util.Encoder; import org.hisp.dhis.constant.ConstantService; import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -49,29 +70,11 @@ import org.hisp.dhis.reporttable.ReportTable; import org.hisp.dhis.reporttable.ReportTableService; import org.hisp.dhis.system.util.DateUtils; -import org.hisp.dhis.commons.util.Encoder; -import org.hisp.dhis.commons.filter.Filter; -import org.hisp.dhis.commons.filter.FilterUtils; import org.hisp.dhis.system.util.JRExportUtils; -import org.hisp.dhis.commons.util.StreamUtils; import org.hisp.dhis.system.velocity.VelocityManager; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.transaction.annotation.Transactional; -import javax.sql.DataSource; -import java.io.OutputStream; -import java.io.Writer; -import java.sql.Connection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.hisp.dhis.commons.util.ConversionUtils.getIdentifiers; -import static org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString; - /** * @author Lars Helge Overland */ @@ -169,7 +172,7 @@ try { - JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report.getDesignContent() ) ); + JasperReport jasperReport = JasperCompileManager.compileReport( IOUtils.toInputStream( report.getDesignContent(), StandardCharsets.UTF_8 ) ); if ( report.hasReportTable() ) // Use JR data source { === modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/StreamUtils.java' --- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/StreamUtils.java 2015-06-16 18:30:37 +0000 +++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/util/StreamUtils.java 2015-06-18 06:57:14 +0000 @@ -30,20 +30,12 @@ import java.io.BufferedInputStream; import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.zip.GZIPInputStream; @@ -51,8 +43,6 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; -import org.hisp.dhis.commons.comparator.FileLastModifiedComparator; - /** * @author Lars Helge Overland */ @@ -62,115 +52,6 @@ public static final String ENCODING_UTF8 = "UTF-8"; /** - * Returns all Files in the given directory. - * - * @param directory a File representing the relevant directory. - * @param sort indicates whether to sort chronologically on the lastModified property. - * @return a List of Files. - */ - public static List getFileList( File directory, boolean sort ) - { - List files = new ArrayList<>(); - - if ( directory != null ) - { - files = Arrays.asList( directory.listFiles() ); - } - - if ( sort ) - { - Collections.sort( files, new FileLastModifiedComparator() ); - } - - return files; - } - - /** - * Writes the content of the StringBuffer to the file. - * - * @param file the file to write to. - * @param content the content to write. - * @throws IOException - */ - public static void writeContent( File file, StringBuffer content ) - throws IOException - { - BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter( new FileOutputStream( file ), ENCODING_UTF8 ) ); - - try - { - writer.write( content.toString() ); - } - finally - { - try - { - writer.flush(); - } - catch ( Exception ex ) - { - } - - try - { - writer.close(); - } - catch ( Exception ex ) - { - } - } - } - - /** - * 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_UTF8 ) ) ); - } - 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 ) - { - BufferedInputStream in = null; - - try - { - in = new BufferedInputStream( new FileInputStream( file ) ); - - byte[] bytes = new byte[(int) file.length()]; - - in.read( bytes ); - - return new String( bytes, ENCODING_UTF8 ); - } - catch ( IOException ex ) - { - throw new RuntimeException( ex ); - } - finally - { - closeInputStream( in ); - } - } - - /** * 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 @@ -240,26 +121,6 @@ } /** - * Closes the given InputStream. - * - * @param in the InputStream to close. - */ - private static void closeInputStream( InputStream in ) - { - if ( in != null ) - { - try - { - in.close(); - } - catch ( Exception ex ) - { - ex.printStackTrace(); - } - } - } - - /** * Test for ZIP/GZIP stream signature. Wraps the input stream in a * BufferedInputStream. If ZIP/GZIP test is true wraps again in ZipInputStream/GZIPInputStream. * === 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 2015-06-15 13:44:20 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2015-06-18 06:57:14 +0000 @@ -29,6 +29,9 @@ */ import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP; +import static org.hisp.dhis.commons.util.CsvUtils.NEWLINE; +import static org.hisp.dhis.commons.util.CsvUtils.SEPARATOR_B; +import static org.hisp.dhis.commons.util.CsvUtils.csvEncode; import static org.hisp.dhis.system.util.PDFUtils.addTableToDocument; import static org.hisp.dhis.system.util.PDFUtils.closeDocument; import static org.hisp.dhis.system.util.PDFUtils.getEmptyCell; @@ -38,13 +41,11 @@ import static org.hisp.dhis.system.util.PDFUtils.getTitleCell; import static org.hisp.dhis.system.util.PDFUtils.openDocument; import static org.hisp.dhis.system.util.PDFUtils.resetPaddings; -import static org.hisp.dhis.commons.util.CsvUtils.csvEncode; -import static org.hisp.dhis.commons.util.CsvUtils.SEPARATOR_B; -import static org.hisp.dhis.commons.util.CsvUtils.NEWLINE; import java.io.OutputStream; import java.io.StringWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -65,6 +66,7 @@ import org.amplecode.staxwax.factory.XMLFactory; import org.amplecode.staxwax.writer.XMLWriter; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -72,14 +74,13 @@ import org.hisp.dhis.common.Grid; import org.hisp.dhis.common.GridHeader; import org.hisp.dhis.common.NameableObjectUtils; +import org.hisp.dhis.commons.collection.ListUtils; +import org.hisp.dhis.commons.util.CodecUtils; +import org.hisp.dhis.commons.util.Encoder; +import org.hisp.dhis.commons.util.TextUtils; import org.hisp.dhis.system.util.DateUtils; import org.hisp.dhis.system.util.ExcelUtils; import org.hisp.dhis.system.util.MathUtils; -import org.hisp.dhis.commons.util.CodecUtils; -import org.hisp.dhis.commons.util.Encoder; -import org.hisp.dhis.commons.collection.ListUtils; -import org.hisp.dhis.commons.util.StreamUtils; -import org.hisp.dhis.commons.util.TextUtils; import org.hisp.dhis.system.velocity.VelocityManager; import org.htmlparser.Node; import org.htmlparser.NodeFilter; @@ -102,7 +103,7 @@ { private static final Log log = LogFactory.getLog( GridUtils.class ); - private static final String EMPTY = ""; + private static final String EMPTY = ""; private static final String XLS_SHEET_PREFIX = "Sheet "; private static final int JXL_MAX_COLS = 256; @@ -390,7 +391,7 @@ String report = writer.toString(); - JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report ) ); + JasperReport jasperReport = JasperCompileManager.compileReport( IOUtils.toInputStream( report, StandardCharsets.UTF_8 ) ); JasperPrint print = JasperFillManager.fillReport( jasperReport, params, grid ); === 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 2015-06-15 13:44:20 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java 2015-06-18 06:57:14 +0000 @@ -30,6 +30,7 @@ import java.io.File; +import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hisp.dhis.commons.action.AbstractRelativePeriodsAction; @@ -39,7 +40,6 @@ import org.hisp.dhis.reporttable.ReportParams; import org.hisp.dhis.reporttable.ReportTable; import org.hisp.dhis.reporttable.ReportTableService; -import org.hisp.dhis.commons.util.StreamUtils; /** * @author Lars Helge Overland @@ -213,7 +213,7 @@ if ( file != null ) { - report.setDesignContent( StreamUtils.getContent( file ) ); + report.setDesignContent( FileUtils.readFileToString( file ) ); } reportService.saveReport( report );