diff --git a/service/grails-app/controllers/mod/rs/ReportController.groovy b/service/grails-app/controllers/mod/rs/ReportController.groovy index a5251eb43..7cf316aac 100644 --- a/service/grails-app/controllers/mod/rs/ReportController.groovy +++ b/service/grails-app/controllers/mod/rs/ReportController.groovy @@ -12,6 +12,7 @@ import com.k_int.okapi.OkapiTenantAwareController; import grails.converters.JSON; import grails.gorm.multitenancy.CurrentTenant; +import grails.gorm.transactions.NotTransactional; import groovy.util.logging.Slf4j; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -171,6 +172,7 @@ class ReportController extends OkapiTenantAwareController { dataType = "string" ) ]) + @NotTransactional def generatePicklist() { ContextLogging.startTime(); ContextLogging.setValue(ContextLogging.FIELD_RESOURCE, RESOURCE_REPORT); @@ -235,6 +237,7 @@ class ReportController extends OkapiTenantAwareController { dataType = "string" ) ]) + @NotTransactional def execute() { ContextLogging.startTime(); ContextLogging.setValue(ContextLogging.FIELD_RESOURCE, RESOURCE_REPORT); diff --git a/service/grails-app/services/org/olf/rs/reporting/JasperReportService.groovy b/service/grails-app/services/org/olf/rs/reporting/JasperReportService.groovy index 273574041..3123efa7b 100644 --- a/service/grails-app/services/org/olf/rs/reporting/JasperReportService.groovy +++ b/service/grails-app/services/org/olf/rs/reporting/JasperReportService.groovy @@ -95,11 +95,13 @@ public class JasperReportService { String fallbackReportResource = null ) { InputStream result = null; + ByteArrayOutputStream outputStream = null; // If you are having issues with fonts, take a look at // https://community.jaspersoft.com/wiki/custom-font-font-extension Connection connection = dataSource.getConnection(); - try{ + JasperPrint jasperPrint; + try { Map parameters = new HashMap(); parameters.put(PARAMETER_IDS, idsForReport); parameters.put(PARAMETER_SCHEMA, schema); @@ -110,15 +112,10 @@ public class JasperReportService { JasperReport jasperReport = getReport(fileDefinition, fallbackReportResource); // Execute the report - JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, connection); - - // Now output the report - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream); - result = new ByteArrayInputStream(outputStream.toByteArray()); - outputStream.close(); + jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, connection); } catch(Exception e) { log.error("Exception thrown while generating a report", e); + return result; } finally { // Not forgetting to close the connection connection.close(); @@ -129,6 +126,17 @@ public class JasperReportService { } } + try { + // Now output the report + outputStream = new ByteArrayOutputStream(); + JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream); + result = new ByteArrayInputStream(outputStream.toByteArray()); + } catch(Exception e) { + log.error("Exception thrown while generating a report PDF", e); + } finally { + outputStream.close(); + } + // Return the result to the caller return(result); }