Giter Site home page Giter Site logo

paulwellnerbou / grails-birt-plugin Goto Github PK

View Code? Open in Web Editor NEW
3.0 5.0 1.0 194 KB

Plugin for Grails 3.2+/4+ offering BIRT functionality from legacy Grails 2 BIRT Plugin (http://grails.org/plugin/birt-report)

License: Apache License 2.0

Groovy 57.09% Shell 5.68% Batchfile 2.81% Java 34.42%
birt grails3 plugin grails reporting

grails-birt-plugin's Introduction

grails-birt-plugin

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.


Usage

Setup

  1. 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.

  1. Add BirtReportService to your beans in your resources.groovy:
birtReportService(BirtReportService, grailsApplication)
  1. Use BirtReportService in your Controllers/Services, it will be automatically injected:
class MyController {

    BirtReportService birtReportService
    ...
}

Configuration

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"
}

Creating a report

Have a look at the unit test class BirtReportServiceTest, where a sample report is created.

Create a PDF file

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()

Use it in your servlet context to deliver a PDF as response

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()

Test, build & install

./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.

Release

./gradlew release -Prelease.useAutomaticVersion=true -PpublishUser=<user> -PpublishKey=<key>

grails-birt-plugin's People

Contributors

paulwellnerbou avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

grails-birt-plugin's Issues

403 Forbidden error

I am trying to add this plugin to my Grails 3 project, but I get this error when reloading build.gradle:

Could not GET 'https://dl.bintray.com/paulwellnerbou/maven/org/grails/plugins/birt-report/4.3.0.4/birt-report-4.3.0.4.pom'. Received status code 403 from server: Forbidden

additional config required in order to use the grails datasource in reports

After setting useGrailsDatasource to true in the application.groovy birt configuration, I got an error saying that the dataSource was null. I was able to fix this by adding a line to the bean definition in resources.groovy (step 2 of the readme setup instructions)

birtReportService(BirtReportService, grailsApplication) {
    dataSource = ref('dataSource')
}

I figured this out by reading this stackoverflow answer:

https://stackoverflow.com/questions/21491074/grails-getting-the-data-source-in-a-normal-groovy-class

The author of the stackoverflow answer mentions that there are a couple of other alternative solutions that I believe could be implemented using either applicationContext or grailsApplication in BirtReportService.groovy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.