Report On Demand
Important: This module works only for Ontimize Boot version 3.9.0 or above. Actual release version:
Prerequisites
You can follow this tutorial using your own application, although for this example we will use an application created using the archetype that can be found on this page and with a REST service.
Clone the repository with the initial state and follow the tutorial step by step.
Initial project
/$ git clone https://github.com/ontimize/ontimize-examples
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-report-initial
Final example
/$ git clone https://github.com/ontimize/ontimize-examples
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-report
Note: To simplify the code being written, three dots (…) may appear in some parts of the code. This indicates that there may be previous code before and after those dots.
Important: In the first step we will learn how to configure the reports system with the database engine. If you want to use the file system engine you can jump to this section.
Steps
Database
Report Tables
With the database started, we create the new tables that will store the reports information. We’re going to need to create two different tables, one for the report itself and one for the report custom parameters.
1
CREATE TABLE PREFERENCES(ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(255),DESCRIPTION VARCHAR(255),PREFERENCES VARCHAR(5000),ENTITY VARCHAR(100), TYPE BIT)
Server
Add Ontimize Report dependencies
-
ontimize-examples
-
projectwiki-api
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
-
api
-
core
-
service
- IUserService.java
-
service
-
core
-
api
-
projectwiki
-
ontimize
-
com
-
java
-
main
- pom.xml
-
src
-
projectwiki-boot
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
- ServerApplication.java
-
projectwiki
-
ontimize
-
com
-
resources
- application.yml
-
java
-
main
- pom.xml
-
src
-
projectwiki-model
-
src
-
main
-
db
- templateDB.tmp
- templateDB.lck
- templateDB.log
- templateDB.properties
- templateDB.script
- templateDB.txt
-
java
-
com
-
ontimize
-
projectwiki
-
model
-
core
-
dao
- UserDao.java
- UserRoleDao.java
-
service
- UserService.java
-
dao
-
core
-
model
-
projectwiki
-
ontimize
-
com
-
resources
-
dao
- placeholders.properties
- RoleDao.xml
- RoleServerPermissionDao.xml
- ServerPermissionDao.xml
- UserDao.xml
- UserRoleDao.xml
-
dao
-
db
-
main
- pom.xml
-
src
-
projectwiki-ws
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
-
ws
-
core
-
rest
- MainRestController.java
- TestRestController.java
- UserRestController.java
-
rest
-
core
-
ws
-
projectwiki
-
ontimize
-
com
-
java
-
main
- pom.xml
-
src
- .gitignore
- candidates.zip
- pom.xml
- README.md
-
projectwiki-api
projectwiki-boot/pom.xml
projectwiki-model/pom.xml
Add Preferences DAOs
A specific DAO will be created for each of both tables in the system, and each of them will implement a different interface.
-
ontimize-examples
-
projectwiki-api
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
-
api
-
core
-
service
- IUserService.java
-
service
-
core
-
api
-
projectwiki
-
ontimize
-
com
-
java
-
main
- pom.xml
-
src
-
projectwiki-boot
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
- ServerApplication.java
-
projectwiki
-
ontimize
-
com
-
resources
- application.yml
-
java
-
main
- pom.xml
-
src
-
projectwiki-model
-
src
-
main
-
db
- templateDB.tmp
- templateDB.lck
- templateDB.log
- templateDB.properties
- templateDB.script
- templateDB.txt
-
java
-
com
-
ontimize
-
projectwiki
-
model
-
core
-
dao
- PreferencesDao.java
- UserDao.java
- UserRoleDao.java
-
service
- UserService.java
-
dao
-
core
-
model
-
projectwiki
-
ontimize
-
com
-
resources
-
dao
- placeholders.properties
- PreferencesDao.xml
- RoleDao.xml
- RoleServerPermissionDao.xml
- ServerPermissionDao.xml
- UserDao.xml
- UserRoleDao.xml
-
dao
-
db
-
main
- pom.xml
-
src
-
projectwiki-ws
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
-
ws
-
core
-
rest
- MainRestController.java
- TestRestController.java
- UserRestController.java
-
rest
-
core
-
ws
-
projectwiki
-
ontimize
-
com
-
java
-
main
- pom.xml
-
src
- .gitignore
- candidates.zip
- pom.xml
- README.md
-
projectwiki-api
PreferencesDao.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<JdbcEntitySetup
xmlns="http://www.ontimize.com/schema/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ontimize.com/schema/jdbc http://www.ontimize.com/schema/jdbc/ontimize-jdbc-dao.xsd"
catalog="" schema="${mainschema}" table="PREFERENCES"
datasource="mainDataSource" sqlhandler="dbSQLStatementHandler">
<DeleteKeys>
<Column>ID</Column>
</DeleteKeys>
<UpdateKeys>
<Column>ID</Column>
</UpdateKeys>
<GeneratedKey>ID</GeneratedKey>
</JdbcEntitySetup>
PreferencesDao.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.imatia.qsallcomponents.model.dao;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;
import com.ontimize.jee.server.dao.IPreferencesDao;
import com.ontimize.jee.server.dao.common.ConfigurationFile;
import com.ontimize.jee.server.dao.jdbc.OntimizeJdbcDaoSupport;
@Lazy
@Repository(value = "PreferencesDao")
@ConfigurationFile(configurationFile = "base-dao/PreferencesDao.xml", configurationFilePlaceholder = "base-dao/placeholders.properties")
public class PreferencesDao extends OntimizeJdbcDaoSupport implements IPreferencesDao {
public static final String ATTR_ID = "ID";
public static final String ATTR_NAME = "NAME";
public static final String ATTR_DESCRIPTION = "DESCRIPTION";
public static final String ATTR_PREFERENCES = "PREFERENCES";
public static final String ATTR_TYPE = "TYPE";
}
Modify application.yml
The application.yml file will be modified to enable the reports module, indicate the report engine type it will use and, if needed, the path where the report files will be stored. In this link you have information about the configuration of the reports system in the application.yml file.
Note: The enable property must be set to true and the engine type must be specified in the engine property before the server is started.
Important: You can only choose ONE of the two options listed below.
-
ontimize-examples
-
projectwiki-api
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
-
api
-
core
-
service
- IUserService.java
-
service
-
core
-
api
-
projectwiki
-
ontimize
-
com
-
java
-
main
- pom.xml
-
src
-
projectwiki-boot
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
- ServerApplication.java
-
projectwiki
-
ontimize
-
com
-
resources
- application.yml
-
java
-
main
- pom.xml
-
src
-
projectwiki-model
-
src
-
main
-
db
- templateDB.tmp
- templateDB.lck
- templateDB.log
- templateDB.properties
- templateDB.script
- templateDB.txt
-
java
-
com
-
ontimize
-
projectwiki
-
model
-
core
-
dao
- ReportDao.java
- ReportParameterDao.java
- UserDao.java
- UserRoleDao.java
-
service
- UserService.java
-
dao
-
core
-
model
-
projectwiki
-
ontimize
-
com
-
resources
-
dao
- placeholders.properties
- ReportDao.xml
- ReportParameterDao.xml
- RoleDao.xml
- RoleServerPermissionDao.xml
- ServerPermissionDao.xml
- UserDao.xml
- UserRoleDao.xml
-
dao
-
db
-
main
- pom.xml
-
src
-
projectwiki-ws
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
-
ws
-
core
-
rest
- MainRestController.java
- TestRestController.java
- UserRestController.java
-
rest
-
core
-
ws
-
projectwiki
-
ontimize
-
com
-
java
-
main
- pom.xml
-
src
- .gitignore
- candidates.zip
- pom.xml
- README.md
-
projectwiki-api
application.yml
For database engine
For file system engine
Testing the reports system
Once the reports system is already configured and the server and the database are running, we will follow the next steps:
Generate report
- URL: http://localhost:33333/dynamicjasper/report
- HTTP Method: POST
- Authorization: User: demo, Password: demouser
- Body: JSON
Element | Meaning |
---|---|
localhost:33333 | Indicates the host |
/dynamicjasper | Indicates the service to be queried |
/report | Indicates the method of the service that is going to be executed |
Body request:
Save preferences
Allows to save the configuration of a report in the database to do it again quickly
- URL: http://localhost:33333/preferences/save
- HTTP Method: POST
- Authorization: Basic Auth with parameters User: demo, Password: demouser
- Body: JSON
Element | Meaning |
---|---|
localhost:33333 | Indicates the host |
/preferences | Indicates the service to be queried |
/save | Indicates the method of the service that is going to be executed |
Body request:
Get preferences
Execute the following request: http://localhost:33333/preferences/preferences?entity=ENTITY&service=SERVICE&type=REPORT.
Element | Meaning |
---|---|
localhost:33333 | Indicates the host |
/preferences | Indicates the service to be queried |
/preferences | Indicates the method of the service that is going to be executed |
?entity=ENTITY | ENTITY indicates the entity to filter the preferences |
&service=SERVICE | SERVICE indicates the service to filter the preferences |
&type=REPORT | Indicates the type to filter the preferences |
The authorization used for these requests is authorization of the type BASIC.
In all three cases cases, the access must be done with a user and password example:
User: demo
Password: demouser
Visualize report document
When you run the above request, in the body of the response you will find the key file, whose value is a Base 64 that contains the format and data of the report template. Copy it and go to this page to convert the Base 64 into a PDF file.