Skip to content

Standalone usage

Eugene Degtyarjov edited this page Nov 1, 2017 · 35 revisions

General info

One of YARG features is ability to use it as a standalone application.

In this case you have 2 options:

  1. Run your reports from command line or from any types of applications
  2. Run standalone reporting service and call GET method to generate reports

There are few steps to start use it this way.

  1. Download latest application distributive from releases
  2. Unzip the content to some folder
  3. Run the reporting engine with the following command:
yarg-console -rp PATH_TO_YOUR_REPORT_XML -op PATH_FOR_OUTPUT -PparamName=ParamValue 

or

yarg-server -dir PATH_TO_DIRECTORY_WITH_YOUR_REPORTS_XMLS -port SERVER_PORT 

Please note, that if you pass date to params, it should have one of the following formats: dd/MM/yyyy or dd/MM/yyyy hh:mm.

Database usage

If you need to use database queries, you should do the following steps (the example is for PostgreSQL database):

  1. Put JDBC driver JAR to the lib sub folder. For PostgreSQL it would be postgresql-9.4.jar
  2. 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(;)
  3. 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-console -prop PATH_TO_PROPERTIES/reporting.properties -rp PATH_TO_YOUR_REPORT_XML -op PATH_FOR_OUTPUT -PparamName=ParamValue

or

yarg-server -dir PATH_TO_DIRECTORY_WITH_YOUR_REPORTS_XMLS -port SERVER_PORT -prop PATH_TO_PROPERTIES/reporting.properties 

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="/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

Console example

When the above is finished we can run the report.

yarg-console -prop /temp/yarg/bin/reporting.properties -rp /temp/yarg/users.xml -op /temp/yarg/result.xlsx

Reporting service example

When the above is finished we can run the reporting service.

yarg-server -prop /temp/yarg/bin/reporting.properties -dir /temp/yarg/users.xml -port 4567

Then we can call the following URL:

http://localhost:4567/generate?report=users

and you will receive the generated report.

If we need to pass any parameters to the URL, we have to use the following syntax

http://localhost:4567/generate?report=users&params[PARAM_NAME]=PARAM_VALUE
Clone this wiki locally