Joget Workflow v6 Beta 3 Released

Check out the latest Joget Workflow v6 Beta for many new features and improvements in user experience (UX), app maintainability and performance.

Skip to end of metadata
Go to start of metadata

 

In this tutorial, we will following the guideline of developing a plugin to develop our Not Permission plugin. Please also refer to the very first tutorial How to develop a Bean Shell Hash Variable for more details steps.

1. What is the problem?

I want to configure the userview permission or form permission to not in groups, department or etc. 

2. What is your idea to solve the problem?

We can develop a Userview Permission/ Form Permission Plugin to reverse the result of other permission plugins.

3. What is the input needed for your plugin?

To develop a Not Permission plugin, we can consider to provide the following as input.

  1. Permission: To configure a Permission plugin to get the result for reverse it.
  2. Must be Logged In User: The result will only valid if and only if the user is also a logged in user.

4. What is the output and expected outcome of your plugin?

The reverse value of the configured permission plugin.

5. Is there any resources/API that can be reuse?

You can refer to How to develop a Gantt Chart Userview Menu on how to reuse a existing plugin.

6. Prepare your development environment

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 "not_permission" folder created in "plugins" folder.

Open the maven project with your favour IDE. I will be using NetBeans.  

7. Just code it!

a. Extending the abstract class of a plugin type

Create a "NotPermission" class under "org.joget.tutorial" package. Then, extend the class with org.joget.apps.userview.model.UserviewPermission abstract class and implement org.joget.apps.form.model.FormPermission interface. Please refer to Userview Permission/ Form Permission Plugin.

b. Implement all the abstract methods

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.

Implementation of all basic abstract methods  Expand source

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/notPermission.json". Let us create a directory "resources/properties" under "not_permission/src/main" directory. After create the directory, create a file named "notPermission.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.

After done the properties option to collect input, we can work on the main method of the plugin which is isAuthorize method.

c. Manage the dependency libraries of your plugin

There are no extra dependency for this plugin.

d. Make your plugin internationalization (i18n) ready

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 "not_permission/src/main" directory. Then, create a "NotPermission.properties" file in the folder. In the properties file, let add all the message keys and its label as below.

e. Register your plugin to Felix Framework

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.

f. Build it and testing

Let build our plugin. Once the building process is done, we will found a "not_permission-5.0.0.jar" file is created under "not_permission/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 open an userview and change one of the category permission to Not Permission. We will want the current user not in a "Managers" group.

After done the configuration and save the userview. Let us test it. First, check the admin user is not in "Managers" group.

Check the userview, the "Personal" category configured with not in "Managers" group is shown correctly.

Now, assign the "admin" user to "Managers" group.

The "Personal" category is now disappeared.

8. Take a step further, share it or sell it

You can download the source code from not_permission.zip.

To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/.

  • No labels