Preferences System
Important: This module works only for Ontimize Boot version 3.9.0 or above. Actual release version:
Introduction
The Ontimize preferences allow you to save the settings that are stored in the localstorage (window size, tables preferences, graphics, or reports) into the database.
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.
There are 2 options to follow this tutorial, clone the repository with the initial state and follow the tutorial step by step, or download the final example and see which files are new and which have been updated.
Initial project
/$ git clone https://github.com/ontimize/ontimize-examples
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-preferences-initial
Final example
/$ git clone https://github.com/ontimize/ontimize-examples
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-preferences
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.
Steps
Database
Configurations Table
With the database started, we create the new table that will store the configuration preferences information.
1
CREATE TABLE TCONFIGS ( ID_CONFIG INTEGER NOT NULL IDENTITY, USER_CONFIG VARCHAR(255), TYPE_CONFIG VARCHAR(255), COMPONENTS VARCHAR(16777216));
Server
Configuration Dao
A specific DAO will be created for the table in the Preferences system, and it will implement a interface.
-
ontimize-examples
-
projectwiki-api
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
-
api
-
core
-
service
- ICandidateService.java
- 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.properties
- templateDB.txt
-
java
-
com
-
ontimize
-
projectwiki
-
model
-
core
-
dao
- CandidateDao.java
- ConfigsDao.java
- UserDao.java
- UserRoleDao.java
-
service
- CandidateService.java
- UserService.java
-
dao
-
core
-
model
-
projectwiki
-
ontimize
-
com
-
resources
-
dao
- CandidateDao.xml
- ConfigsDao.xml
- 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
- CandidateRestController.java
- MainRestController.java
- TestRestController.java
- UserRestController.java
-
rest
-
core
-
ws
-
projectwiki
-
ontimize
-
com
-
java
-
main
- pom.xml
-
src
- .gitignore
- pom.xml
- README.md
-
projectwiki-api
ConfigsDao.java
ConfigsDao.xml
Add parameters to Application YML
As has already been explained previously (in this link) we add the following parameters to the application.yml
to define the name of the DAO of the preferences system and to activate autoconfiguration.
-
ontimize-examples
-
projectwiki-api
-
src
-
main
-
java
-
com
-
ontimize
-
projectwiki
-
api
-
core
-
service
- ICandidateService.java
- 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.properties
- templateDB.txt
-
java
-
com
-
ontimize
-
projectwiki
-
model
-
core
-
dao
- CandidateDao.java
- ConfigsDao.java
- UserDao.java
- UserRoleDao.java
-
service
- CandidateService.java
- UserService.java
-
dao
-
core
-
model
-
projectwiki
-
ontimize
-
com
-
resources
-
dao
- CandidateDao.xml
- ConfigsDao.xml
- 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
- CandidateRestController.java
- MainRestController.java
- TestRestController.java
- UserRestController.java
-
rest
-
core
-
ws
-
projectwiki
-
ontimize
-
com
-
java
-
main
- pom.xml
-
src
- .gitignore
- pom.xml
- README.md
-
projectwiki-api
application.yml
Testing the preferences system
Once the preferences system is already configured and the server and the database are running, we will follow the next steps:
Add preferences to database
To add or modify preferences to the database, we will execute the following REST Request: http://localhost:33333/configuration/preferences
The type of the request is POST.
Element | Meaning |
---|---|
localhost:33333 | Indicates the host |
/configuration | Indicates the service |
/preferences | Indicates the type of configuration that you’re going to save. You can write the name you want. |
The body of the request needs to have the following structure:
Note: By default the request will create a new entry in the database. If it already exists, it will be modified.
Query preferences
To query preferences of the database, we will execute the following REST Request: http://localhost:33333/configuration/preferences?user=demo
The type of the request is GET.
Element | Meaning |
---|---|
localhost:33333 | Indicates the host. |
/configuration | Indicates the service to be queried. |
/preferences | Indicates the type of configuration that will be queried. |
?user=demo | Indicates the user. |