-
1. Re: Can I get to the parent process, given a sub-process?
avbentem Mar 30, 2007 4:17 AM (in response to avbentem)Meanwhile I've found GraphElement#getParents() (and likewise getParentChain), which returns all the parents of a graph element ordered by age.
List parents = processInstance.getProcessDefinition().getParents();
To me, it's a bit odd that the parents are retrieved from the process definition, as this would then not take runtime changes into account?
Like when using an event handler to set the sub-process on runtime -- that would probably change the process definition of that specific process instance, but I doubt these are persisted for each process instance?
Or when using loops, like when the current process has already been executed 3 times, would one then expect the current process to be found in getParents() 3 times as well?
Hmmm, maybe getParents() is the way to go in this case (to get the calling <process-state> from within some sub-process I would not care about traversing all the way up to the main process). I'll soon want an overview of the whole history though, so any thoughts are appreciated!
Thanks,
Arjan. -
2. Re: Can I get to the parent process, given a sub-process?
avbentem Apr 23, 2007 11:53 AM (in response to avbentem)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 printstask1 [TaskNode] -> my-sub-process [ProcessDefinition]
...when invoked usinglog.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.