[rules-users] WorkflowProcessInstance in DRL

Gareth Evans evans.g.p at gmail.com
Wed Mar 23 23:07:24 EDT 2011


Thought I'd update my post for anyone Googling this. I am not sure if
my solution is correct (or if I am addressing the wrong problem)
though it has been satisfactory so far in our testing environment.

What I did was create an event listener implementing
ProcessEventListener and RuleFlowEventListenerExtension that would
grab the ProcessInstance fact handle from working memory and update it
on the following events:

	@Override
	public void beforeProcessStarted(ProcessStartedEvent processStartedEvent) {
		maintainPorcessInstance(processStartedEvent.getKnowledgeRuntime(),
processStartedEvent.getProcessInstance());
	}
	
	@Override
	public void beforeNodeLeft(ProcessNodeLeftEvent processNodeLeftEvent) {
		if(processNodeLeftEvent.getNodeInstance() instanceof SubProcessNodeInstance) {
			maintainPorcessInstance(processNodeLeftEvent.getKnowledgeRuntime(),
processNodeLeftEvent.getProcessInstance());
		}
	}
	
	@Override
	public void afterVariableChange(RuleFlowVariableChangeEvent
ruleFlowVariableChangeEvent, WorkingMemory workingMemory) {
		maintainProcessInstance(ruleFlowVariableChangeEvent, workingMemory);
	}

This means that I do not need to manually update the ProcessInstance
when entering a subflow or after changing a rule flow variable.

Cheers,
Gareth

On 1 March 2011 09:04, Gareth Evans <evans.g.p at gmail.com> wrote:
> I'll try to make my questions less verbose:
>
> 1) When you change a flow variable what is the best way to update the
> WorkflowProcessInstance object in working memory if you are using
> subflows and hence have multiple WorkflowProcessInstances?
>
> 2) If I insert the WorkflowProcessInstance for both a parent flow and
> child subflow and reference it in the LHS of a rule using
> "processInstance : WorkflowProcessInstance()" I get activations for
> both instances of the object. The documentation says that this should
> only match the current process instance. Am I doing something wrong?
>
> Cheers!
> Gareth
>
> On 25 February 2011 08:48, Gareth Evans <evans.g.p at gmail.com> wrote:
>> Hello,
>>
>> I am having some problems using WorkflowProcessInstance in rules. I
>> have searched and not been able to find an answer to my question.
>>
>> I am attempting to use rule flows to define business processes and
>> rules both in ruleflow groups to be executed on demand of the process
>> and outside of a ruleflow group for "global" rules and to potentially
>> direct the ruleflow(/process) is to run. Many of these processes are
>> comprised of subprocesses which I have been using sub flows to model.
>>
>> I have used flow variables to store some minimal information about the
>> process such as what the process ID corresponds to in the existing
>> data model I am working with. My intent was so that I could use a
>> single rule flow group in many rule flows to extract information from
>> the database for the corresponding process ID in the working memory
>> (this extraction would also depend on other facts in the working
>> memory).
>>
>> I've inserted the WorkflowProcessInstance by using an action node in
>> the "parent" process and it seems to work fine. My problem arises when
>> I am then in a "child" process/subflow and try to invoke this single
>> rule flow group with a different process ID in the flow variable,
>> there are no activations. I think this happens because the
>> WorkflowProcessInstance has not been updated in working memory so it
>> will not know that there might be a new process ID stored in the flow
>> variable (it has the same name in both flows as it is meant to
>> represent the same thing).
>>
>> If I insert the WorkflowProcessInstance again in the sub flow I get
>> activations in the rule flow group for facts in the working memory
>> associated with both the parent and child sub flow which almost makes
>> sense except for this:
>>
>> "We have added special logic to make sure that a variable
>> processInstance of type WorkflowProcessInstance will only match to the
>> current process instance and not to other process instances in the
>> Working Memory."
>>
>> It seems that it is matching both instances of
>> WorkflowProcessInstance. I use the convention of starting variable
>> names from the LHS of a rule with a $ but I have tested it without and
>> I get the same result. Is this expected behaviour?
>>
>> An alternative I've been trying to figure out is how to update the
>> WorkflowProcessInstance in working memory in the child process. Since
>> it is actually a different object I'm unsure how to do this. Should I
>> retract all instances and then insert the current? Is there a way to
>> do this more cleanly than looking through all working memory objects
>> and checking their type in an action node?
>>
>> Finally (or perhaps firstly...), am I going about this correctly?
>>
>> Cheers,
>> Gareth
>>
>




More information about the rules-users mailing list