Joget DX 8 Beta Released
The beta release for Joget DX 8 is now available, with a focus on UX and Governance.
In this tutorial, we will following the guideline of developing a plugin to develop our Form Submission Statistics Generator. Please also refer to the very first tutorial How to develop a Bean Shell Hash Variable for more details steps.
We have 2 SQL Chart menus (the queries used are dependent on MySQL) to show form data submission statistics and this 2 menus always need to replicate for different form.
We can develop a Generator Plugin to ease the process to replicate the 2 SQL Chart menus for other forms.
To develop a Generator Plugin for our 2 SQL Chart menus, we can consider to provide the following as input.
2 SQL Chart menus will be added to the selected userview under a new category. One of the menu will show the monthly submission chart and another one will show the daily submission chart based on the year and month filter.
First, we can do build our 2 SQL Chart menus in one of the existing userview. Then, copy the JSON definition of the category which contains our 2 SQL Chart menus form the "ADVANCED: JSON Definition" on the bottom of the Userview Builder.
We will get our JSON definition of the category as following. Please note that the queries used in the 2 SQL Chart menus are dependent on MySQL database.
After that, we can utilize the GeneratorUtil to add the category JSON definition to our selected userview JSON definition.
We need to always have our Joget Workflow Source Code ready and builded by following this guideline.
The following of this tutorial is prepared with a Macbook Pro and Joget Source Code version 5.0.0. Please refer to Guideline for developing a plugin for other platform command.
Let said our folder directory as following.
The "plugins" directory is the folder we will create and store all our plugins and the "jw-community" directory is where the Joget Workflow Source code stored.
Run the following command to create a maven project in "plugins" directory.
Then, the shell script will ask us to key in a version for your plugin and ask us for confirmation before generate the maven project.
We should get "BUILD SUCCESS" message shown in our terminal and a "form_submission_statistics_generator" folder created in "plugins" folder.
Open the maven project with your favour IDE. I will be using NetBeans.
Create a "FormSubmissionStatisticsGenerator" class under "org.joget.tutorial" package. Then, extend the class with org.joget.apps.generator.model.GeneratorPlugin abstract class. Please refer to Generator Plugin.
As usual, we have to implement all the abstract methods. We will using AppPluginUtil.getMessage method to support i18n and using constant variable MESSAGE_PATH for message resource bundle directory.
Then, we have to do a UI for admin user to provide inputs for our plugin. In getPropertyOptions method, we already specify our Plugin Properties Options definition file is locate at "/properties/formSubmissionStatisticsGenerator.json". Let us create a directory "resources/properties" under "form_submission_statistics_generator/src/main" directory. After create the directory, create a file named "formSubmissionStatisticsGenerator.json" in the "properties" folder.
In the properties definition options file, we will need to provide options as below. Please note that we can use "@@message.key@@" syntax to support i18n in our properties options.
Once we done the properties option to collect input, we can work on the main method of the plugin which is format method.
In the getCategoryJson method, we will retrieve the category JSON definition form "/resources/category.json" file. Let us create a directory "resources/resources" under "form_submission_statistics_generator/src/main" directory. After create the directory, create a file named "category.json" in the "resources" folder. Then, copy the category JSON definition we created previously and paste it inside this file. We will need to replace some of the hardcoded value as variable and remember to escape those existing "%" to "%%" as the AppUtil.readPluginResource using String.format for injects value into the file.
Our plugin is using javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse class, so we will need to add jsp-api library to our POM file.
We are using i18n message key in getLabel and getDescription method. We also used i18n message key in our properties options definition as well. So, we will need to create a message resource bundle properties file for our plugin.Create directory "resources/messages" under "form_submission_statistics_generator/src/main" directory. Then, create a "FormSubmissionStatisticsGenerator.properties" file in the folder. In the properties file, let add all the message keys and its label as below.
We will have to register our plugin class in Activator class (Auto generated in the same class package) to tell Felix Framework that this is a plugin.
Let build our plugin. Once the building process is done, we will found a "form_submission_statistics_generator-5.0.0.jar" file is created under "form_submission_statistics_generator/target" directory.
Then, let upload the plugin jar to Manage Plugins. After upload the jar file, double check the plugin is uploaded and activated correctly.
Let us check the properties page for "Advanced Generator".
After the generation process is done.
A new category is added to our userview.
The SQL chart menus will shown as following.
You can download the source code from form_submission_statistics_generator.zip.
To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/.