Charts On Demand

This module works only for Ontimize Boot version 3.9.0 or above. Actual release version: Ontimize Boot

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-charts-initial

Final example

/$ git clone https://github.com/ontimize/ontimize-examples
/ontimize-examples$ cd ontimize-examples
/ontimize-examples$ git checkout boot-charts

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

Preferences Table

With the database started, we create the new tables that will store the charts information. We’re going to need to create two different tables, one for the chart itself and one for the chart custom parameters.

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 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.

PreferencesDao.xml

<?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

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";

}

Testing the preferences system

Save preferences

Allows to save the configuration of a chart 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:

{   "name":"chart preference",
    "entity":"customer",
    "service":"customers"
    "type":"CHART",
    "params":
      {"title":"Chart of type",
      "subtitle":"This is an example of a pie chart",
      "entity":"customer",
      "service":"customers",
      "selectedXAxis":"CUSTOMERTYPEID",
      "selectedYAxis":"CUSTOMERTYPEID",
      "selectedXAxisType":4,
      "selectedYAxisType":4,
      "selectedTypeChart":4,
      "selectedDataTypeChart":3}
}

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=CHART 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