Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions service/grails-app/controllers/mod/rs/ReportController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,6 +172,7 @@ class ReportController extends OkapiTenantAwareController<Report> {
dataType = "string"
)
])
@NotTransactional
def generatePicklist() {
ContextLogging.startTime();
ContextLogging.setValue(ContextLogging.FIELD_RESOURCE, RESOURCE_REPORT);
Expand Down Expand Up @@ -235,6 +237,7 @@ class ReportController extends OkapiTenantAwareController<Report> {
dataType = "string"
)
])
@NotTransactional
def execute() {
ContextLogging.startTime();
ContextLogging.setValue(ContextLogging.FIELD_RESOURCE, RESOURCE_REPORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> parameters = new HashMap<String, Object>();
parameters.put(PARAMETER_IDS, idsForReport);
parameters.put(PARAMETER_SCHEMA, schema);
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down
Loading