hboie/jasper-report-bundle

Symfony 2-5 / Symfony Flex Bundle integrating the Jaspersoft REST v2 client (jaspersoft/rest-client)

Installs: 5 096

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 3

Open Issues: 1

Type:symfony-bundle

v1.6 2021-11-08 22:15 UTC

This package is auto-updated.

Last update: 2024-03-29 03:01:29 UTC


README

The JasperReportBundle requires jaspersoft/rest-client and provides an JasperReport-Client as service in the Symfony service container.

Installation with Symfony Flex (4 / 5)
Basic Usage in Symfony 4 / 5
Installation with Symfony 2 / 3
Basic Usage in Symfony 2 / 3
Search Resource Command
Export Resource Command
Import Resource Command
Copying Resources between different Servers
Additional Configuration Options

Installation with Symfony Flex (4 / 5)

1 Add bundle to composer.json:

    composer require hboie/jasper_report_bundle

2 The Bundle will be registred automatically and by executing the recipe the configuration file jasper-report.yaml will be created in the config/packages directory and the corresponding entries in the .env file will be made

3 Change the standard setting in the file jasper-report.yaml

    hboie_jasper_report:
        host:      'http://localhost:8080/jasperserver'
        username:  '%env(HBOIE_JASPER_REPORT_USERNAME)%'
        password:  '%env(HBOIE_JASPER_REPORT_PASSWORD)%'
        org_id:    '%env(HBOIE_JASPER_REPORT_ORGID)%'

and in the .env file

HBOIE_JASPER_REPORT_USERNAME=jasperadmin
HBOIE_JASPER_REPORT_PASSWORD=jasperadmin
HBOIE_JASPER_REPORT_ORGID=

Basic Usage in Symfony 4 / 5

The bundle supports autowiring, so you can access the report-service directly in your controller, e.g.

    use Symfony\Component\HttpFoundation\Request;
    use Hboie\JasperReportBundle\ReportService;

    public function reportAction(Request $request, ReportService $reportService)
    {
        $report = $reportService->runReport('/reports/TestReport', 'pdf');

        $response = new Response($report);
        $response->headers->set('Content-type', 'application/pdf');
        $response->headers->set('Content-Disposition', 'inline; filename=Report.pdf');
        $response->headers->set('Cache-Control', 'must-revalidate');

        return $response;
    }

Installation with Symfony 2 / 3

1 Add bundle to composer.json:

    composer require hboie/jasper_report_bundle

2 Register bundle in app/AppKernel.php:

    $bundle = [
            ...
    new Hboie\JasperReportBundle\HboieJasperReportBundle(),
            ...
    ];

3 Add parameter to app/config/config.yml

    hboie_jasper_report:
        host:      "%jasper_host%"
        username:  "%jasper_user%"
        password:  "%jasper_password%"
        org_id:    "%jasper_org_id%"

4 Add a dummy configuration in app/config/paramters.yml.dist

    jasper_host: http://localhost:8080/jasperserver
    jasper_user: jasperadmin
    jasper_password: jasperadmin
    jasper_org_id:

5 Add your own configuration in app/config/paramters.yml

Basic Usage in Symfony 2 / 3

You can now access the Client object via the Symfony service jasperreport.client:

    $client = $this->get('jasperreport.client');

or directly access the ReportService using the Symfony service jasperreport.reportservice:

    $report = $this->get('jasperreport.reportservice')->runReport('/reports/TestReport', 'pdf');

So a controller giving back a pdf-report would look like

    public function reportAction(Request $request)
    {
        $report = $this->get('jasperreport.reportservice')->runReport('/reports/TestReport', 'pdf');

        $response = new Response($report);
        $response->headers->set('Content-type', 'application/pdf');
        $response->headers->set('Content-Disposition', 'inline; filename=Report.pdf');
        $response->headers->set('Cache-Control', 'must-revalidate');

        return $response;
    }

Search Resource Command

With the jasper:repository:search you can search resources on the JaserReport server

    php bin/console jasper:repository:search <Citeria> <Detail>

Criteria: search criteria
Detail: show details (optional)
If no detail-value is given, only the uri of the resources will be listed. If an detail value greater than 0 is given, full data will be displayed.

Export Resource Command

With the jasper:export:resource command, a given resource will be exported from the JasperServer and downloaded to an zip-archive file.

    php bin/console jasper:export:resource <UriOfResource> <Filename> <SkipDependentResources>

UriOfResource: uri of the resouce that should be downloaded
Filename: filename of the local target file
SkipDependentResources: if set to "true", dependent resource, e.g. the database connection of a report will be skipped.

Import Resource Command

With the jasper:import:resource command, a previously exported resource can be imported to a JasperServer.

    php bin/console jasper:import:resource <Filename> <IncludebrokenDependencies>

Filename: filename of the local import file
IncludebrokenDependencies: if set to "true", for resources with broken dependencies (e.g. exported with the option SkipDependentResources) the import process attempts to import the resource by resolving dependencies with local resources.

Copying Resources between different Servers

You can use the export and import resources commands to copy resources from one server to another, e.g. between different stages of an application. Use the SkipDependentResources option when exporting a resource and the IncludebrokenDependencies option when importing it on the second server to avoid that the database connection is overwritten on the target server.

Take care that the export and import keys on both servers are adjusted. Read https://community.jaspersoft.com/documentation/tibco-jasperreports-server-security-guide/v7/using-custom-keys for further information on how to use customs keys.

Create key store

    keytool -genseckey -keystore ./mystore -storetype jceks -storepass <storepass> -keyalg AES -keysize 128 -alias importExportEncSecret -keypass <keypass>

Copy store to JasperServer's buildomatic directory

    cp ./mystore /opt/jasperreports-server-cp-7.8.0/buildomatic/

Go to the buildomatic directory as root user and import key to JasperServer

    ./js-import.sh --input-key --keystore ./mystore --storepass <storepass> --keyalias importExportEncSecret --keypass <keypass>

Restart the JasperServer application or reboot the server

Additional Configuration Options

    hboie_jasper_report:
        host:      'http://localhost:8080/jasperserver'
        username:  '%env(HBOIE_JASPER_REPORT_USERNAME)%'
        password:  '%env(HBOIE_JASPER_REPORT_PASSWORD)%'
        org_id:    '%env(HBOIE_JASPER_REPORT_ORGID)%'
        timeout:   50

timeout: timeout for REST-request (in seconds)