Jump to content
We've recently updated our Privacy Statement, available here ×

jmacnama

Members
  • Posts

    6
  • Joined

  • Last visited

jmacnama's Achievements

Rookie

Rookie (2/14)

  • Week One Done
  • One Month Later
  • One Year In
  • Conversation Starter Rare

Recent Badges

0

Reputation

  1. IntroductionThese configuration files perform declarative configuration with kubectl apply to deploy JasperReports Server within Kubernetes (k8s). These Kubernetes configurations leverage images created via https://github.com/TIBCOSoftware/js-docker and configuration options for the JasperReports Server containers are defined there. You must change the environment variables and declarative configuration to fit with your deployment environment, such as the platform - Docker for Windows/Mac, Minikube, Amazon EKS, Azure AKS, ... - and how you want to deploy JasperReports Server: exposed to the outside world directly: NodePort, Ingress, LoadBalancerJasperReports Server repository database location: within or external to Kubernetesuse of environment variables and volumesuse of secrets for license and keystoresThis configuration has been certified using the PostgreSQL 9 database with JasperReports Server 6.4+ and with PostgreSQL 10 for JasperReports Server 7.2+. Knowledge of Docker, Kubernetes and your infrastructure is required. For more information about Docker and containers, see the official documentation for Docker. For more information about Kubernetes, see the official documentation for Kubernetes. For more information about JasperReports Server, see: Jaspersoft Quick Start.Jaspersoft community.PrerequisitesThe following software is required or recommended: docker-engine version 1.18 or higher(required) TIBCO Jaspersoft® commercial license.Contact your sales representative for information about licensing.(Recommended) for development - they include Kubernetes:Docker Desktop for WindowsDocker Desktop for Mac(optional)kubernetes version 1.19 or higher(optional) Preconfigured PostgreSQL 9, 10 or 11 database. If you do not currently have a PostgreSQL instance, you can create a PostgreSQL container at run time.Build the Kubernetes specific command line imageBuild the main jasperserver-pro:<version> and jasperserver-pro-cmdline:<version> images in the js-docker directory. In this directory, run: docker build -f Dockerfile-cmdline-k8s -t jasperserver-pro-cmdline:k8s-<version> . Environment Variable NameNotesJASPERREPORTS_SERVER_IMAGE_TAGTag of jasperserver-pro-cmdline image to base this image on. jasperserver-pro-cmdline:<JASPERREPORTS_SERVER_IMAGE_TAG> Default: 7.9.0JASPERREPORTS_SERVER_VERSIONVersion number used in file names. Default: 7.9.0 Configure the JasperReports Server serviceBy default, this is a basic deployment, standing up a single instance service, exposed to the outside world through a LoadBalancer. The init-container in the Service, which runs a cmdline image, ensures that the JasperReports Server repository exists and the keystore files are created in the correct volume, prior to the JaspeReports Server web application starts. Modify the environment variables as needed: Refer to JasperReports Server Docker environment variablesIt refers to the repository via DB_HOST, which in the default configuration is the postgresql service within k8s defined above.Do k8s level configuration, such as pods, NodePort or LoadBalancer, use of secrets etc.You can set the NodePort the Server will run on or change the network access as you see fit.Decide on secrets and volumes below.Keystores in Secrets and VolumesYour JasperReports Server license is in a secret. kubectl create secret generic jasperserver-pro-license --from-file=jasperserver.license=./jasperserver.license -n jaspersoft Use the secret as a volume in both the init and main containers. volumeMounts: - name: license mountPath: "/usr/local/share/jasperserver-pro/license" readOnly: true volumes: - name: license secret: secretName: jasperserver-pro-license See the main README for details of other volumes. Saving KeystoresJasperReports Server keystore files need to be saved when the repository database is created or the keystore is updated via the js-import and js-export command line tools. Here are two approaches to keystore storage: Using a persistent volumeUsing a SecretA Kubernetes Secret for keystore filesKeystore files can be maintained in a Secret. The cmdline:k8s init container or job creates and updates the keystore secret. This set of files creates the JasperReports Server environment: commandNoteskubectl apply -f namespace-rbac.yamlcreates the "jaspersoft" namespace and the "jasper-robot" service account with a role that allows the JasperReports Server containers to update the keystore secret "jasperserver-pro-jrsks"kubectl apply -f secrets.yamlcreate the keystore secret "jasperserver-pro-jrsks"You can pre-load the keystore files, too, before you run the server or the command line against a new repository database. kubectl create secret generic jasperserver-pro-jrsks -n jaspersoft --from-file=.jrsks=./.jrsks --from-file=.jrsksp=./.jrsksp These secret needs to be mapped as volumes into the containers. You need to map a volume for configuration files created by the init container. At least: volumes: - name: keystore-files-secret secret: secretName: jasperserver-pro-jrsks - name: jasperserver-pro-volume emptyDir: {} And then use the secret with the containers. For the init container, use the cmdline:k8s image. initContainers: - name: init image: jasperserver-pro-cmdline:k8s-7.9.0 env: #- name: KEYSTORE_SECRET_NAME # value: "jasperserver-pro-jrsks" volumeMounts: # have the keystore secret under its own path. # init container will maintain the keystore files in # /usr/local/share/jasperserver-pro/keystore # and update the secret if needed - name: keystore-files-secret mountPath: "/usr/local/share/jasperserver-pro-secrets/jasperserver-pro-jrsks" readOnly: true - name: jasperserver-pro-volume mountPath: "/usr/local/share/jasperserver-pro" readOnly: false And for the JasperReports Server web application container: containers: - name: jasperserver-pro image: jasperserver-pro:7.9.0 env: volumeMounts: - name: license mountPath: "/usr/local/share/jasperserver-pro-secrets/license" readOnly: true # web app accesses the keystore secret directly - name: keystore-files-secret mountPath: "/usr/local/share/jasperserver-pro/keystore" readOnly: true - name: jasperserver-pro-volume mountPath: "/usr/local/share/jasperserver-pro" readOnly: true Persistent Volume for the keystore filesAn alternative is to have a persistent volume. See local-pv.yaml as an example. Run via kubectl apply -f local-pv.yaml Review jasperreports-server-k8s-volume.yaml Include the persistent volume in the service. volumes: - name: jasperserver-pro-volume persistentVolumeClaim: claimName: jasperreports-server-pv-claim And then use the persistent volume with the containers. For the init container, use the base cmdline image. initContainers: - name: init image: jasperserver-pro-cmdline:7.9.0 env: volumeMounts: - name: jasperserver-pro-volume mountPath: "/usr/local/share/jasperserver-pro" readOnly: false for the web application: containers: - name: jasperserver-pro image: jasperserver-pro:7.9.0 env: ports: volumeMounts: - name: jasperserver-pro-volume mountPath: "/usr/local/share/jasperserver-pro" readOnly: true Additional default_master.properties in a SecretAs noted in the main README you can add additional configuration properties by mapping the /usr/local/share/jasperserver-pro/deploy-customization and /usr/local/share/jasperserver-pro/buildomatic-customization volumes. The properties files can be the same. They can also be stored in Secrets. Create the secrets: kubectl create secret generic jasperserver-pro-additional-master -n jaspersoft --from-file=default_master_additional.properties=default_master_additional.propertieskubectl create secret generic jasperserver-pro-buildomatic-additional-master -n jaspersoft --from-file=default_master_additional.properties=default_master_buildomatic_additional.properties Update the secrets.yaml and jasperreports-server-service-deployment.yaml to use these properties secrets. Additional runtime environment variablesSee runtime environment variables for the main jasperserver-pro-cmdline image in the master README for this repository. For the jasperserver-pro-cmdline:k8s image: Environment Variable NameNotesKEYSTORE_SECRET_NAMEWhen using a secret to store the keystore files, this is the secret name where keystore files will be stored. Used in volumeMount paths. Default: jasperserver-pro-jrsks Configure and Start the Jaspersoft repository databaseThis JasperReports Server deloyment to Docker and k8s uses a PostgreSQL database to store configuration information. You can run the repository outside k8s. You will need to set the DB_* environment variables in the k8s configuration to point to the external database.Or run the PostgreSQL repository inside k8s, which is the default approach taken with this configuration. edit repository-database.yaml to suit your environment.This creates a persistent volume and the postgresql service in k8sset volume name, username, password, use secrets etc according to your requirementsuse kubectl to create the postgresql service: kubectl apply -f repository-database.yamlSee the main README for details on how to use other databases for the repository apart from PostgreSQL. Launch the JasperReports Server serviceLaunch the JasperReports Server. Update the references to images you have built ie. if you deployed the images into your Amazon ECR, then you will need to update your references to : .dkr.ecr..amazonaws.com/jasperserver-pro-cmdline:k8s-7.5.0 For keystores in secrets: kubectl apply -f jasperreports-server-service-deployment.yaml An initContainer manages the repository database initialization and keystore creation.ConfigMap for Deployment.Service: ClusterIP, NodePort, LoadBalancer.Note: If Service is not an external loadbalancer like aws or azure loadbalancer or using NodePort as Service then Service ports , Liveness and Readiness ports should be updated to 8080 and 8443. Otherwise launch via volumes only: kubectl apply -f jasperreports-server-k8s-volume.yaml TroubleshootingWhen running the service with keystore files in a secret, this error: Error from server (Forbidden): secrets "jasperserver-pro-jrsks" is forbidden: User "system:serviceaccount:default:default" cannot get secrets in the namespace "default" comes from the cmdline init-container not having permissions to update the secret. Check the Role being set for the namespace and the service account linked to it. Logging in to JasperReports ServerAfter the JasperReports Server container is up, log into it via URL from a browser. You can find the IP and port via: PS > kubectl get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEjasperreports-server NodePort 10.96.1.127 <none> 8080:31562/TCP 3mkubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1dpostgresql ClusterIP 10.100.26.80 <none> 5432/TCP 4mor:jasperserver-pro LoadBalancer 10.100.138.114 ab62d98fe4d3d11eab1980665fc8fbc6-1620952781.us-west-2.elb.amazonaws.com 80:30650/TCP,443:30961/TCP 3h22mp 31562 indicated above is the NodePort for the jasperreports-server service in the PORT(S) column. So login via: http://<host>:<port>/jasperserver-pro Where: host : name or IP address of your k8s cluster.port : port the jasperreports-server service is running on.JasperReports Server ships with the following default credentials: superuser/superuser - System-wide administratorjasperadmin/jasperadmin - Administrator for the default organizationCopyrightCopyright © 2019-2021. TIBCO Software Inc. This file is subject to the license terms contained in the license file that is distributed with this file. TIBCO, Jaspersoft, and JasperReports are trademarks or registered trademarks of TIBCO Software Inc. in the United States and/or other countries. Docker is a trademark or registered trademark of Docker, Inc. in the United States and/or other countries.
  2. IntroductionThis distribution includes Dockerfiles and supporting files for building, configuring, and running TIBCO JasperReports® Server commercial editions in containers. Orchestration via Kubernetes, AWS and Helm are outlined as options. These samples can be used as is or modified to meet the needs of your environment. The distribution can be downloaded from https://github.com/TIBCOSoftware/js-docker. This configuration has been certified using the PostgreSQL 9 database with JasperReports Server 6.4+ and with PostgreSQL 10 for JasperReports Server 7.2+ Basic knowledge of Docker and the underlying infrastructure is required. For more information about Docker see the official documentation for Docker. For more information about JasperReports Server, see the Jaspersoft community. PrerequisitesThe following software is required or recommended: docker-engine version 1.12 or higher(recommended):Docker Desktop for WindowsDocker Desktop for Mac(optional) docker-compose version 1.12 or higher(optional) git(required) TIBCO Jaspersoft® commercial license.Contact your sales representative for information about licensing. If you do not specify a TIBCO Jaspersoft license, the evaluation license is used.(optional) Preconfigured PostgreSQL, MySQL, Oracle, SQL Server or DB2 database. If you do not currently have a database instance, you can create a database container at deployment time.InstallationGet the js-docker Dockerfile and supporting resourcesDownload the js-docker repository as a zip and unzip it, or clone the repository from Github. To download a zip of js-docker: Go to https://github.com/TIBCOSoftware/js-dockerSelect Download ZIP on the right hand side of the screen. Select Open in Desktop if you have a Git Desktop installed. This will clone the repository for you. If you have the Git command line installed, you can clone the JasperReports Server Docker github repository at https://github.com/TIBCOSoftware/js-docker $ git clone https://github.com/TIBCOSoftware/js-docker$ cd js-docker The installed Repository structureThe js-docker github repository contains: Repository file/directoryNotesDockerfileJasperReports Server web application image. Based on Tomcat.Dockerfile-cmdlineJasperReports Server command line tools image. Initialize repository and keystore, import, export.docker-compose.ymlsample configuration for running web app and command line images via docker-compose.envsample environment variables for docker-compose.yml. Use Postgres as a repositorydocker-compose-mysql.ymldocker-compose with MySQL/MariaDB for repository.env-mysqlsample environment variables for docker-compose-mysql.ymlREADME.mdthis documentresources/directory where you put your unzipped JasperReports Server WAR file installer at build timescripts/entrypoints and scripts for images- entrypoint.shENTRYPOINT for a JasperReports Server web app container. Referred to by Dockerfile and Dockerfile-exploded.- entrypoint-cmdline.shENTRYPOINT for a JasperReports Server command line container. Referred to by Dockerfile-cmdline.kubernetes/directory of JasperReports Server Kubernetes configurationkubernetes/helm/directory of JasperReports Server Helm configuration- README.mdJasperReports Server Kubernetes documentationoptions/directory of optional configurations and customizations for JasperReports Server containers. includes creating a JasperReports Server cluster- README.mdoptions documentationplatforms/aws/directory of optional configurations and customizations for AWS- README.mdAWS documentation Building your JasperReports Server imagesThere are two images for JasperReports Server container deployments. jasperserver-pro: JasperReports Server web applicationjasperserver-pro-cmdline: Command line tools. Initialize the repository and keystore, export, import.Prepare the resources for the imagesWe need commercial editions of the JasperReports Server WAR file installer in order to build the images. Either:Download a commerical edition of JasperReports Server WAR File installer zip archive from the TIBCO eDelivery site, which is available to TIBCO/Jaspersoft customers.Or build a WAR file installer from the installation of a commercial Jaspersoft bundled installer Jaspersoft WAR File Installer builderPut the installer zip file to the resources directory in the repository structure.Run resources/unpackWARInstaller.sh or unpackWARInstaller.bat. This will create a directory like jasperreports-server-pro-X.X.X-bin. Also unzip jasperreports-server-pro-X.X.X-bin/jasperserver-pro.war into jasperreports-server-pro-X.X.X-bin/jasperserver-pro.You can do this manually as well. If you have downloaded the WAR file installer zip to your ~/Downloads directory: $ unzip -o -q ~/Downloads/TIB_js-jrs_X.X.X_bin.zip -d resources/$ cd resources/jasperreports-server-pro-X.X.X-bin$ unzip -o -q jasperserver-pro.war -d jasperserver-pro docker build time environment variablesThese can be passed on the command line with --build-arg, in an env-file, docker-compose.yml, Kubernetes etc. For the JasperReports Server Web app (WAR): Environment Variable NameNotesTOMCAT_BASE_IMAGETomcat Docker image certified for the version of JasperReports Server being deployed. Linux images using apt-get (Debian) or yum (CentOS, Redhat, Corretto/Amazon Linux 2) package managers. Default for 7.9.0: "tomcat:9.0.37-jdk11-openjdk" and for Amazon Linux "tomcat:9.0.37-jdk11-corretto".JASPERREPORTS_SERVER_VERSIONVersion number used in file names. Default for JasperReports Server: 7.9.0EXPLODED_INSTALLER_DIRECTORYDirectory below the Dockerfiles where the WAR file installer has been prepared as above. Default: resources/jasperreports-server-pro-$JASPERREPORTS_SERVER_VERSION-binHTTP_PORTHTTP port Tomcat runs on and .env file should be updated wih right port number if any non default port is used. Default: "8080"HTTPS_PORTHTTPS port Tomcat runs on and .env file should be updated wih right port number if any non default port is used. Default: "8443"JRS_HTTPS_ONLYEnables HTTPS-only mode. Default: false. A self signed SSL certificate is defined for Tomcat.DN_HOSTNAMESelf signed certificate host name. Default: "localhost.localdomain"KS_PASSWORDSSL Keystore password. Default: "changeit"POSTGRES_JDBC_DRIVER_VERSIONDefault: 42.2.5. If you change this, the new version will be downloaded from https://jdbc.postgresql.org/download.htmlJAVASCRIPT_RENDERING_ENGINEDefault: chromium. if not chromium, phantomjs will be installed.For the cmdline: Environment Variable NameNotesJAVA_BASE_IMAGEJava Docker image certified for the version of JasperReports Server being deployed. Linux images using apt-get (Debian) or yum (CentOS, Redhat, Corretto/Amazon Linux 2) package managers. JDK 8 or 11 from https://github.com/docker-library/docs/blob/master/openjdk/README.md#supported-tags-and-respective-dockerfile-links Default openjdk:11-jdk and for Amazon Linux amazoncorretto:11JASPERREPORTS_SERVER_VERSIONVersion number used in file names. Default: 7.9.0EXPLODED_INSTALLER_DIRECTORYDirectory below the Dockerfiles where the WAR file installer has been prepared as above. Default: resources/jasperreports-server-pro-$JASPERREPORTS_SERVER_VERSION-binPOSTGRES_JDBC_DRIVER_VERSIONDefault: 42.2.5. If you change this, the new version will be downloaded from https://jdbc.postgresql.org/download.html Build the imagesdocker build -t jasperserver-pro:7.9.0 . docker build -t jasperserver-pro-cmdline:7.9.0 -f Dockerfile-cmdline . docker run time environment variablesThese can be passed on the command line with -e, in an env-file, docker-compose.yml, Kubernetes etc For the JasperReports Server Web app (WAR): This image does not create the repository and keystore files. See cmdline below. Environment Variable NameNotesDB_TYPEvalid dbTypes are: postgresql, mysql, sqlserver, oracle, db2. Default: postgresql.DB_HOSTdatabase host IP or domain name. Default: postgresDB_PORTdatabase port. Default: default port for the dbTypeDB_USERdatabase username. Default: postgresDB_PASSWORDdatabase password. Default: postgresDB_NAMEJasperReports Server repository schema name in the database. Default: "jasperserver"HTTP_PORTHTTP port Tomcat runs on. Default: HTTP_PORT in imageHTTPS_PORTHTTPS port Tomcat runs on. Default: HTTPS_PORT in imageJAVA_OPTSCommand line options passed to Java. Optional. The Java heap size of JasperReports Server is automatically managed to conform to the container size.JAVA_MIN_RAM_PERCENTAGEJava heap minimum percentage in the container. Default: 33.3%JAVA_MAX_RAM_PERCENTAGEJava heap maximum percentage in the container. Default: 80.0%JDBC_DRIVER_VERSIONoptional. for non-PostgreSQL databases. Requires a JDBC driver with the required version accessible through a volume. See Use of VolumesPOSTGRES_JDBC_DRIVER_VERSIONoptional, Default: 42.2.5. If you change this, the new version will need to be installed by volume as above. See Use of VolumesJRS_DBCONFIG_REGENForces updates to the repository JNDI database configuration plus the JDBC driver in tomcat/lib. Default: false.JRS_HTTPS_ONLYEnables HTTPS-only mode. Default: false.KS_PASSWORDSSL Keystore password. Default: "changeit". Only used if a keystore is being overridden through a new keystore. See new keystore addition through volumes below.For the cmdline: If the DB_NAME repository database does not exist in the configured repository database, the cmdline image will create it, Environment Variable NameNotesDB_TYPEvalid dbTypes are: postgresql, mysql, sqlserver, oracle, db2. Default: postgresql.DB_HOSTdatabase host IP or domain name. Default: postgresDB_PORTdatabase port. Default: default port for the dbTypeDB_USERdatabase username. Default: postgresDB_PASSWORDdatabase password. Default: postgresDB_NAMEJasperReports Server repository schema name in the database. Default: "jasperserver"JAVA_OPTSCommand line options passed to Java. Optional. The Java heap size of JasperReports Server is automatically managed to conform to the container size.JAVA_MIN_RAM_PERCENTAGEJava heap minimum percentage in the container. Default: 33.3%JAVA_MAX_RAM_PERCENTAGEJava heap maximum percentage in the container. Default: 80.0%JDBC_DRIVER_VERSIONoptional. for non-PostgreSQL databases. Requires a JDBC driver with the required version accessible through a volume. See Use of VolumesPOSTGRES_JDBC_DRIVER_VERSIONoptional, Default: 42.2.5. If you change this, the new version will need to be installed by volume as above. See Use of VolumesJRS_LOAD_SAMPLESLoad JasperReports Server samples when creating the database. Default: false Configuring JasperReports Server with volumesUsing data volumesJasperReports Server requires the use of data volumes for managing persistent data and configurations. See: [Volume plugins] https://docs.docker.com/engine/extend/plugins/)[Docker volume tips](https://docs.docker.com/engine/tutorials/dockervolumes/#/important-tips-on-using-shared-volumesfor more information. JasperReports Server VolumesVolumes are required to deploy JasperReports Server in containers. For the JasperReports Server Web app (WAR): DescriptionPath to override in containerNotesLicense/usr/local/share/jasperserver-pro/licenseREQUIRED. Path to contain jasperserver.license file to use.Encryption keystore files/usr/local/share/jasperserver-pro/keystoreREQUIRED. .jrsks and .jrsksp files used to encrypt sensitive values. This volume is required for use with JRS 7.9.0, which will create these files on this volume if they do not exist when initializing the repository database.JasperReports Server customizations/usr/local/share/jasperserver-pro/customizationZip files. If a zip file contains install.sh, it will be unzipped and executed - useful for hotfixes or config changes in the image. Zip files that do not contain install.sh will be unzipped into ${CATALINA_HOME}/webapps/jasperserver-pro. Files are processed in alphabetical order, so duplicate file names within zips can be overridden.Tomcat level customizations/usr/local/share/jasperserver-pro/tomcat-customizationZip files that are unzipped into ${CATALINA_HOME}. Files are processed in alphabetical order, so duplicate file names within zips can be overridden.SSL keystore file/usr/local/share/jasperserver-pro/ssl-certificate.keystore file containing the certificate in this volume will be loaded into /root and Tomcat updated to use it. The keystore password must be set as the KS_PASSWORD environment variable.Additional default_master installation properties/usr/local/share/jasperserver-pro/deploy-customizationdefault_master_additional.properties file contents appended to default_master.properties. See "To install the WAR file using js-install scripts" in JasperReports Server Installation GuideJDBC driver for the repository database/usr/src/jasperreports-server/buildomatic/conf_source/db/dbType/jdbcOverride JDBC drivers within the image for the repository. Valid dbTypes are: postgresql, mysql, sqlserver, oracle, db2. Need to set the JDBC_DRIVER_VERSION environment variable to the version number of the driver.Note: Tomcat and JasperReports server customizations are applied after deploying the JasperReports Server Application in tomcat. For the cmdline: DescriptionPath to override in containerNotesLicense/usr/local/share/jasperserver-pro/licenseREQUIRED. Path to contain jasperserver.license file to use.Encryption keystore files/usr/local/share/jasperserver-pro/keystoreREQUIRED. .jrsks and .jrsksp files used to encrypt sensitive values. This volume is required for use with JRS 7.9.0, which will create these files on this volume if they do not exist when initializing the database.Additional default_master installation properties/usr/local/share/jasperserver-pro/deploy-customizationdefault_master_additional.properties file contents appended to default_master.properties. See "To install the WAR file using js-install scripts" in JasperReports Server Installation GuideJDBC driver for the repository database/usr/src/jasperreports-server/buildomatic/conf_source/db//jdbcOverride JDBC drivers within the image for the repository. Valid dbTypes are: postgresql, mysql, sqlserver, oracle, db2. Need to set the JDBC_DRIVER_VERSION environment variable to the version number of the driver.Buildomatic customizations/usr/local/share/jasperserver-pro/buildomatic_customizationZip files. If a zip file contains install.sh, it will be unzipped and executed - useful for hotfixes or config changes in the image. Zip files that do not contain install.sh will be unzipped into ${BUILDOMATIC_HOME}. Files are processed in alphabetical order, so duplicate file names within zips can be overridden.Setting volumesdocker run -v external_volume:<path to override in container> docker-compose volumes - jrs_license:/usr/local/share/jasperserver-pro/license If you update the files in a volume listed above, you will need to restart the container, as these are only processed at container start time. Paths to data volumes on Mac and WindowsYou can mount a volume to a directory on your local machine. For example, to access a license on a local directory on Mac: docker run --name new-jrs -v /<path>/resources/license:/usr/local/share/jasperserver-pro/license -v /<path>/resources/keystore:/usr/local/share/jasperserver-pro/keystore -p 8080:8080 -e DB_HOST=172.17.10.182 -e DB_USER=postgres -e DB_PASSWORD=postgres -d jasperserver-pro:X.X. Volumes in Docker for Windows need to be under the logged in user's User area ie. volumes - /C/Users/<user>/Documents/License:/usr/local/share/jasperserver-pro/license Windows paths need some help with a Docker Compose environment setting COMPOSE_CONVERT_WINDOWS_PATHS=1 Initializing the JasperReport Server RepositorySet the dbType and DB_* environment variables as outlined above. PostgreSQL (default), MySQL, Oracle, SQL Server and DB2 can be configured as repository databases. The default command of the cmdline container - init - will detect whether the repository host exists and can be connected to, and whether the repository database exists in the host, and create them as needed. The JRS_LOAD_SAMPLES environment variable can be set to true to load the JasperReports Server samples and their underlying databases into the repository database. Also there is the standalone init command for the image that allows you to pre-create the repository database and samples. docker run --rm --env-file .env -e DB_HOST=jasperserver_pro_repository -v /path/to/directoryContainingLicense:/usr/local/share/jasperserver-pro/license -v /path/to/directoryForKeystores:/usr/local/share/jasperserver-pro/keystore --name jasperserver-pro-init jasperserver-pro-cmdline:X.X.X init The JasperReports Server samples can be loaded via the init command without setting the JRS_LOAD_SAMPLES environment variable. Add samples as a parameter to the init command as follows: docker run --rm --env-file .env -e DB_HOST=jasperserver_pro_repository -v /path/to/directoryContainingLicense:/usr/local/share/jasperserver-pro/license -v /path/to/directoryForKeystores:/usr/local/share/jasperserver-pro/keystore --name jasperserver-pro-init jasperserver-pro-cmdline:X.X.X init samples Using a pre-existing databaseTo run a JasperReports Server container with a pre-existing PostgreSQL instance, execute these commands: $ docker run --name some-jasperserver-cmdline -e DB_HOST=some-external-host -e DB_USER=username -e DB_PASSWORD=password -v /path/to/directoryContainingLicense:/usr/local/share/jasperserver-pro/license -v /path/to/directoryForKeystores:/usr/local/share/jasperserver-pro/keystore jasperserver-pro-cmdline:X.X.X$ docker run --name some-jasperserver -p 8080:8080 -e DB_HOST=some-external-host -e DB_USER=username -v /path/to/directoryContainingLicense:/usr/local/share/jasperserver-pro/license -v /path/to/directoryForKeystores:/usr/local/share/jasperserver-pro/keystore -e DB_PASSWORD=password -d jasperserver-pro:X.X.X Where jasperserver-pro-cmdline:X.X.X is the image name and version tag of the jasperserver-pro-cmdline image you built. This image will be used to create containers.some-jasperserver-cmdline is the name of the new JasperReports Server cmdline containerjasperserver-pro:X.X.X is the image name and version tag of the jasperserver-pro web application image you built. This image will be used to create containers.some-jasperserver is the name of the new JasperReports Server web application containersome-external-host is the hostname, fully qualified domain name (FQDN), or IP address of your database serverusername and password are the user credentials for your repository database serverUsing a database containerUse linking to run JasperReports Server with the repository database in a container. $ docker run --name some-postgres -e POSTGRES_USER=username -e POSTGRES_PASSWORD=password -d postgres:10$ docker run --name some-jasperserver-cmdline --link some-postgres:postgres -v /path/to/directoryContainingLicense:/usr/local/share/jasperserver-pro/license -v /path/to/directoryForKeystores:/usr/local/share/jasperserver-pro/keystore -e DB_HOST=some-postgres -e DB_USER=username -e DB_PASSWORD=password jasperserver-pro-cmdline:X.X.X$ docker run --name some-jasperserver --link some-postgres:postgres -p 8080:8080 -e DB_HOST=some-postgres -e DB_USER=db_username -v /path/to/directoryContainingLicense:/usr/local/share/jasperserver-pro/license -v /path/to/directoryForKeystores:/usr/local/share/jasperserver-pro/keystore -e DB_PASSWORD=db_password -d jasperserver-pro:X.X. Where some-postgres is the name of your new database containerusername and password are the user credentials to use for the new PostgreSQL container and JasperReports Server containerpostgres:10 PostgreSQL 10 is the PostgreSQL image from Docker Hub. This can be replaced with other database types that match the dbType environment variablejasperserver-pro-cmdline:X.X.X is the image name and version tag of the jasperserver-pro-cmdline image you built. This image will be used to create containers.some-jasperserver-cmdline is the name of the new JasperReports Server cmdline containerjasperserver-pro:X.X.X is the image name and version tag for your build. This image will be used to create containerssome-jasperserver is the name of the new JasperReports Server containerdb_username and db_password are the user credentials for accessing the database server. Database settings should be modified for your setupBuilding and running with docker-composedocker-compose.yml provides a sample Compose implementation of JasperReports Server with PostgreSQL server, configured with volumes for JasperReports Server web application and license, with pre-setup network and mapped ports. There is also a pre-configured .env file for use with docker-compose. To build and run using docker-compose.yml, execute the following commands in the root directory of your repository. $ docker-compose build$ docker-compose run jasperserver-pro-cmdline$ docker-compose up -d jasperserver-pro There is also a .env-mysql to show how an external MySQL database running on the default 3306 port can be used as a repository. Note that you should set the amount of memory and CPU that each JasperReports Server container uses. The options below in the docker-compose.yml are recommended as starting points, and may need to be increased if the container is under heavy load. The entrypoint.sh configures the underlying Java memory settings according to the container memory settings. mem_limit: 3g mem_reservation: 1g cpu_shares: 250 Import and ExportOne maintenance aspect of the JasperReports Server is exporting and importing content - reports, domains and other metadata - with the repository. The cmdline image has commands to allow you to run the JasperReports Server image to do imports and export directly to a JasperReports Server repository database, leveraging the JRS command line js-export and js-import tools, documented in the JasperReports Server Administration Guide. See [Jaspersoft Documentation](https://community.jaspersoft.com/documentation and search for "Administration" in the page to get the latest. Exporting to a JasperReports Server repositoryCreate an 'export.properties' file in a directory, with each line containing parameters for individual imports: zip files and/or directories. See the JasperReports Server Administration Guide - section: "Exporting from the Command Line" for the options.# Comment lines are ignored, as are empty line# Server setting--output-zip BS-server-settings-export.zip --include-server-settings# Repository export--output-zip Bikeshare-JRS-export.zip --uris /public/Bikeshare_demo# Repository export--output-dir some-sub-directory# Organization export. The organization has to be created before running this import.--output-zip Bikeshare_org_user_export.zip --organization Bikeshar Run the JasperReports Server image with the export command defining and passing into the command in one or more volumes where the export.properties is and the exports are to be stored. And do either: Use existing database running in Docker. Note the network and DB_HOST settings docker run --rm -v /path/to/a/volume:/usr/local/share/jasperserver-pro/export -v /path/to/a/volume-license:/usr/local/share/jasperserver-pro/license -v /path/to/a/volume-keystore:/usr/local/share/jasperserver-pro/keystore --network js-docker_default -e DB_HOST=jasperserver_pro_repository --name jasperserver-pro-export jasperserver-pro-cmdline:X.X.X export /usr/local/share/jasperserver-pro/export Use an external repository database. Note the DB_HOST settingsdocker run --rm -v /path/to/a/volume:/usr/local/share/jasperserver-pro/import -v /path/to/a/volume-license:/usr/local/share/jasperserver-pro/license -v /path/to/a/volume-keystore:/usr/local/share/jasperserver-pro/keystore -e DB_HOST=domain.or.IP.where.repository.database.is --name jasperserver-export jasperserver-pro:X.X.X export /usr/local/share/jasperserver-pro/import After an export run, for each volume passed in: A sub-directory below the export file is created: export-YYYY-MM-DD-HH-MM-SSthe export.properties file is copied into that sub-directory as export.properties.the exported files are in that sub-directorythe log of the export process is in that sub-directory: export-YYYY-MM-DD-HH-MM-SS.logImporting to a JasperReports Server repositorCreate an 'import.properties' file in a directory, with each line containing parameters for individual imports from export zip files and/or directories. See the JasperReports Server Administration Guide - section: "Importing from the Command Line" for the options.# Comment lines are ignored, as are empty lines# Server setting--input-zip BS-server-settings-export.zip# Repository import--input-zip Bikeshare-JRS-export.zip# Import from a directory--input-dir some-sub-directory# Organization import. Org has to be created before running this import--input-zip Bikeshare_org_user_export.zip --organization Bikeshar Place the ZIP files and/or directories into the same directory as the import.properties Run the JasperReports Server image, defining and passing into the command one or more volumes where the import.properties and the exports are stored And do either: Use a database instance running in your container environment. Note the network and DB_HOST settingsdocker run --rm -v /path/to/a/volume:/usr/local/share/jasperserver-pro/import -v /path/to/a/volume-license:/usr/local/share/jasperserver-pro/license -v /path/to/a/volume-keystore:/usr/local/share/jasperserver-pro/keystore --network js-docker_default -e DB_HOST=jasperserver_pro_repository --name jasperserver-pro-import jasperserver-pro:X.X.X import /usr/local/share/jasperserver-pro/import Use an external repository database. Note the DB_HOST setting.docker run --rm -v /path/to/a/volume:/usr/local/share/jasperserver-pro/import -v /path/to/a/volume-license:/usr/local/share/jasperserver-pro/license -v /path/to/a/volume-keystore:/usr/local/share/jasperserver-pro/keystore -e DB_HOST=domain.or.IP.where.database.is --name jasperserver-import jasperserver-pro:X.X.X import /usr/local/share/jasperserver-pro/import After an import run, for each volume passed in: A sub-directory below the import file is created: import-YYYY-MM-DD-HH-MM-SSthe import.properties file is moved into that sub-directory as import.properties.the log of the import process is in that sub-directory: import-YYYY-MM-DD-HH-MM-SS.logNote that, as of JasperReports 7.2.0 at least, there is no way to import a organization export.zip at the highest level (root) without first creating the organization via the JasperReports Server user interface or REST. JasperReports Server container logsBy default, the JasperReports Server log is streamed to the console so default Docker logging can pick that up. Beyond the console. there are multiple options for log access, aggregation, and management in the Docker ecosystem. The most common options are: volumizing log fileusing container logs [logging drivers]https://docs.docker.com/engine/admin/logging/overview/For the TIBCO JasperReports Server containers, the default json-file docker drivers should be sufficient. In a more complex environment a log collector should be considered. One example is collecting logs on a remote syslog server. See the [logging drivers](https://docs.docker.com/engine/admin/logging/overview/ documentation for more information. To volumize the JasperReports Server container log, you can create a container for log storage. $ docker volume create --name some-jasperserver-log$ docker run --name some-jasperserver -v some-jasperserver-log:/usr/local/tomcat/webapps/jasperserver-pro/WEB-INF/logs -p 8080:8080 -e DB_HOST=172.17.10.182 -e DB_USER=postgres -e DB_PASSWORD=postgres -d jasperserver-pro:X.X. Where: some-jasperserver-log is the name of the new data volume for log storagesome-jasperserver is the name of the new JasperReports Server containerjasperserver-pro:X.X.X is the image name and version tag for your build. This image will be used to create containersDatabase settings should be modified for your setupNote that docker containers do not have separate logs. All information is logged via the driver or application. In the case of the JasperReports Server container, the main log is output by Tomcat to the docker-engine via the logging driver, and the application log specific to JasperReports Server is output to some-jasperserver-log:/usr/local/tomcat/webapps/jasperserver-pro/WEB-INF/logs Logging in to JasperReports ServerAfter the JasperReports Server container is up, log into it via URL The URL depends upon your installation. The default configuration uses: http://<domain or IP>:8080/jasperserver-proor if running on port 80:http://<domain or IP>/jasperserver-pro Where: localhost is the name or IP address of the computer hosting JasperReports Server8080 is the port number for the Apache Tomcat application server.If you used a different port when installing your application server, specify its port number instead of 8080 JasperReports Server ships with the following default credentials superuser/superuser - System-wide administratorjasperadmin/jasperadmin - Administrator for the default organizationTroubleshootingUnable to download phantomjsAt build-time Docker fails with an error "403: Forbidden" when downloading phantomjs 2016-09-19 20:54:50 ERROR 403: Forbidden This occurs when the phantomjs binary is temporarily unavailable for download. You can do one of the following: disable the phantomjs download, change the URL, or use a locally-downloaded phantomjs archive. See Dockerfile for details. Note that if you had a successful build and the Docker cache has not been invalidated, you do not need to re-download phantomjs on a subsequent build. "No route to host" error on a VPN or network with maskThe default Docker network may conflict with your VPN space. Change to a different CIDR for the Docker network using --bip See the [Docker networking documentation]https://docs.docker.com/v1.8/articles/networking/#docker0 for more information; for Mac, also see: Docker issue 25064 docker volume inspect returns incorrect paths on MacOSDue to the nature of [Docker for Mac]https://docs.docker.com/engine/installation/mac/#/docker-for-mac, docker volume inspect returns paths that are relative to the main docker process. You must either access the path in the container, for example: /var/lib/docker/volumes/some-jasperserver-license/_data or define a volume path instead of a named volume This also applies to Docker Compose. See Using data volumes for defining a local path For more information see Docker Community Forums: [Host path of volume] https://forums.docker.com/t/host-path-of-volume/12277/6 Connection to repository database failThe entrypoint.sh tries to connect to the repository database before starting the Server. If there are problems, there will be 5 retries to connect before stopping the process. You can see the problem in the JasperReports Server container log. PS C:UsersuserDocumentsGitHubjs-docker> docker run --rm --env-file .env-mysql--name jrs-init-test -v /C/Users/user/Documents/Docker/buildomatic/mysql/jdbc:/usr/src/jasperreports-server/buildomatic/conf_source/db/mysql/jdbcjasperserver-pro:X.X.X ini [exec] Execute failed: java.io.IOException: Cannot run program "git": error=2, No such file or directoryBUILD FAILED/usr/src/jasperreports-server/buildomatic/bin/validation.xml:493: The following error occurred while executing this line/usr/src/jasperreports-server/buildomatic/bin/validation.xml:374: The following error occurred while executing this line/usr/src/jasperreports-server/buildomatic/conf_source/db/mysql/db.xml:73: The following error occurred while executing this line/usr/src/jasperreports-server/buildomatic/bin/validation.xml:411: The following error occurred while executing this line/usr/src/jasperreports-server/buildomatic/bin/validation.xml:468: Invalid username/password combination: [jaspersoftX/jaspersoft] Treating problem with JDBC connection as unrecoverableTotal time: 0 secondsaw 0 OK connections, not at least test_connection returned fai You will need to review the network connection between the Server and the database instance, and review DB_* environment settings Docker documentationFor additional questions regarding docker and docker-compose usage see: docker-engine documentationdocker-compose documentationCopyrightCopyright © 2021. TIBCO Software Inc This file is subject to the license terms contained in the license file that is distributed with this file. __ TIBCO, Jaspersoft, and JasperReports are trademarks of registered trademarks of TIBCO Software Inc in the United States and/or other countries. Docker is a trademark or registered trademark of Docker, Inc. in the United States and/or other countries.
  3. jmacnama

    Expressions

    Many settings in a report are defined by formulas, such as conditions that can hide an element, special calculations, or text processing that requires knowledge of a scripting language. Formulas can be written in at least three languages, two of which (JavaScript and Groovy) can be used without knowledge of programming methods. All formulas in JasperReports are defined through expressions. The default expression language is Java, but if you're not a programmer, we recommend JavaScript or Groovy, because those languages hide a lot of the Java complexity. The language is a property of the document. To set it, select the document root node in the Outline view and choose your language in the Language property in the Properties view. An expression is a formula that operates on some values and returns a result, like a formula in a spreadsheet cell. A cell can have a simple value or a complex formula that refers to other values. In a spreadsheet you refer to values contained in other cells; in JasperReports you use the report fields, parameters, and variables. Whatever is in your expression, when it's computed, it returns a value (which can be null). Expression TypesAn expression's type is determined by the context in which the expression is used. For example, if your expression is used to evaluate a condition, the expression should be Boolean (true or false); if you're creating an expression to display in a text field, it's probably a String or a number (Integer or Double). Using the right type is crucial; JasperReports requires precision when choosing an expression type. Some of the most important Java types are: java.lang.Boolean Defines an Object that represents a Boolean value such as true and false java.lang.Byte Defines an Object that represents a byte java.lang.Short Defines an Object that represents an short integer java.lang.Integer Defines an Object that represents integer numbers java.lang.Long Defines an Object that represents long integer numbers java.lang.Float Defines an Object that represents floating point numbers java.lang.Double Defines an Object that represents real numbers java.lang.String Defines an Object that represents a text java.util.Date Defines an Object that represents a date or a timestamp java.lang.Object A generic java Object If an expression is used to determine the value of a condition that determines, for instance, whether an element should be printed, the return type is java.lang.Boolean. To create it, you need an expression that returns an instance of a Boolean object. Similarly, if an expression shows a number in a text field, the return type is java.lang.Integer or java.lang.Double. Neither JavaScript nor Groovy is particularly formal about types, since they are not typed languages; the language itself treats a value in the best way by trying to guess the value type or by performing implicit casts (conversion of the type). Expression Operators and Object MethodsOperators in Java, Groovy and JavaScript are similar because these languages share the same basic syntax. Operators can be applied to a single operand (unary operators) or on two operands (binary operators). The following table shows a number of operators, but it is not a complete list. For example, there is a unary operator to add 1 to a variable (++), but it is easier to use x + 1. Expression operators Operator Description Example + Sum (it can be used to sum two numbers or to concatenate two strings) A + B - Subtraction A - B / Division A / B % Rest, it returns the rest of an integer division A % B || Boolean operator OR A || B && Boolean operator AND A && B == Equals A == B != Not equals A != B ! Boolean operator NOT !A Regarding the Equals operator: in Java, the == operator can only be used to compare two primitive values. With objects, you need to use the special method “equals”; for example, you cannot write an expression like "test" == "test", you need to write "test".equals("test"). Regarding the Equals operator: in Java, the != operator can only be used to compare two primitive values. Within an expression, you can use the syntax summarized in Syntax for referring to report objects to refer to the parameters, variables, and fields defined in the report. Syntax for referring to report objects Syntax Description $F{name_field} Specifies the name_field field ("F" means field). $V{name_variable} Specifies the name_variable variable. $P{name_parameter} Specifies the name_parameter parameter. $P!{name_parameter} Special syntax used in the report SQL query to indicate that the parameter does not have to be dealt as a value to transfer to a prepared statement, but that it represents a little piece of the query. $R{resource_key} Special syntax for localization of strings. $X{functionName, col_name, param1,[param2]}Syntax for complex queries, such as comparing a column value to a parameter value. Based on the function in the first argument, JasperReports constructs a SQL clause. The following functions are available: •Functions expecting three arguments for $X{} – EQUAL, NOTEQUAL, LESS, LESS] (less than or equal to), GREATER, [GREATER (greater than or equal to), IN, NOTIN. For example:$X{EQUAL, order_date, date_parameter} •Functions expecting four arguments for $X{} – BETWEEN (excludes both endpoints) BETWEEN] (includes right endpoint) [bETWEEN (includes left endpoint) [bETWEEN] (includes both endpoints) For example: $X{BETWEEN, order_date, start_date_param, end_date_param} In summary, fields, variables and parameters represent objects; specify their type when you declare them within a report. Although expressions can be complicated, usually it is a simple operation that returns a value. There is a simple if-else expression that is very useful in many situations. An expression is just an arbitrary operation that any stage must represent a value. In Java, these operators can be applied only to primitive values, except for the sum operator (+). The sum operator can be applied to a String expression with the special meaning of concatenate. For example: $F{city} + “, ” + $F{state} results in a string like: San Francisco, California Any object in an expression can include methods. A method can accept zero or more arguments, and it can return or not a value. In an expression you can use only methods that return a value; otherwise, you would have nothing to return from your expression. The syntax of a method call is: Object.method(argument1, argument2, <etc.>) Some examples: Expression Result “test”.length() 4 “test”.substring(0, 3) “tes” “test”.startsWith(“A”) false “test”.substring(1, 2).startsWith(“e”) true The methods of each object are usually explained in the JasperReports Library Javadocs, which that are available at http://jasperreports.sourceforge.net/api/. You can use parentheses to isolate expressions and make the overall expression more readable. Using an If-Else Construct in an ExpressionA way to create an if-else-like expression is by using the special question mark operator. For example: (($F{name}.length() > 50) ? $F{name}.substring(0,50) : $F{name}) The syntax is (<condition>) ? <value on true> : <value on false>. It is extremely useful, and can be recursive, meaning that the value on true and false can be represented by another expression which can be a new condition: (($F{name}.length() > 50) ? (($F{name}.startsWidth(“A”)) ? “AAAA” : “BBB”) : $F{name}) This expression returns the String AAAA when the value of the field name is longer than 50 characters and starts with A, returns BBB if it is longer than 50 characters but does not start with A, and, finally, returns the original field value if neither of these conditions is true. Despite the possible complexity of an expression, it can be insufficient to define a needed value. For example, if you want to print a number in Roman numerals or return the name of the weekday of a date, it is possible to transfer the elaborations to an external Java class method, which must be declared as static, as shown in the following example: MyFormatter.toRomanNumber( $F{MyInteger}.intValue() ) The function operand toRomanNumber is a static method of the MyFormatter class, which takes an int as argument (the conversion from Integer to int is done by means of the intValue() method; it is required only when using Java as language) and gives back the Roman version of a number in a lace. This technique can be used for many purposes; for example, to read the text from a CLOB field or to add a value into a HashMap (a Java object that represents a set of key/value pairs). Using Unicode Characters in ExpressionsYou can use Unicode syntax to write non-Latin-based characters (such as Greek, Cyrillic, and Asian characters). For these characters, specify the Unicode code in the expression that identifies the field text. For example, to print the Euro symbol, use the Unicode u20ac character escape. The expression u20ac is not simple text; it is a Java expression that identifies a string containing the € character. If you use this character in a static text element, “u20ac” will appear. The value of a static field is not interpreted as a Java expression. Using Java as a Language for ExpressionsJava was the first language supported by JasperReports and is still the most commonly-used language as well as being the default. Following are some examples of Java expressions: •“This is an expression” •new Boolean(true) •new Integer(3) •(($P{MyParam}.equals("S")) ? "Yes" : "No") new Integer( 5 + 3 )The first thing to note is that each of these expressions represents a Java Object, meaning that the result of each expression is a non-primitive value. The difference between an object and a primitive value makes sense only in Java, but it is very important: a primitive value is a pure value like the number 5 or the Boolean value true. Operations between primitive values have as a result a new primitive value, so the expression: 5+5 results in the primitive value 10. Objects are complex types that can have methods, can be null, and must be “instanced” with the keyword “new” most of the time. In the second example above, for instance (new Boolean(true)), we must wrap the primitive value true in an object that represents it. By contrast, in a scripting language such as Groovy and JavaScript, primitive values are automatically wrapped into objects, so the distinction between primitive values and objects wanes. When using Java, the result of our expression must be an object, which is why the expression 5+3 is not legal as-is but must be fixed with something like this: The fix creates a new object of type Integer representing the primitive value 10. So, if you use Java as the default language for your expressions, remember that expressions like the following are not valid: •3 + 2 * 5 •true •(($P{MyParam} == 1) ? "Yes" : "No") Groovy is a full language for the Java 2 Platform. Inside the Groovy language you can use all classes and JARs that are available for Java. The following table compares some typical JasperReports expressions written in Java and Groovy:These expressions don’t make the correct use of objects. In particular, the first and the second expressions are not valid because they are of primitive types (integer in the first case and boolean in the second case) which do not produce an object as a result. The third expression is not valid because it assumes that the MyParam parameter is a primitive type and that it can be compared through the == operator with an int, but it cannot. In fact, we said that parameters, variables, and fields are always objects and primitive values cannot be compared or used directly in a mathematical expression with an object. Using Groovy as a Language for ExpressionsThe modular architecture of JasperReports provides a way to plug in support for languages other than Java. By default, the library supports Groovy and JavaScript. Groovy and Java code samples Expression Java Groovy Field $F{field_name} $F{field_name} Sum of two double fields new Double($F{f1}.doubleValue() + $F{f2}.doubleValue()) $F{f1} + $F{f2} Comparison of numbers new Boolean($F{f}.intValue() == 1) $F{f} == 1 Comparison of strings new Boolean($F{f} != null && $F{f}.equals("test")) $F{f} == "test" The following is a correct Groovy expression: new JREmptyDataSource($F{num_of_void_records}) JREmptyDataSource is a class of JasperReports that creates an empty record set (meaning with the all fields set to null). You can see how you can instance this class (a pure Java class) in Groovy without any problem. At the same time, Groovy allows you to use a simple expression like this one: 5+5 The language automatically encapsulates the primitive value 10 (the result of that expression) in a proper object. Actually, you can do more: you can treat this value as an object of type String and create an expression such as: 5 + 5+ ”my value” Whether or not such an expression resolves to a rational value, it is still a legal expression and the result is an object of type String with the value: 10 my value Hiding the difference between objects and primitive values, Groovy allows the comparison of different types of objects and primitive values, such as the legal expression: $F{Name} == “John” This expression returns true or false, or, again: $F{Age} > 18 Returns true if the Age object interpreted as a number is greater than 18. “340” < 100 Always returns false. “340”.substring(0,2) < 100 Always returns true (since the substring method call produces the string “34”, which is less than 100). Groovy provides a way to greatly simplify expressions and never complains about null objects that can crash a Java expression throwing a NullPointerException. It really does open the doors of JasperReports to people who don’t know Java. Using Javascript as a Language for ExpressionsJavaScript is a popular scripting language with a syntax very similar to Java and Groovy. JavaScript has a set of functions and object methods that in some cases differ from Java and Groovy. For example, the method String.startsWith(...) does not exist in JavaScript. You can still use Java objects in JavaScript. An example is: (new java.lang.String("test")).startsWith("t") This is a valid JavaScript expression creating a Java object (in this case a java.lang.String) and using its methods. JavaScript is the best choice for users who have no knowledge of other languages. The other significant advantage of JavaScript is that it is not interpreted at run time, but instead generates pure Java byte-code. As a result, it offers almost the same performance as Java itself.
  4. You can create a report that filters information based on a date range relative to the current system date using a parameter of type DateRange. A date range parameter can take either a date or a text expression that specifies a date range relative to the current system date. A relative date expression is always calculated in the time zone of the logged-in user. However, the start day of the week can be configured independent of locale. Relative Date Keywords The text expression for the relative date must be in the format <Keyword>+/-<N> where: •<Keyword> – Specifies the time span you want to use. Options include: DAY, WEEK, MONTH, QUARTER, SEMI, and YEAR. •<+/-> – Specifies whether the time span occurs before (-) or after (+) the chosen date. •<N> – Specifies the number of the above-mentioned time spans you want to include in the filter.For example, if you want to look at Sales for the prior month, your expression would be MONTH - 1. Relative dates don't currently support keywords like "Week-To-Date" (from the start of the current week to the end of the current day). However, you can set a relative date period in a query in JRXML using BETWEEN, which has the syntax: $X{BETWEEN, column, startParam, endParam} For example, to create a week-to-date query, set startParam to WEEK and endParam to DAY. You can do this for other time ranges, such as Year-To-Day, Year-To-Week, and so forth. Creating a Date Range Parameter The class attribute of a JasperReports date range parameter must have one of the following values: •net.sf.jasperreports.types.date.DateRange (Date only) – Accepts text strings with relative date keywords as described above and date strings in YYYY-MM-DD format. For example:<parameter name="myParameter" class="net.sf.jasperreports.types.date.DateRange"> •net.sf.jasperreports.types.date.TimestampRange (Date and Time) – Accepts text strings with relative date keywords as described above and date strings in YYYY-MM-DD HH:mm:ss format. For example: <parameter name="myParam" class="net.sf.jasperreports.types.date.TimestampRange"> Using Date Ranges in Queries You must use $X{} functions with date ranges, because $P{} does not support the date-range types (DateRange and TimestampRange). To use date ranges, create a parameter with type date range and use it as the third argument in the $X{} function. To set the default value expression of a date range parameter, use the DateRangeBuilder() class to cast the expression to the correct type: •new net.sf.jasperreports.types.date.DateRangeBuilder("DAY-1").toDateRange() – casts a keyword text string to a DateRange. •new net.sf.jasperreports.types.date.DateRangeBuilder("WEEK").set(Timestamp.class).toDateRange() – casts a keyword text string to a TimestampRange. •new net.sf.jasperreports.types.date.DateRangeBuilder("2012-08-01").toDateRange()– casts a date in YYYY-MM-DD format to a DateRange. •new net.sf.jasperreports.types.date.DateRangeBuilder("2012-08-01 12:34:56").toDateRange()– casts a date in YYYY-MM-DD HH:mm:ss format to a TimestampRange.The following JRXML example shows data from the previous day: This JRXML example shows results prior to the end of last month: The following table shows two additional examples of relative dates. Problem Solution Set up a relative date parameter called StartDate that takes the value: QUARTER. QUARTER evaluates to the first day (the first instant, really) of this quarter.Find all purchases made previous to this quarter SQL: select * from orders where $X{LESS, order_date, StartDate} Find all purchases made in this quarter select * from orders where $X{EQUAL, order_date, StartDate} Using Relative Dates in Input Controls When you create an input control for a DateRange or TimestampRange parameter, the user can either type a relative date expression or enter a specific date (either by typing or by using the calendar widget). Use BETWEEN to set up input controls that allow the user to specify a range (other than a day) using either a relative date expression or actual dates. To do this: •Define two date range parameters, for example, StartDate and EndDate. •Optionally, set default values for one or both parameters using defaultValueExpression. •Use a $X{} expression with a BETWEEN function in your query. •Create a date type input control for each parameter, for example, StartDate and EndDate.The following JRXML example uses the BETWEEN keyword in the $X() function to find all data from the previous 20 years: You can use the getStart() and getEnd() methods to get the precise beginning and end of a relative date. Both of these methods return a date instead of a date range. The following example shows how to get the precise start date as a default value expression. Publishing Reports with Relative Dates to JasperReports Server Jaspersoft Studio automatically enables support for date range expressions on connections to JasperReports Server. To verify that date range expressions are enabled: 1.Right-click on the server connection in the Repository and select Edit. 2.In the Server profile wizard, display the Advanced settings and select Supports DateRange Expressions.When Supports DateRange Expressions is enabled, input controls for date range parameters work correctly when published to JasperReports Server.
  5. Jaspersoft Studio uses these objects in data source queries. In order to use these objects in a report, they must be declared with a discrete type that corresponds to a Java class, such as String or Double. After they have been declared in a report design, the objects can be modified or updated during the report generation process. Setup: Jaspersoft Studio displays available fields as children of the Fields node in the document outline view. To create a field, right-click the Fields node and select Create Field. The new field is included as an undefined entry on the Properties tab. You can configure the field properties by selecting it. Select the Object tab to name your field, enter a description, and choose a class. Object Tab in Properties View of a Field Select the Advanced tab to enter advanced properties for the field. Advanced Tab in Properties View of a Field A field is identified by a unique name, a type, and an optional description. Inside each report expression (like the one used to set the content of a text field) Jaspersoft Studio specifies a field object, using the following syntax: $F{<field name>} where <field name> must be replaced with the name of the field. When using a field expression (for example, calling a method on it), keep in mind that it can have a value of null, so you should check for that condition. An example of a Java expression that checks for a null value is: ($F{myField} != null) ? $F{myFiled}.doSomething() : null This method is generally valid for all the objects, not just fields. Using Groovy or JavaScript this is rarely a problem, since those languages handle a null value exception in a more transparent way, usually returning an empty string. In some cases a field can be a complex object, like a JavaBean, not just a simple value like a String or an Integer. A trick to convert a generic object to a String is to concatenate it to an empty string this way: $F{myfield}+ “” All Java objects can be converted to a string; the result of this expression depends on the individual object implementation (specifically, by the implementation of the toString() method). If the object is null, the result returns the literal text string “null” as a value. Getting Data: A print is commonly created starting from a data source that provides a set of records composed of a series of fields. This behavior is exactly like obtaining the results of an SQL query. You can also define a set of name/value pair properties for each field. Field properties are used by QueryExecutors to configure fields, for example, to set up the timezone or date, or to configure the number format to be used. In many QueryExecuters where the data source is not a flat table (such as MDX, JSON, or XPath), properties can contain instructions or addresses to data. For JDBC, properties can be used to indicate the index of the column in the dataset; you can also set a property for the column name, which functions as an alias. Applications like Jaspersoft Studio can use properties to store useful information: for example, column size could be used to size the TextFields or Table cells during report design. Field properties can be static or dynamic; that is, you can set the value using an expression, which will be evaluated at the beginning of dataset iteration. Jaspersoft Studio determines the value for a field based on your data source. For example, when using an SQL query to fill a report, Jaspersoft Studio assumes that the name of the field matches the name of a field in the query result set. You must ensure that the field name and type match the field name and type in the data source. You can systematically declare and configure large numbers of fields using the tools provided by Jaspersoft Studio. Because the number of fields in a report can be quite large (possibly reaching the hundreds), Jaspersoft Studio provides different tools for handling declaration fields retrieved from particular types of data sources. Use Case: To print a field in a text element, you must set the expression and the textfield class type correctly. You may also need to define a formatting pattern for the field. To create a corresponding text field, drag the field you want to display from the Outline view into the design panel. Jaspersoft Studio creates a new text field with the correct expression (for example, $F{fieldname}) and assigns the correct class name.
  6. The difference between Pixel Perfect and Web (Jaspersoft Studio v JasperReports Server) is primarily in there uses. JSS allow you fine-grained, manual control over report layout and generation. However, it is a desktop tool, so you still need JRS to push those reports to the web. You can lay out each report in JSS and then publish it to the server, or you can create a custom layout in JSS and then use it in Ad Hoc. JasperReports Server only allows the creation of basic reports so if you want to customize the layout of reports in JasperReports Server Ad Hoc, you need to create a report template in Jaspersoft Studio and publish it from Studio to JRS. A video describing the basic functionalities of both is available below: https://youtu.be/OkE7yDN_gsQ
×
×
  • Create New...