bardioc77 [http://community.jboss.org/people/bardioc77] created the discussion

"jbpm 4.4: sub-process in foreach: howto modify business key"

To view the discussion, visit: http://community.jboss.org/message/575112#575112

--------------------------------------------------------------
Hello,

we are using the new foreach-node within our model to start a sub-process for 
each message in a list. The sub-process falls into a waiting state (with a set 
timeout). Each message in a list can be identified by a business key containing 
two values (person-id + contract-id). The (simplified) model is as follows:


<foreach g="493,601,48,48" name="foreach" 
var="message.incomingSingleMessages">    <transition g="10,-7" name="to sub: 
process single messages" to="sub: process single message"/></foreach>
<sub-process g="430,707,169,52" name="sub: process single message" 
sub-process-key="ProcessSingleMessage">   <transition g="-76,-7" name="to end 
foreach" to="end foreach"/></sub-process>
<join g="491,789,48,48" name="end foreach" 
multiplicity="#{message.incomingSingleMessages}">    <transition g="-170,-9" 
name="to map success message response" to="map success message 
response"/></join>



Now it might happen that while one sub-process is in the defined waiting state, 
a message with the same business key is created. We would like to either delete 
the waiting state or modify it rather than creating another new sub-process. 
However, we do not know how to find the corresponding waiting execution of the 
previous sub-process to signal it.

What we accomplished till now is the following. Within the sub-process right 
after the 'start'-node, we figure out, whether a sub-process already exists. In 
that case, we modify the message that waits and finish the sub-process. We use 
the following code for this.


// collect waiting jobsfinal JobQuery jobQuery = 
this.managementService.createJobQuery().timers();for (final Job job : 
jobQuery.list()){     // get Process from job     ProcessInstance process = 
executionService.findProcessInstanceById(job.getExecution().getId());     final 
Execution exec = job.getExecution();     // get Variable name     final Message 
oldMessage = (Message) this.executionService.getVariable(exec.getId(), 
"message");     if (oldMessage.getPersonId() == message.getPersonId() 
             &amp;&amp; oldMessage.getContractId() == message.getContractId())
     {
         // modify old message
     }

}



The better solution would be to directly transition to the currently waiting 
sub-process by embedding the business key (personId + contractId) in the 
sub-process' id and simply try to find the waiting sub-process.

Has somebody an idea of how to accomplish this?

Thank you very much.

Heiko

PS: If more or detailed information is needed, I'll provide them.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/575112#575112]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to