Example Task Extensions

There are several simple tasks that can be used as the basis of extending the workflow environment by adding your own tasks. Here are some:

  1. org.dwfa.bpa.tasks.web.FetchFromWeb A task that reads a string from a URL, parses the string, and presents the string to the user in a dialog. This task demonstrates how tasks can connecting to servers over the network, and do something with those results.



  2. org.dwfa.bpa.tasks.dialog.ShowInfoDialog A task that displays a message to the user. The message was set when the process was created in the process builder, using standard JavaBeans property editor conventions.



Steps to Create A Task

There are three steps to creating a task:
  1. Create the task class by extending org.dwfa.bpa.tasks.AbstractTask. Put the code to execute the tasks desired action in the evaluate method of your class. Pattern your class after one of the existing example tasks, then add new functionality as desired. The org.dwfa.bpa.tasks.web.FetchFromWeb task and the org.dwfa.bpa.tasks.dialog.ShowInfoDialog tasks provide simple examples.



  2. Create a BeanInfo class for your task. This BeanInfo class controls how the task is presented in the process builder, and how its properties are edited within the process builder. More information about how to program the BeanInfo class can be found here. Your BeanInfo class must be named following standard conventions where the first part of the name is identical to the name of your task class, followed by "BeanInfo". Your BeanInfo class must be in the same package as your task class.



  3. Add an entry to the pom.xml to write the task to disk as a JavaBean, and include this task in the DWFA bundle so it can be accessed from the process builder. The generation of JavaBeans during the Maven build process is managed by the dwfa-maven-plugin, which is one of the modules of this project. The syntax for including a new JavaBean specification for this plugin is to add a beanSpec entry such as this entry for the FetchFromWeb task:
            <plugin>
                <groupId>org.dwfa.maven</groupId>
                <artifactId>dwfa-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <configuration>
                    <specs>
                        <beanSpec>
                            <sourceName>org.dwfa.bpa.tasks.web.FetchFromWeb</sourceName>
                            <dirName>web</dirName>
                        </beanSpec>
                    <specs>
                <configuration>
            <plugin>
    
    
    Additional bean specifications can be specified by adding additional beanSpec entries to the plugin configuration.

Step by Step Example

The following steps will create a simple "hello world!" task from within eclipse:
  1. If you have not already done so, follow the steps described in Eclipse Integration to import the process module into your eclipse environment.



  2. Within eclipse, select the org.dwfa.bpa.tasks.dialog package. Right click on this package, and select New > Class. Name the new class HelloWorldDialog, and set the Superclass to be org.dwfa.bpa.tasks.AbstractTask, and select the checkbox labeled "Inherited abstract methods". Now commit this dialog, and create the class.



  3. Change the method:
    	public int[] getDataContainerIds() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    to the following:
    	public int[] getDataContainerIds() {
    		return new int[] {};
    	}
    
    This method will be deprecated in future versions of the architecture.



  4. Change the method:
    	public Collection<Condition> getConditions() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    to the following:
    	public Collection<Condition> getConditions() {
    		return CONTINUE_CONDITION;
    	}
    
    This method defines the possible valid exit conditions for this task. In this case, we just want the environment to continue with the next task after executing this task, hence the CONTINUE_CONDITION specification. Other tasks may allow for branching conditions, or other exit conditions, and may define a different collection of exit conditions.



  5. Add the following fields and methods to control the serialization of this task:
        private static final long serialVersionUID = 1;
    
        private static final int dataVersion = 1;
    
        private void writeObject(ObjectOutputStream out) throws IOException {
            out.writeInt(dataVersion);
        }
    
        private void readObject(java.io.ObjectInputStream in) throws IOException,
                ClassNotFoundException {
            int objDataVersion = in.readInt();
            if (objDataVersion == 1) {
               //all is well :-)
            } else {
                throw new IOException("Can't handle dataversion: " + objDataVersion);
            }
            
        }
    
    Although this task is very simple, other tasks may have more complicated data structures which are set at design time using standard JavaBean editing conventions. By implementing the serialization methods, and by explicitely defining the serialVersionUID and dataVersion, we are providing a foundation for supporting task evolution over time.



  6. Change this method:
    	public Condition evaluate(I_EncodeBusinessProcess process, I_Work worker)
    			throws TaskFailedException {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    
    to the following:
        public Condition evaluate(I_EncodeBusinessProcess process, I_Work worker)
                throws TaskFailedException {
            JOptionPane.showMessageDialog(new JFrame(), "Hello World!");
            return Condition.CONTINUE;
        }
    
    
    The task is now fully functional. To use the task from within the Process Builder, (see the Clinic Demonstration for an introduction to runing the bundled environment, and the Process Builder), we must create a BeanInfo class for this task.



  7. Create the BeanInfo class by extending java.beans.SimpleBeanInfo. Within eclipse, select the org.dwfa.bpa.tasks.dialog package. Right click on this package, and select New > Class. Name the new class HelloWorldDialogBeanInfo, and set the Superclass to be java.beans.SimpleBeanInfo. Now commit this dialog, and create the class.



  8. Add the following method to this class:
        public BeanDescriptor getBeanDescriptor() {
            BeanDescriptor bd = new BeanDescriptor(HelloWorldDialog.class);
            bd.setDisplayName("<html><font color='green'><center>Hello World");
            return bd;
        }
    
    Now that the Task has a BeanInfo class to describe it, it can be made available to the process builder by writing the the task bean to disk. This step is managed by adding an entry to the Maven pom.xml file.



  9. Open the process pom.xml file from within eclipse, and add the following entry below the entry for org.dwfa.bpa.tasks.dialog.ShowInfoDialog (you can use eclipse to search the file to find this entry):
            <beanSpec>
                <sourceName>org.dwfa.bpa.tasks.dialog.HelloWorldDialog</sourceName>
                <dirName>dialog</dirName>
            </beanSpec>
    




  10. Generate a new "bundle" using maven by navigating to the dev/bundle directory and executing either mkbundle.sh (unix) or mkbundle.bat (windows). This command causes all the modules to be built, and bundled in a directory. This directory will be located inside the dev/bundle/target/dwfa-bundle.dir/dwfa when the build is complete. Go stretch for awhile :-) It takes 40 minutes to do this complete bundle build on our development machines.



  11. Once the bundle build is complete, you can execute the resulting bundle by executing the startClinic.sh (unix) or startClinic.bat (windows) file located inside of the dev/bundle/target/dwfa-bundle.dir/dwfa directory.



  12. After launching the clinic bundle, you should be able to locate the new task from within the Process Builder by selecting the "dialog" folder in the upper left panel of the window, and the new task should be displayed in the lower left panel, and can be dragged onto the process panel on the right.