[jboss-user] [JBoss jBPM] - Re: Can I get to the parent process, given a sub-process?

avbentem do-not-reply at jboss.com
Mon Apr 23 11:53:29 EDT 2007


GraphElement#getParentChain is documented to return "this graph element plus all the parents ordered by age". However, this does not seem to work when using sub-processes: the parents of the parent process-state(s) are not returned. 

To me, the "ordered by age" in the documentation suggests that getParents/getParentChain return runtime information, knowing about how a specific process got invoked, and thus also returning that information... So, maybe either the documentation can be enhanced to make clear that any super process is not taken into account. Or, if we'd expect the super process(es) to be included as well, then the current implementation has a bug. 

Any ideas on this?

For example:
// NOTE: not thoroughly tested
  | public String getElementHistory(GraphElement element) {
  |     StringBuffer s = new StringBuffer();
  |     List<GraphElement> parentChain = element.getParentChain();
  |     if (parentChain != null) {
  |         for (GraphElement parent : parentChain) {
  |             if (s.length() != 0) {
  |                 s.append(" -> ");
  |             }
  |             s.append(parent.getName());
  |             s.append(" [" + parent.getClass().getSimpleName() + "]");
  |         }
  |     }
  |     return s.toString();
  | }
This prints
task1 [TaskNode] -> my-sub-process [ProcessDefinition]
...when invoked using
log.info(getElementHistory(taskInstance.getToken().getNode()));
...from a task-start event in the example posted earlier in this thread: 
<process-definition xmlns="" name="my-sub-process">
  |    :
  |    <task-node name="task1">
  |       <task name="task1">
  |          <event type="task-start">
  |             <action name="taskStart" expression="#{...}" />
  |          </event>
  |          ...
  |       </task>
  |       :
Above, it doesn't matter whether my-sub-process is started stand-alone, or by some parent process: the code does not iterate into the parent process.

Of course, one could use getSuperProcessToken to iterate into the parent process, using the processInstance rather than a token from the taskInstance. Like:
// NOTE: not thoroughly tested
  | public String getProcessHistory(ProcessInstance instance) {
  |     StringBuffer s = new StringBuffer();
  | 
  |     Token superToken = instance.getSuperProcessToken();
  |     if (superToken != null) {
  |         ProcessInstance superInstance = superToken.getProcessInstance();
  |         s.append(getHistory(superInstance));
  |     }
  | 
  |     List<GraphElement> parentChain =
  |         instance.getProcessDefinition().getParentChain();
  |     if (parentChain != null) {
  |         for (GraphElement parent : parentChain) {
  |             if (s.length() != 0) {
  |                 s.append(" -> ");
  |             }
  |             s.append(parent.getName());
  |         }
  |     }
  |     return s.toString();
  | }
For the example posted earlier, when passing the processInstance, this would print:
my-process -> my-sub-process
It's a bit harder to get the detailed node information though...

Arjan.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4039904#4039904

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4039904



More information about the jboss-user mailing list