You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

In this tutorial, we will following the guideline of developing a plugin to develop our Bean Shell Hash Variable plugin. 

1. What is the problem?

Hash variable is convenient in used, but sometime we want to do some condition check before display a value. But, Hash variable does not provide the ability to do condition checking.

2. What is your idea to solve the problem?

So, how to solve this issue? By looking at the Plugin Types that supported by Joget Workflow, we may need to develop a Hash Variable Plugin to allow us to write our scripting for condition checking. There are quite a number of Bean Shell plugins provided as default plugin for several plugin types. We can do one for Hash Variable plugin as well.

3. What is the input needed for your plugin?

Hash Variable plugin does not provide interface for user to configure, but to develop a Bean Shell Hash Variable plugin, we need somewhere to put our Bean Shell script. We can reuse the Environment Variable to store our script. So the Hash Variable syntax will be a prefix with environment variable key.

e.g.: #beanshell.EnvironmentVariableKey#

But, this may not be enough, we may need some way to pass in some variable also. We can consider to use a URL query parameters syntax to pass in our variables because it is easier to parse later on.

e.g.: #beanshell.EnvironmentVariableKey[name=Joget&email=info@joget.org&message={form.sample.message?url}]#

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

What are we expected from this Bean Shell Hash variable plugin? The Bean Shell Hash Variable plugin is for admin user to use while building the app. Once it is used, the Hash Variable will replaced by the output return from the Bean Shell interpreter. So that the admin user can do condition check before display something to normal user.

e.g.: Display a welcome message for logged in user but display nothing when the user is an anonymous.

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

To develop Bean Shell Hash Variable plugin, we can refer to the source code of all the Hash Variable plugin and Bean Shell plugin. Especially, we can refer to Environment Variable Hash Variable plugin on how to retrieve environment variable using a variable key. We can also refer to Bean Shell Tool or Bean Shell Form Binder plugin on what to execute the script with Bean Shell interpreter. 

We can use getUrlParams method from StringUtil to help us parse parameters passed in in URL query parameters syntax.

6. Prepare your development environment

Always has your Joget Workflow Source Code ready and builded by following this guideline

Let said my folder directory as following. This tutorial is prepared with a Macbook Pro and Joget Source Code version 5.0.0. Please refer to Guideline of developing a plugin for other platform command.

- Home
  - joget
    - plugins
    - jw-community
      -5.0.0

The "plugins" directory is the folder I will create and store all my 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.

cd joget/plugins/
~/joget/jw-community/5.0.0/wflow-plugin-archetype/create-plugin.sh org.joget.tutorial beanshell_hash_variable 5.0.0

Then, the shell script will ask you to key in a version for your plugin and ask you for confirmation before generate the maven project.

Define value for property 'version':  1.0-SNAPSHOT: : 5.0.0
[INFO] Using property: package = org.joget.tutorial
Confirm properties configuration:
groupId: org.joget.tutorial
artifactId: beanshell_hash_variable
version: 5.0.0
package: org.joget.tutorial
Y: : y

You should get "BUILD SUCCESS" message shown in your terminal and a "beanshell_hash_variable" 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 "BeanShellHashVariable" class under "org.joget.tutorial" package.

Then, based on Hash Variable Plugin document, we will have to extends org.joget.apps.app.model.DefaultHashVariablePlugin abstract class.

b. Implement all the abstract methods

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

package org.joget.tutorial;
 
import org.joget.apps.app.model.DefaultHashVariablePlugin;
import org.joget.apps.app.service.AppPluginUtil;
 
public class BeanShellHashVariable extends DefaultHashVariablePlugin {
    
    private final static String MESSAGE_PATH = "message/BeanShellHashVariable";
 
    public String getName() {
        return "BeanShellHashVariable";
    }
 
    public String getVersion() {
        return "5.0.0";
    }
 
    public String getClassName() {
        return getClass().getName();
    }
    
    public String getLabel() {
        //support i18n
        return AppPluginUtil.getMessage("org.joget.tutorial.BeanShellHashVariable.pluginLabel", getClassName(), MESSAGE_PATH);
    }
    
    public String getDescription() {
        //support i18n
        return AppPluginUtil.getMessage("org.joget.tutorial.BeanShellHashVariable.pluginDesc", getClassName(), MESSAGE_PATH);
    }
 
    public String getPropertyOptions() {
        //Hash variable plugin do not support property options
        return "";
    }
    
    public String getPrefix() {
        return "beanshell";
    }
    
    public String processHashVariable(String variableKey) {
        throw new UnsupportedOperationException("Not supported yet."); 
    }
}

Now, let focus on the main method of our Hash Variable plugin which is processHashVariable.

 


 

  • No labels