Error while unzipping saved reports

I am using openmrs-module-reporting to generate reports (all previous versions till 0.9.8.1).

Once I generate report and restart the application, reports generated before restart shows error.

I did found issue in function : org.openmrs.module.reporting.report.util.ReportUtil.decompressFile(File inFile, File outFile).

Same issue can resolved by replacing current readStringFromFile function with :

public static String readStringFromFile(File f) throws IOException {
    String ret = null;
    StringBuilder fileContents = new StringBuilder((int)f.length());
    System.out.println(f);
    Scanner scanner = new Scanner(f);
    System.out.println(scanner);
    String lineSeparator = System.getProperty("line.separator");
    try {
        while(scanner.hasNextLine()) {        
            fileContents.append(scanner.nextLine() + lineSeparator);
        }
        ret = fileContents.toString();
        System.out.println(ret);
    } finally {
        scanner.close();
    }

Can any one suggest what should be done? Otherwise we have to replace replicate the module and make required changes.

Note - latest version of reporting module does not support Openmrs version we are using.

@sagarbele, sorry for the trouble. Can you share a little more detail to help us reproduce the problem?

The existing “readStringFromFile” method will first try to de-compress the file if it’s extension ends with “.gz”. Is it possible that your report has a “.gz” extension but isn’t actually compressed? If so it could be that the issue is in the writing of the report output correctly, rather than in the reading of the output file for viewing.

Can you share the saved report that is failing to open (you can find this in your REPORT_RESULTS folder) or can you share a failing unit test that demonstrates the problem?

Thanks, Mike

@mseaton, yes the report is having an extension of “.gz”, but as I could open it directly without decompressing it, it might not have got compressed, link to sample report generated for regenerating issue - http://hospdev.hispindia.org/owncloud/index.php/s/bgSWkgvblbTZa79

No need to reinvent the wheel

https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#readFileToString(java.io.File)

Note: this works only if the file is text (and your method too). For compressed ones (binary) it won’t work.

Actually it’s an uncompressed XML file without encoding (this could be a problem in some languages). If parsing is required there’s no need to store it in a String, XML parsers do just fine with input streams.

@sagarbele, this does seem to be a bug. From what I can gather, this is limited to where the report is rendered to the default “Web” renderer, rather than to any non-web renderer. If you were going to go into your REPORT_DATA folder and rename all of your *.reportdata.gz to *.reportdata, my guess is that things will work. We can raise a ticket for this and apply a fix for the next version of reporting. If you need this backported to a version that is compatible with you, then it may be that you need to fork and create a point release for yourself that contains the necessary fix.

I have created a ticket for this issue here:

@sagarbele, I’ve pushed a fix for this into the master branch here: https://github.com/openmrs/openmrs-module-reporting/commit/fd673eb9254e88535dc05e32f8eeb3b7fcfceaed

Thanks @mseaton.