Create Business Process Diagram using Open API

Business Process Model and Notation (BPMN) is a standard to model and visualize the business workflow. In Visual Paradigm user can model the business workflow with BPMN using Business Process Diagram. In this article we will show you how to create Business Process Diagram with BPMN using Open API.

Sample Business Process Diagram

This is the Business Process Diagram we going to create. It consist of pools, lanes, task, sub-process, start and end events, as well as sequence and message flows.

Create Blank Business Process Diagram

First we create a blank Business Process Diagram. We can use the DiagramManager.createDiagram to create a blank diagram.

// Create blank Business Process Diagram
DiagramManager diagramManager = ApplicationManager.instance().getDiagramManager();
IBusinessProcessDiagramUIModel bpd = (IBusinessProcessDiagramUIModel) diagramManager.createDiagram(IDiagramTypeConstants.DIAGRAM_TYPE_BUSINESS_PROCESS_DIAGRAM);
bpd.setName("Simple BPD");

Create Pools and Lanes

Once the diagram is ready we then go to create the pools and lanes. We first create the Supplier pool from IModelElementFactory. We will turn off the Auto Stretch Pool option to avoid the pool being resize automatically according to the diagram width.

// Create pool model for Supplier
IBPPool poolSupplier = IModelElementFactory.instance().createBPPool();
poolSupplier.setName("Supplier");
// Create the pool shape on diagram
IBPPoolUIModel poolShapeSupplier = (IBPPoolUIModel) diagramManager.createDiagramElement(bpd, poolSupplier);
poolShapeSupplier.setBounds(20, 210, 700, 240);
// Turn off the auto stretch off pool option        
poolShapeSupplier.setAutoStretch(IBPPoolUIModel.AUTO_STRETCH_OFF);
// Call to re-calculate caption position when render the diagram
poolShapeSupplier.resetCaption();

Once the pool model and shape being created we can then create its child lanes. We can use the IBPPool.createBPLane() method to lanes under the pool.

// Create the Distribution lane under Supplier pool
IBPLane laneDistribution = poolSupplier.createBPLane();
laneDistribution.setName("Distribution");		
// Create the lane shape for Distribution
IBPLaneUIModel laneShapeDistribution = (IBPLaneUIModel) diagramManager.createDiagramElement(bpd, laneDistribution);
poolShapeSupplier.addChild(laneShapeDistribution);
laneShapeDistribution.setBounds(35, 210, 685, 120);
laneShapeDistribution.resetCaption();

Now try to create the other pools and lanes on diagram by yourself.

Create Start Events

Now we go to create the Start Events inside the lane. Similar to create lanes under pool, you can use the IBPLane.createBPStartEvent() to create the start event.

// Create start event model and shape under Sales lane
IBPStartEvent startSales = laneSales.createBPStartEvent();
IBPStartEventUIModel startShapeSales = (IBPStartEventUIModel) diagramManager.createDiagramElement(bpd, startSales);
laneShapeSales.addChild(startShapeSales);
startShapeSales.setBounds(70, 380, 20, 20);

Create Tasks and Sub-processes

Next we create the task and sub-process. Similar to above, we can use the IBPLane.createBPTask() and IBPLane.createBPSubProcess() to create the task and sub-process.

// Create Authorize Payment task model and shape under Sales lane
IBPTask taskAuthorizePayment = laneSales.createBPTask();
taskAuthorizePayment.setName("Authorize Payment");
IBPTaskUIModel taskShapeAuthorizePayment = (IBPTaskUIModel) diagramManager.createDiagramElement(bpd, taskAuthorizePayment);
laneShapeSales.addChild(taskShapeAuthorizePayment);
taskShapeAuthorizePayment.setBounds(130, 370, 80, 40);
taskShapeAuthorizePayment.resetCaption();

// Create Process Order sub-process model and shape under Sales lane
IBPSubProcess subprocessProcessOrder = laneSales.createBPSubProcess();
subprocessProcessOrder.setName("Process Order");
IBPSubProcessUIModel subprocessShapeProcessOrder = (IBPSubProcessUIModel) diagramManager.createDiagramElement(bpd, subprocessProcessOrder);
laneShapeSales.addChild(subprocessShapeProcessOrder);
subprocessShapeProcessOrder.setBounds(260, 370, 90, 40);
subprocessShapeProcessOrder.resetCaption();

Again, it’s your turn to create the other tasks and sub-processes on diagram.

Create End Events

Now we go to create the last flow elements in diagram, which is the end event. We can use the IBPLane.createBPEndEvent() to create the end event element.

// Create end event model and shape under Distribution lane
IBPEndEvent endDistribution = laneDistribution.createBPEndEvent();
IBPEndEventUIModel endShapeDistribution = (IBPEndEventUIModel) diagramManager.createDiagramElement(bpd, endDistribution);
laneShapeDistribution.addChild(endShapeDistribution);
endShapeDistribution.setBounds(660, 260, 20, 20);

Create Sequence Flows and Message Flows

Once all flow elements being created we then turn to create the relationships. In the sequence flow and message flow are the major relationships in Business Process Diagram. The sequence flow is the flow within the pool, and message flow is the one across the pool. To create sequence flows:

// Create sequence flow model between start event in Sales lane and Authorize Payment task
IBPSequenceFlow seqSalesStartAuthorizePayment = IModelElementFactory.instance().createBPSequenceFlow();
seqSalesStartAuthorizePayment.setFrom(startSales);
seqSalesStartAuthorizePayment.setTo(taskAuthorizePayment);
// Create sequence flow shape between start event in Sales lane and Authorize Payment task shape 
diagramManager.createConnector(bpd, seqSalesStartAuthorizePayment, startShapeSales, taskShapeAuthorizePayment, new Point[] {new Point(90, 390), new Point(130, 390)});

And to create message flows:

// Create message flow model and shape from Credit Card Authorization task to Credit Card Authorization sub-process 
IBPMessageFlow msgAuthorizePaymentCreditCardAuthorization = IModelElementFactory.instance().createBPMessageFlow();
msgAuthorizePaymentCreditCardAuthorization.setFrom(taskAuthorizePayment);
msgAuthorizePaymentCreditCardAuthorization.setTo(subprocessCreditCardAuthorization);
diagramManager.createConnector(bpd, msgAuthorizePaymentCreditCardAuthorization, taskShapeAuthorizePayment, subprocessShapeCreditCardAuthorization, new Point[] {new Point(150, 370), new Point(150, 135)});

Now it’s your turn to create other sequence flow and message flows on diagram.

Show Up the Diagram

Finally we can show up the diagram.

// Show up the diagram
diagramManager.openDiagram(bpd);

Sample Plugin

The sample plugin demonstrate how to create business process diagram using Open API. After you deploy the plugin into Visual Paradigm you can then click the plugin button in the application toolbar to trigger it.

Trigger sample plugin

Download Sample Plugin

You can click this link to download the sample plugin.

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply