Plugin for Grails 4+ offering BIRT functionality from legacy Grails 2 BIRT Plugin (http://grails.org/plugin/birt-report)
This plugin takes mainly eyck's code from his BIRT Plugin for Grails 2, restructured so that it works with Grails 3 and works with reports from classpath resources, not only from files.
As I am neither an expert for grails nor for BIRT, there may be way better methods to set up this Grails 3 plugin or to initialize the BIRT engine. If so, please contact me, open an issue or create a pull request.
- Include the dependency in your
build.gradle
of your Grails 4 project:
repositories {
maven {
url "https://dl.bintray.com/paulwellnerbou/maven"
}
}
...
dependencies {
compile 'org.grails.plugins:birt-report:4.4.0'
}
For Grails 3, use version 4.3.0.4
.
- Add
BirtReportService
to your beans in yourresources.groovy
:
birtReportService(BirtReportService, grailsApplication)
- Use
BirtReportService
in your Controllers/Services, it will be automatically injected:
class MyController {
BirtReportService birtReportService
...
}
The location of the reports can be configured in your application.groovy
with
birt {
reportHome = "classpath:Reports"
useGrailsDatasource = false
generateAbsoluteBaseURL = false
baseUrl = ...
imageUrl = ...
}
This are the default values. Your reports are found in the application's classpath if they are packaged correctly as
resources (this is src/main/resources
by convention).
I don't really know what the other configuration options are exactly doing, the source code was copied without modifying the logic from Eyck's original sources. Please consider reading the source to find out more. If you found out, please tell me, so I can update the documentation.
If you want to use reports from filesystem, you can use the file:
prefix:
birt {
reportHome = "file:path/to/your/reports"
}
Have a look at the unit test class BirtReportServiceTest
, where a sample report is created.
def parameters = [:]
def birtReportTmpFile = "anyTmpFileName"
def reportName = "myReport" // .rptdesign is added automatically
def options = birtReportService.getRenderOption(null, 'pdf')
birtReportService.run(reportName, parameters, birtReportTmpFile)
def targetFileName = "/path/to/target/file.pdf"
def result = birtReportService.render(targetFileName, parameters, options)
new File(targetFileName).newOutputStream() << result.toByteArray()
def parameters = [:]
def birtReportTmpFile = "anyTmpFileName"
def reportName = "myReport" // .rptdesign is added automatically
def options = birtReportService.getRenderOption(request, 'pdf')
birtReportService.run(reportName, parameters, birtReportTmpFile)
def result = birtReportService.render(targetFileName, parameters, options)
response.setHeader("Content-disposition", "attachment; filename=report.pdf")
response.contentType = 'application/pdf'
response.outputStream << result.toByteArray()
./gradlew check install
The check
task will build and run the tests. The install
tasks will package the plugin and publish it to your
local Maven repository.
./gradlew release -Prelease.useAutomaticVersion=true -PpublishUser=<user> -PpublishKey=<key>