-
Notifications
You must be signed in to change notification settings - Fork 74
Standalone usage
One of YARG features is ability to use it as standalone application.
In this case you can run your reports from command line or from any types of applications.
There are few steps to start use it this way.
- Download latest application distributive from releases
- Unzip the content to some folder
- Run the reporting engine with the following command:
yarg -rp PATH_TO_YOUR_REPORT_XML -op PATH_FOR_OUTPUT -PparamName=ParamValue
Please note, that if you path date to params, it should have one of the following formats: dd/MM/yyyy
or dd/MM/yyyy hh:mm
.
If you need to use database queries, you should do the following steps (the example is for PostgreSQL database):
- Put JDBC driver JAR to the lib subfolder. For PostgreSQL it would be postgresql-9.4.jar
- Add the JDBC driver JAR's path to CLASSPATH variable in the executable script (yarg or yarg.bat). For PostgreSQL you should add
%APP_HOME%\lib\postgresql-9.4.jar
. Please note, that separators are different for Linux(:) and Windows(;) - Create the reporting.properties file somewhere. The file should contain the following properties
cuba.reporting.sql.driver=org.postgresql.Driver #PostgreSQL driver name
cuba.reporting.sql.dbUrl=jdbc:postgresql://localhost/yarg #database url
cuba.reporting.sql.user=root #login
cuba.reporting.sql.password=root #password
cuba.reporting.openoffice.path=/usr/lib/libreoffice/program #path to OpenOffice, if you need to use doc and odt templates, and also if you need to convert result files to PDF
cuba.reporting.openoffice.ports=8100|8101 #OpenOffice ports to use
cuba.reporting.openoffice.timeout=60 #timeout for OpenOffice connections
cuba.reporting.openoffice.displayDeviceAvailable=false #just leave it as is)
The path of the reporting.properties should be passed as -prop argument of command line.
yarg -prop PATH_TO_PROPERTIES/reporting.properties -rp PATH_TO_YOUR_REPORT_XML -op PATH_FOR_OUTPUT -PparamName=ParamValue
#Example
Let's consider the example of standalone usage:
We have the users table in the database.
create table users (
login varchar(50),
name varchar(50),
surname varchar(50),
role varchar(50),
primary key (login)
);
We need to generate a report, showing users with specific role. The default role for the report is "admin" role.
Let's create the report's xml:
<?xml version="1.0" encoding="UTF-8"?>
<report name="report">
<templates>
<template code="DEFAULT" documentName="users-template.xlsx"
documentPath="D:/temp/yarg/users-template.xlsx" outputType="xlsx"
outputNamePattern="users.xlsx"/>
</templates>
<parameters>
<parameter name="Role" alias="role" required="true"
class="java.lang.String" defaultValue="admin"/>
</parameters>
<formats/>
<rootBand name="Root" orientation="H">
<bands>
<band name="Header" orientation="H"/>
<band name="Band" orientation="H">
<bands/>
<queries>
<query name="Data_set_1" type="sql">
<script>
select u.login, u.name, u.surname
from users u
where u.role = ${role}
</script>
</query>
</queries>
</band>
</bands>
<queries/>
</rootBand>
</report>
Then we need to create the report's template
When the above is finished we can run the report.
yarg -prop /temp/yarg/bin/reporting.properties -rp /temp/yarg/users.xml -op /temp/yarg/result.xlsx