Blog Posts BPMN DMN

Building Dashboards using Plain Java

Blog: Drools & jBPM Blog

DashBuilder is a great tool to author dashboards that can consume and display data from many sources, i.e. Prometheus, JDBC, Kie Server, and others. These dashboards can be later exported to a ZIP file and then be executed on DashBuilder Runtime.

Dashboard built with DashBuilder

Recently, we added a new alternative to create those dashboards: a pure Java API. The Java API exposes our existing builders and factories for data sets and visual components, but it also brings a new set of components for pages and navigation.

View the code on Gist.
View the code on Gist.

In this post, we will introduce the DashBuilder Java DSL (Domain Specific Language) API and teach you how to get started with it.

Dashbuider DSL API

The API has 5 main core components. Let’s take a look at those:

Data Sets

The API for data sets has as entry point the class org.dashbuilder.dataset.def.DataSetDefFactory which allows you to create your own data set definition. You can also pure Java data set using the class DataSetFactory, for example:

View the code on Gist.

It is also possible to build data sets from multiple sources, such as CSV, Prometheus, SQL, and many others. It is important to notice that the same data set can have a different representation using lookups, which can be understood as data sets transformation requests. We will explore this later.

Components

Components can be used in a dashboard page to display a data set or static information. The entry point to create components is the class org.dashbuilder.dsl.factory.component.ComponentFactory.

From there you can refer to components in your local file system or build displayers components. For “displayer” components notice that we need a factory to build the settings, the factory is class: org.dashbuilder.displayer.DisplayerSettingsFactory, where you can build the settings for your displayer. Bear in mind that all classes that use a displayer will require a data set to be built, otherwise, an exception will be thrown when exporting the dashboard;

Page

You can build pages composed of the components mentioned in 2. Pages have rows that can have columns and finally components. Using the class org.dashbuilder.dsl.factory.page.PageFactory allow make it easy for you to create any page component;

Navigation

You can create the pages navigation using org.dashbuilder.dsl.factory.navigation.NavigationFactory. This class can be used to define the menu of pages that will be displayed in DashBuilder Runtime;

Dashboard

This is the class that glues everything. It can be created using org.dashbuilder.dsl.factory.dashboard.DashboardFactory.

Note: All these classes have builders that can be used instead of the factory

Finally, when the work is done you can export the dashboard using the class org.dashbuilder.dsl.serialization.DashboardExporter.


Hello World Dashboard

Let’s now, create a Hello world using our API:

Requirements

  1. Java 11+
  2. Maven
  3. Docker or podman

Steps

  1. Create a maven project in your favorite IDE or use the following command:
View the code on Gist.

Make sure to update it with the properties, dependencies, and build the section from this pom.xml:

View the code on Gist.
  1. Create the class PopulationDashboard.java in package org.kie.dashbuilder with the content as seen below; It creates a dashboard and exports it to a ZIP file.
View the code on Gist.
  1. On the project root, create the following directory structure. Notice that dashboards are a directory.
View the code on Gist.

Make sure Dockerfile has the content as shown below

View the code on Gist.

This is how the project structure should look like:

View the code on Gist.
  1. Run PopulationDashboard.java in your IDE or using the command mvn clean install exec:java. After it runs the file population.zip is generated in dashbuilder-runtime/dashboards directory. This is the Dashboard you created:

    To visualize the dashboard you must:

    1. Build the image. Inside dashbuilder-runtime directory build the image using the following docker/podman command

    docker build -t dashbuilder-dev .

    It will download DashBuilder runtime, so it may take a while. You must run this command once.

    1. Then run the image:

    docker run -dp 8080:8080 -v ./dashboards:/tmp/dashbuilder/models:z dashbuilder-dev

    Once it is running you can access localhost:8080 and login as admin/admin. Every time you run PopulationDashboard Java class, the dashboard will be automatically updated.

    When the work is done, you can use the generated ZIP in production by using Dashbuilder Runtime in Static mode with the provided ZIP.

    Conclusion

    In this post, we introduced the Java API to create dashboards for Dashbuilder. In the next post, we will introduce other data set types and data set lookup, so stay tuned!

The post Building Dashboards using Plain Java appeared first on KIE Community.

Leave a Comment

Get the BPI Web Feed

Using the HTML code below, you can display this Business Process Incubator page content with the current filter and sorting inside your web site for FREE.

Copy/Paste this code in your website html code:

<iframe src="https://www.businessprocessincubator.com/content/building-dashboards-using-plain-java/?feed=html" frameborder="0" scrolling="auto" width="100%" height="700">

Customizing your BPI Web Feed

You can click on the Get the BPI Web Feed link on any of our page to create the best possible feed for your site. Here are a few tips to customize your BPI Web Feed.

Customizing the Content Filter
On any page, you can add filter criteria using the MORE FILTERS interface:

Customizing the Content Filter

Customizing the Content Sorting
Clicking on the sorting options will also change the way your BPI Web Feed will be ordered on your site:

Get the BPI Web Feed

Some integration examples

BPMN.org

XPDL.org

×