Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

1. What is the problem?

We would like to run multiple store binders plugins in a single store binder selection. This would open up more use cases with the ability to store form data into multiple destinations without the need for relying on other approaches such as JSON Tool or SOAP Tool.

2. What is your idea to solve the problem?

Joget has a plugin type called Form Store Binder Plugin. We will develop one based on this plugin category to support multiple selections and execution of store binders to store form data.

3. What is the input needed for your plugin?

To develop a Multi Store binders, we will need a multi-selector in a grid form and a text editor for additional notes for app designers.

  1. Binders: Displays a list of store binders available.


  2. Comments: Additional notes users might wish to add.


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

All submitted data will store accordingly based on the configuration of each of the store binders selected.

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

We can refer to the implementation of other available Form Store Binder plugins. We can also refer to how Multi Tools plugin for the design: 

...

https://github.com/jogetworkflow/jw-community/blob/7.0-SNAPSHOT/wflow-core/src/main/resources/properties/app/multiTools.json

6. Prepare your development environment

We need to always have our Joget Workflow Source Code ready and built by following this guideline

...

Open the maven project with your favorite IDE. We will be using NetBeans.

7. Just code it!

a. Extending the abstract class of a plugin type

Create a "MultiStoreBinders" class under "org.joget.marketplace" package. Then, extend the class with org.joget.apps.form.model.FormBinder abstract class.

...

 Please refer to Form Store Binder Plugin. 

b. Implement all the abstract methods

As usual, we have to implement all the abstract methods. We will be using the AppPluginUtil.getMessage method to support i18n and using the constant variable MESSAGE_PATH for the message resource bundle directory.

...

Code Block
linenumberstrue
    public FormRowSet store(Element element, FormRowSet rows, FormData formData) {
        final Object[] binders = (Object[]) getProperty("binders");
        if (binders != null && binders.length > 0) {
            Thread newThread;         
            final PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
            newThread = new PluginThread(new Runnable() {
                    public void run() {                        
                        for (Object binder : binders) {
                            if (binder != null && binder instanceof Map) {
                                Map binderMap = (Map) binder;
                                if (binderMap != null && binderMap.containsKey("className") && !binderMap.get("className").toString().isEmpty()) {
                                    String className = binderMap.get("className").toString();
                                    FormStoreBinder p = (FormStoreBinder) pluginManager.getPlugin(className);
                                    if (p != null) {
                                        Map properties = new HashMap();
                                        properties.putAll((Map) binderMap.get("properties"));                                       
                                        if (p instanceof PropertyEditable) {
                                            ((PropertyEditable) p).setProperties(properties);
                                        }
                                        p.store(element, rows, formData);
                                    }
                                }
                            }
                        }
                    }
                });
                newThread.start();            
        }
        return null;
    }

c. Manage the dependency libraries of your plugin

Our plugin is using dbcp, javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse class, so we will need to add jsp-api and commons-dbcp library to our POM file.

...

Code Block
languagexml
<!-- Change plugin specific dependencies here -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.0</version>
</dependency>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20080701</version>
    <scope>provided</scope>
</dependency>
<!-- End change plugin specific dependencies here -->

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.

...

Code Block
linenumberstrue
org.joget.marketplace.MultiStoreBinders.pluginLabel=multi store binders
org.joget.marketplace.MultiStoreBinders.pluginDesc=Enable the use of multiple store binders
org.joget.marketplace.MultiStoreBinders.config=Configure multi store binders
org.joget.marketplace.MultiStoreBinders.storeBinder=Store Binders
org.joget.marketplace.MultiStoreBinders.comment=Comment

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.

...

Code Block
languagejava
    public void start(BundleContext context) {
        registrationList = new ArrayList<ServiceRegistration>();
        //Register plugin here
        registrationList.add(context.registerService(MultiStoreBinders.class.getName(), new MultiStoreBinders(), null));
    } 

f. Build it and testing

Let build our plugin. Once the building process is done, we will found a "multi_store_binder-7.0.0.jar" file is created under the "multi_store_binder/target" directory.

...

It works! Please remember to test the other features of the plugin as well. (big grin)

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

You can download the source code from multi_store_binder.zip

...