Skip to content

Symfony Bundle integrating the Jaspersoft REST v2 client (jaspersoft/rest-client) update for Symfony 7.4

License

Notifications You must be signed in to change notification settings

Graalstrike/JasperReportBundle

 
 

Repository files navigation

JasperReportBundle

Requirements*

Packagist PHP Version Packagist Dependency Version

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

Installation
Basic Usage
Search Resource Command
Additional configuration options

Installation

1 Add bundle to composer.json:

    composer require graalstrike/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

    graalstrike_jasper_report:
        host:      'http://localhost:8080/jasperserver'
        username:  '%env(GRAALSTRIKE_JASPER_REPORT_USERNAME)%'
        password:  '%env(GRAALSTRIKE_JASPER_REPORT_PASSWORD)%'
        org_id:    '%env(GRAALSTRIKE_JASPER_REPORT_ORGID)%'

and in the .env file

GRAALSTRIKE_JASPER_REPORT_USERNAME=jasperadmin
GRAALSTRIKE_JASPER_REPORT_PASSWORD=jasperadmin
GRAALSTRIKE_JASPER_REPORT_ORGID=

Basic Usage in Symfony

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

    use Symfony\Component\HttpFoundation\Request;
    use Graalstrike\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;
    }

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

    graalstrike_jasper_report:
        host:      'http://localhost:8080/jasperserver'
        username:  '%env(GRAALSTRIKE_JASPER_REPORT_USERNAME)%'
        password:  '%env(GHRAALSTRIKE_JASPER_REPORT_PASSWORD)%'
        org_id:    '%env(GRAALSTRIKE_JASPER_REPORT_ORGID)%'
        timeout:   50

timeout: timeout for REST-request (in seconds)

About

Symfony Bundle integrating the Jaspersoft REST v2 client (jaspersoft/rest-client) update for Symfony 7.4

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%