1 Reply Latest reply on Sep 20, 2005 11:30 AM by tom.baeyens

    Storing Application Data With A Task Node Definition

    jrustine

      Okay I may be missing something, so this is an ?is there a better way?? question. I?ve basically completed part of an app that allows users to create their own workflows, all based on JBPM (BTW thanks for a great library, saved me a TON of work). No problem taking the input and using Java objects to create nodes in a workflow, then saving it out.

      The problem I keep coming across is how to save application-specific data with the definition of a TaskNode. A user creates a step (a TaskNode) and for editing and security purposes, I need to keep track of who/what/when/where/etc.

      I ended up solving this by creating a dummy handler with task information fields and not much else:

      public class TaskData implements ActionHandler
      {
       private static final long serialVersionUID = 1L;
      
       String action = "";
       String username = "";
       String email = "";
       Date createDate = "";
      
       public void execute(ExecutionContext executionContext)
       {
       // Not really anything to do here.
       }
      }
      

      Then for every TaskNode, I create a node-enter event with an action that delegates to this:
       // Set up simple placeholder for task data.
       Action dataAction = new Action();
       Delegation dataDelegation = new Delegation("TaskData");
       dataAction.setActionDelegation(dataDelegation);
       Event dataEvent = new Event(Event.EVENTTYPE_NODE_ENTER);
       dataEvent.addAction(dataAction);
       taskNode.addEvent(dataEvent);
      

      Any application data I want to maintain gets inserted as configuration data (example, I do it much more automated in the real app):
       dataDelegation.setConfiguration(
       ?<action>approval</action>? +
       ?<username>jsmith</username>? +
       ?<email>jsmith@company.com</email>? +
       ?<createDate>09/15/2005</createDate>?
       );
      

      Pulling it back out for editing the task is a LITTLE painful (the XML string has to be manually parsed back out into its pieces) but it's do-able. Obviously at run time, getting variables in and out of the ProcessInstance is pretty straightforward, but this is for maintaining the definition.

      So?

      Is there a better way?

        • 1. Re: Storing Application Data With A Task Node Definition
          tom.baeyens

          i think you found the best solution that
          1) does not change the jbpm db schema and
          2) does not change the jbpm code.

          more clean would be to write your own subclass of TaskNode, and add the members to that subclass and persist them with hibernate.

          but that requires to change the hibernate mapping files (adding one) and hence changing the jbpm db schema.

          regards, tom.

          ps. congrats ! you really know your way around jbpm.