Get swimlane from an activity

365 views
Skip to first unread message

nekron...@gmail.com

unread,
Apr 2, 2014, 9:19:31 AM4/2/14
to camunda-...@googlegroups.com
Hi @ll,

I want to get the swimlane an activity belongs to using the Camunda API. How can I do so?
Thanks for your help in advance!


Greetz
Alex

Daniel Meyer

unread,
Apr 2, 2014, 2:58:47 PM4/2/14
to
Hi Alex,

what do you mean by "Swimmlane"? Do you mean the lane in BPMN?

<process id="invoice" name="invoice receipt" isExecutable="true">
   
<laneSet id="laneSet_5">
     
<lane id="Approver" name="Approver">
       
<flowNodeRef>approveInvoice</flowNodeRef>
       
<flowNodeRef>invoice_approved</flowNodeRef>
     
</lane>
     
<lane id="teamAssistant" name="Team Assistant">
       
<flowNodeRef>reviewInvoice</flowNodeRef>
       
<flowNodeRef>reviewSuccessful_gw</flowNodeRef>
       
<flowNodeRef>assignApprover</flowNodeRef>
       
<flowNodeRef>StartEvent_1</flowNodeRef>
       
<flowNodeRef>invoiceNotProcessed</flowNodeRef>
     
</lane>
     
<lane id="Accountant" name="Accountant">
       
<flowNodeRef>prepareBankTransfer</flowNodeRef>
       
<flowNodeRef>invoiceProcessed</flowNodeRef>
       
<flowNodeRef>ServiceTask_1</flowNodeRef>
     
</lane>
   
</laneSet>


If you want to find the lane for the activity "prepareBankTransfer" you can use the bpmn model API.

First you have to get the model instance of your process. The way to get the model depends on whether you are calling the service API of the engine or whether you are implementing a Service Task or Task Listener. 

    // EITHER (1) service API
   
BpmnModelInstance model = repositoryService.getBpmnModelInstance("...");  

If you are impementing a service task or listener, you can always get the current model instance:

    // OR (2) inside a JavaDelegate / TaskListener ... (while executing the process)
   
BpmnModelInstance model = delegateExecuton.getBpmnModelInstance();

Once you have retrieved the model instance you can simply iterate:

    // find all lanesets within the model
   
Collection<LaneSet> laneSets = model.getModelElementsByType(LaneSet.class);
   
for (LaneSet laneSet : laneSets) {
     
     
//iterate the lanes
     
Collection<Lane> lanes = laneSet.getLanes();
     
for (Lane lane : lanes) {
       
       
// check the flow nodes
       
Collection<FlowNode> flowNodeRefs = lane.getFlowNodeRefs();
       
for (FlowNode flowNode : flowNodeRefs) {
         
         
// check the id. (note that you can do the check based on aly attribute (also from custom namespace) or child element
         
if ("prepareBankTransfer".equals(flowNode.getId())) {
           
// found the lane!
         
}
       
}
     
}


   
}


Note that accessing the BpmnModelInstance is fast since the model instance is cached.

Does this help?

Daniel

nekron...@gmail.com

unread,
Apr 3, 2014, 8:52:08 AM4/3/14
to camunda-...@googlegroups.com, nekron...@gmail.com

Hi Daniel!

Thanks for your answer and that's exactly what I need.
But I have a problem with your code.

The LaneSet.class can't be used for the getModelElementsByType method. I get the following exception:

The method getModelElementsByType(ModelElementType) in the type ModelInstance is not applicable for the arguments (Class<LaneSet>)

I am using Camunda 7.1-Final.

Thanks in advance!

nekron...@gmail.com

unread,
Apr 3, 2014, 9:21:07 AM4/3/14
to camunda-...@googlegroups.com
Hi Daniel,

Forget about my last message, I was still using 7.1-alpha 4 ;).
Everything is working fine!
Thanks a lot for your help!


Greetz
Alex
Reply all
Reply to author
Forward
0 new messages