No diagram to display. Why?

Hi I have integrated the Camunda API in my eclipse.
I also tried to follow the example nr.1 in this page:
https://docs.camunda.org/manual/7.7/user-guide/model-api/bpmn-model-api/create-a-model/

When I try to run the program, it will succeed to create a .bpmn file but when I try to open it with the Camunda Modeler, the model doesn’t appears and meanwhile it is showed a message that says: “ooops! No diagram to display. Do you believe “bpmn-model-api-9187723787476926161.bpmn” is a valid BPMN diagram?”
I will providea screen about the error to let you understand better… please help me to understand which is the error since I simply followed the guide.

@Andrea_Nardi can you upload your BPMN model?

@aravindhrs I can’t! Actually I am trying to create a model from the beginning using the API of Camunda.

https://docs.camunda.org/manual/7.7/user-guide/model-api/bpmn-model-api/create-a-model/

Here there is a guide to create a simple model composed by a start event, followed by a user task and then an end event.
I wanted to create it using the guide, when I run the program it creates a bpmn file which I tried to open with Camunda Modeler. But this is the error that I get when I try to visualize the model in the Camunda Modeler… I think that there is something missing in thew xml file but I followed all the steps in the guide so I don’t know what it is…
Please help me…

The guide you’ve been following also says:

The following code creates this process using the helper methods from above (without the DI elements).
You’re creating a model through this API but no visual represantation of this model.
Because of this, modeller only shows you the xml and no graphic.

@langfr can you please help me to understand how to create the DI elements? there are no guidelines in the Camunda website I guess…
Please help me.

When you create BPMN model using camunda modeler it generates a xml file which contains xml element called <BPMNDiagram> , which is used for BPMN visualization. So from your model visualization part is missing. Same model you can design in camunda modeller also and then compare both xml and check what modeller is generated extra.

@langfr @aravindhrs
Here it is my code where I created the methods for creating elements and the sequence flows:

package Prova.Prova;

import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.BaseElement;
import org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance;
import org.camunda.bpm.model.bpmn.instance.Definitions;
import org.camunda.bpm.model.bpmn.instance.FlowNode;
import org.camunda.bpm.model.bpmn.instance.Process;
import org.camunda.bpm.model.bpmn.instance.SequenceFlow;
import org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnDiagram;
import org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnEdge;
import org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnLabel;
import org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnPlane;
import org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape;
import org.camunda.bpm.model.bpmn.instance.dc.Bounds;
import org.camunda.bpm.model.bpmn.instance.di.Waypoint;

public class HelpClass {

public BpmnModelInstance modelInstance;
public Definitions definitions;
public Process process;
public BpmnPlane plane;

public HelpClass() {
}

public void create() {

	modelInstance = Bpmn.createEmptyModel();

	definitions = modelInstance.newInstance(Definitions.class);
	definitions.setTargetNamespace("http://camunda.org/examples");
	modelInstance.setDefinitions(definitions);

	process = modelInstance.newInstance(Process.class);
	process.setId("process");
	definitions.addChildElement(process);
	
	BpmnDiagram diagram = modelInstance.newInstance(BpmnDiagram.class);
    BpmnPlane plane = modelInstance.newInstance(BpmnPlane.class);
    plane.setBpmnElement(process);
    diagram.setBpmnPlane(plane);
    definitions.addChildElement(diagram);

}

  public <T extends BpmnModelElementInstance> T createElement(BpmnModelElementInstance parentElement, 
	      String id, String name, Class<T> elementClass, BpmnPlane plane, 
	      double x, double y, double heigth, double width, boolean withLabel) {
	    T element = modelInstance.newInstance(elementClass);
	    element.setAttributeValue("id", id, true);
	    element.setAttributeValue("name", name, false);
	    parentElement.addChildElement(element);
	    
	    BpmnShape bpmnShape = modelInstance.newInstance(BpmnShape.class);
	    bpmnShape.setBpmnElement((BaseElement) element);
	    
	    Bounds bounds = modelInstance.newInstance(Bounds.class);
	    bounds.setX(x);
	    bounds.setY(y);
	    bounds.setHeight(heigth);
	    bounds.setWidth(width);
	    bpmnShape.setBounds(bounds);
	    
	    if (withLabel) {
	      BpmnLabel bpmnLabel = modelInstance.newInstance(BpmnLabel.class);
	      Bounds labelBounds = modelInstance.newInstance(Bounds.class);
	      labelBounds.setX(x);
	      labelBounds.setY(y + heigth);
	      labelBounds.setHeight(heigth);
	      labelBounds.setWidth(width);
	      bpmnLabel.addChildElement(labelBounds);
	      bpmnShape.addChildElement(bpmnLabel);
	    }
	    plane.addChildElement(bpmnShape);
	    
	    return element;
	  }

  public SequenceFlow createSequenceFlow(Process process, FlowNode from, FlowNode to, BpmnPlane plane,
	      int... waypoints) {
	    String identifier = from.getId() + "-" + to.getId();
	    SequenceFlow sequenceFlow = modelInstance.newInstance(SequenceFlow.class);
	    sequenceFlow.setAttributeValue("id", identifier, true);
	    process.addChildElement(sequenceFlow);
	    sequenceFlow.setSource(from);
	    from.getOutgoing().add(sequenceFlow);
	    sequenceFlow.setTarget(to);
	    to.getIncoming().add(sequenceFlow);
	    
	    BpmnEdge bpmnEdge = modelInstance.newInstance(BpmnEdge.class);
	    bpmnEdge.setBpmnElement(sequenceFlow);
	    for (int i = 0; i < waypoints.length / 2; i++) {
	      double waypointX = waypoints[i*2];
	      double waypointY = waypoints[i*2+1];
	      Waypoint wp = modelInstance.newInstance(Waypoint.class);
	      wp.setX(waypointX);
	      wp.setY(waypointY);
	      bpmnEdge.addChildElement(wp);
	    }
	    plane.addChildElement(bpmnEdge);
	    
	    return sequenceFlow;
	  }

}

Then in this other class I call these methods to create the start event, the task andthe end event:

package Prova.Prova;

import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance;
import org.camunda.bpm.model.bpmn.instance.Definitions;
import org.camunda.bpm.model.bpmn.instance.EndEvent;
import org.camunda.bpm.model.bpmn.instance.FlowNode;
import org.camunda.bpm.model.bpmn.instance.ParallelGateway;
import org.camunda.bpm.model.bpmn.instance.ServiceTask;
import org.camunda.bpm.model.bpmn.instance.StartEvent;
import org.camunda.bpm.model.bpmn.instance.UserTask;
import org.camunda.bpm.model.bpmn.instance.Process;
import org.camunda.bpm.model.bpmn.instance.SequenceFlow;

import java.io.File;
import java.io.IOException;

import org.camunda.bpm.*;

public class TextBPM {

public static void main(String[] args) throws IOException {

	HelpClass helpClass = new HelpClass();
	helpClass.create();
	

	StartEvent startEvent = helpClass.createElement(helpClass.process, "start", "Di generation wanted", 
	        StartEvent.class, helpClass.plane, 15, 15, 50, 50, true);
	
	UserTask task = helpClass.createElement(helpClass.process, "userTask", "Generate Model with DI", 
	        UserTask.class, helpClass.plane, 100, 0, 80, 100, false);
	task.setName("User Task");
	
	EndEvent endEvent = helpClass.createElement(helpClass.process, "end", "DI generation completed", 
	        EndEvent.class, helpClass.plane, 250, 15, 50, 50, true); 

	 helpClass.createSequenceFlow(helpClass.process, startEvent, task, helpClass.plane, 65, 40, 100, 40);
	 helpClass.createSequenceFlow(helpClass.process, task, endEvent, helpClass.plane, 200, 40, 250, 40);

	// validate and write model to file
	Bpmn.validateModel(helpClass.modelInstance);
	File file = File.createTempFile("bpmn-model-api-", ".bpmn");
	Bpmn.writeModelToFile(file, helpClass.modelInstance);

}

}

The problem now is that when I run the program it says:

Exception in thread “main” java.lang.NullPointerException
at Prova.Prova.HelpClass.createElement(HelpClass.java:84)
at Prova.Prova.TextBPM.main(TextBPM.java:29)

What does it mean? And how can I solve it?

NPE is thrown here:
plane.addChildElement(bpmnShape);
Change
BpmnPlane plane = modelInstance.newInstance(BpmnPlane.class);
to
plane = modelInstance.newInstance(BpmnPlane.class);
.

1 Like

@langfr
Thanks!! Now I can draw the example shown in the Camunda guide :smiley:

Since it is the first step to develop my thesis, and since I am not so good in use Camunda, can you please send me your email address so that if I need an help I can contact you? My name is Andrea from Italy :slight_smile:

@langfr @aravindhrs
Do you know if there is a way to arrange an element in the plane in a “dynamic way”? I mean without setting the position manually but automatically…
Instead of putting coordinates manually, like piutting int values manually, I want the program understand that each element, must be distant from the previous one for about a certain measure… can it be possible?

Here below I post my code:

import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance;
import org.camunda.bpm.model.bpmn.instance.Definitions;
import org.camunda.bpm.model.bpmn.instance.EndEvent;
import org.camunda.bpm.model.bpmn.instance.FlowNode;
import org.camunda.bpm.model.bpmn.instance.ParallelGateway;
import org.camunda.bpm.model.bpmn.instance.ServiceTask;
import org.camunda.bpm.model.bpmn.instance.StartEvent;
import org.camunda.bpm.model.bpmn.instance.UserTask;
import org.camunda.bpm.model.bpmn.instance.Process;
import org.camunda.bpm.model.bpmn.instance.SequenceFlow;

import java.io.File;
import java.io.IOException;

import org.camunda.bpm.*;

public class TextBPM {

public static void main(String[] args) throws IOException {

	HelpClass helpClass = new HelpClass();
	helpClass.create();

	// create the elements

	StartEvent startEvent = helpClass.createElement(helpClass.process, "start", "Start label", StartEvent.class,
			helpClass.plane, 15, 15, 50, 50, true);

	UserTask task = helpClass.createElement(helpClass.process, "userTask", "Task label", UserTask.class,
			helpClass.plane, 100, 0, 80, 100, false);

	EndEvent endEvent = helpClass.createElement(helpClass.process, "end", "End label", EndEvent.class,
			helpClass.plane, 250, 15, 50, 50, true);

	// create the connections between the elements

	helpClass.createSequenceFlow(helpClass.process, startEvent, task, helpClass.plane, 65, 40, 100, 40);
	helpClass.createSequenceFlow(helpClass.process, task, endEvent, helpClass.plane, 200, 40, 250, 40);

	// validate and write model to file

	Bpmn.validateModel(helpClass.modelInstance);
	File file = File.createTempFile("bpmn-model-api-", ".bpmn");
	Bpmn.writeModelToFile(file, helpClass.modelInstance);

}

}

See the creation of the task in my class. As you can see, i had to set the parameter manually to locate it in the plane. I would like to locate it automatically and tell the program something like: "let’s put the task element after the startEvent element but distant about a tot. and before the endEvent element distant about a tot.
Is that clear?
Is it possible?
Thanks.

I never used this API myself.
But in the docs there is a Fluent API (1) as an alternative which seems to generate the diagram automatically (2).

  1. https://docs.camunda.org/manual/7.11/user-guide/model-api/bpmn-model-api/fluent-builder-api/
  2. https://docs.camunda.org/manual/7.11/user-guide/model-api/bpmn-model-api/fluent-builder-api/#generation-of-diagram-interchange

Can you help me with the use of fluent camunda API?
Now I’ll tell you what I have to do with my project:

Here is the code of my class (called FromTextToBPMN.java):

package Prova.Prova;

import java.util.Random;
import java.util.StringTokenizer; //Bisogna importare la classe

import org.apache.poi.ss.formula.functions.Count;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.impl.instance.TimeDateImpl;
import org.camunda.bpm.model.bpmn.impl.instance.TimerEventDefinitionImpl;
import org.camunda.bpm.model.bpmn.instance.BoundaryEvent;
import org.camunda.bpm.model.bpmn.instance.EndEvent;
import org.camunda.bpm.model.bpmn.instance.EventBasedGateway;
import org.camunda.bpm.model.bpmn.instance.ExclusiveGateway;
import org.camunda.bpm.model.bpmn.instance.FlowNode;
import org.camunda.bpm.model.bpmn.instance.IntermediateCatchEvent;
import org.camunda.bpm.model.bpmn.instance.MessageEventDefinition;
import org.camunda.bpm.model.bpmn.instance.Participant;
import org.camunda.bpm.model.bpmn.instance.SendTask;
import org.camunda.bpm.model.bpmn.instance.SignalEventDefinition;
import org.camunda.bpm.model.bpmn.instance.StartEvent;
import org.camunda.bpm.model.bpmn.instance.Task;
import org.camunda.bpm.model.bpmn.instance.TimeDuration;
import org.camunda.bpm.model.bpmn.instance.TimerEventDefinition;

import java.io.;
import java.lang.
;

public class FromTextToBPMN{

public static void main(String [] args) throws IOException{
	
	
	HelpClass helpClass = new HelpClass();
	helpClass.create();
	Random random = new Random();
	
			String input = "The process CSR is a pool." +
					"The process Customer is a pool."  +
					"The process Admin is a black pool." + 
					"The process CSR starts by propose mortgage offer before perform a send message send offer." + 
					"The process CSR performs a send message mortgage offer by send offer after the start and before wait for a reply." + 
					"The process CSR expects a reply after perform a send message mortgage offer and before receive a message reject offer and before receive a message accept offer." + 
					"The process Customer receives a message mortgage offer and starts by offer received before the decision." + 
					"The process Customer must take a decision (Offer accepted?) after the start and before perform a send message offer rejected and before perform a send message offer accepted." + 
					"The decision is: “Offer accepted?”." + 
					"In the first case, the process Customer performs a send message offer rejected by reject offer after the decision and before the end." + 
					"The process Customer ends by offer rejected after perform a send message offer rejected." + 
					"In the second case, the process Customer performs a send message offer accepted by accept offer after the decision and before wait for a reply." + 
					"The process Customer expects a reply after perform a send message offer accepted and before receive a message requesting docs and before receive a message ok offer." + 
					"The process CSR receives a message offer rejected by reject offer after wait for a reply and before perform the activity update details." + 
					"The process CSR performs the activity by update details after receive a message offer rejected and before perform the activity work archived." + 
					"The process CSR performs the activity by work archived after the activity update details and before the activity order cancelled." + 
					"The process CSR performs the activity by order cancelled after the activity work archived and before the end." + 
					"The process CSR ends by order cancelled after the activity order cancelled." + 
					"The process CSR receives a message offer accepted by accept offer after wait for a reply and before perform the activity check documents." + 
					"The process CSR performs the activity by check documents after receive a message offer accepted and before the decision." + 
					"The process CSR must take a decision (Documents attached?) after the activity check documents and before perform a send message requesting docs and before perform a send message move." + 
					"The decision is: “Documents attached?”." + 
					"In the first case, the process CSR performs a send message move by inistration after the decision and before perform a send message ok offer." + 
					"The process Admin catches the message move."+
					"The process CSR performs a send message ok order by ok offer after perform a send message move and before the end." + 
					"The process CSR ends by offer sold after perform a send message ok offer." + 
					"The process Customer receives a message ok offer by ok offer after wait for a reply and before the end." + 
					"The process Customer ends by offer accepted after receive a message ok offer." + 
					"In the second case, the process CSR performs a send message requesting docs by requesting outstanding documents after the decision end before receive a message documents." + 
					"The process Customer receives a message requesting docs by outstanding documents requested after wait for a reply and before perform a send message documents." + 
					"The process Customer performs a send message documents by send documents after receive a message requesting docs and before end." + 
					"The process Customer ends by documents sent after perform a send message documents." + 
					"The process CSR receives a message documents by documents received after perform a send message requesting docs and before wait." + 
					"The process CSR waits by 2 weeks after receive a message documents and before a decision." + 
					"The process CSR must take a decision (Documents received?) after wait and before perform a send message move and before the activity update details." + 
					"In the first case, the process CSR performs a send message move by move to administration after the decision and before the end." +
					"The process Admin catches the message move." +
					"The process CSR ends by offer sold after perform a send message move." + 
					"In the second case, the process CSR performs the activity by update details after the decision and before the activity archive." + 
					"The process CSR performs the activity by archive after the activity update details and before the activity cancellation." + 
					"The process CSR performs the activity by cancellation after the activity archive and before the end." + 
					"The process CSR ends by offer cancelled after the activity cancellation." + "The process PIPPO performs a receive message ID MESSAGGIO by LABEL MESSAGGIO after AFTERQUALCOSA and before BEFOREQUALCOS'ALTRO." +
					"The process PIPPO sends a message ID MESSAGGIO and ends by LABEL MESSAGGIO after AFTERQUALCOSA and before BEFOREQUALCOS'ALTRO." + "The process PIPPO customer sends a message ID MESSAGGIO by LABEL MESSAGGIO after AFTERQUALCOSA and before BEFOREQUALCOS'ALTRO." + 
					"The choice is: “Which kind of goods?”." + 
					"The process PIPPO begins at LABEL TIMER before BEFORE QUALCOSA." +
					"The process PIPPO begins in LABEL TIMER before BEFORE QUALCOSA." +
					"The process PIPPO begins every LABEL TIMER before BEFORE QUALCOSA." +
					"The process PIPPO waits by LABEL START-TIMER after AFTER QUALCOSA and before BEFORE QUALCOS'ALTRO."+
					"SCRIVI QUALCOSA DI SBAGLIATO.";

String common = "The process "; // This string is in common in all the sentences and I will find it in every BPMN element.

			String pool = "is a pool"; // The "common" string + the "pool" string gives me the pool BPMN element
			String Bpool = "is a black"; // The "common" string + the "Bpool" string gives me the  Blackpool BPMN element
			String BpoolMsg = "catches the message"; // The "BpoolMsg" string must draw a Bpool receiving a message.
		
			String start = "starts "; // The "common" string + the "start" string gives me the start event BPMN element
			String msgR = "receives a message "; // The "common" string + the "msgR" string gives me the INTERMEDIATE RECEIVE MESSAGE BPMN element. If in the sentence there is also the "start" string I must draw the START-RECEIVING MESSAGE.
			
			String end = "ends "; //The "common" string + the "end" string gives me the end BPMN element
			String msgS = "sends a message "; // The "common" string + the "msgS" string gives me the INTERMEDIATE SEND MESSAGE BPMN element. If in the sentence there is also the "and" string(declared in the next step) I must draw the END-SEND-MESSAGE.
			String and ="and ends"; // I will use this string to distinguish the simple INTERMEDIATE SEND MESSAGE-EVENT from the END MESSAGE-EVENT.
			
			String task = "performs the activity"; // The "common" string + the "task" string gives me the task BPMN element
			String taskS = "performs a send message "; // The "common" string + the "taskS" string gives me the TASK-SEND MESSAGE BPMN element. 
			String taskR = "performs a receive message "; // The "common" string + the "taskR" string gives me theTASK-RECEIVE MESSAGE BPMN element.
			
			String xorS = "must take a decision"; // The "common" string + the "xorS" string gives me the XOR SPLIT BPMN element
			String xorJ = "completes the decision"; //The "common" string + the "xorJ" string gives me the XOR JOIN BPMN element
			
			String andS = "must take a parallel selection"; //The "common" string + the "andS" string gives me the  AND SPLIT BPMN element
			String andJ = "completes the selection"; // The "common" string + the "andJ" string gives me the AND JOIN BPMN element 
			
			String inclS = "must make a choice"; // The "common" string + the "inclS" string gives me the INCLUSIVE SPLIT BPMN element
			String inclJ = "completes the choice"; // The "common" string + the "inclJ" string gives me the INCLUSIVE JOIN BPMN element.
			
			String eventBased = "expects a reply"; // The "common" string + the "eventBased" string gives me the EVENT-BASED GATEWAY BPMN element.
			
			String timerStart1 = "begins at"; // The "common" string + the "timerStart1" string gives me the START TIMER EVENT BPMN element.
			String timerStart2 = "begins in"; // The "common" string + the "timerStart2" string gives me the START TIMER EVENT BPMN element.
			String timerStart3 = "begins every"; //  The "common" string + the "timerStart3" string gives me the START TIMER EVENT BPMN element.
			
			String timerIntermediate = "waits by"; //  The "common" string + the "timerIntermediate" string gives me the INTEMREDIATE TIMER EVENT BPMN element. 
			
			String intrLabel = "by "; // used to write labels of the elements (like tasks and others)
			String conj = "and "; // used to find the id of the messages in the START-RECEIVING MESSAGE ELEMENT and in the END-SENDING MESSAGE. 
			
			String before = "before "; //used for linking elements purpose.
			String after = "after "; //used for linking elements purpose.

String[] result = input.split("\."); // I create an array of strings and inside it there is the input text splitted in sentences (strings) by the “dot” character.

			for (String inputStr:result) { // For each single sentence I am going to apply the rules here below.					
					
				if(inputStr.contains(common)&&inputStr.contains(pool)) { //  If in the sentence I will find "The process" + "is a pool"
					
						String processName = inputStr.substring((inputStr.indexOf(common.toLowerCase())+common.length()), inputStr.indexOf(pool));
						
						System.out.println("\n" + "POOL:" + inputStr);// print POOL
						System.out.println("POOL NAME:"+ processName.trim()); // print POOL NAME + name of the pool;
					
					
				}	
									
				else if(inputStr.contains(common)&&inputStr.contains(Bpool)) { //  If in the sentence I will find "The process" + "is a black"
					
				//	String processName = inputStr.substring((inputStr.indexOf(common.toLowerCase())+common.length()), inputStr.indexOf(Bpool));
					
				//	System.out.println("\n" + "BLACKPOOL:" + inputStr); // print BLACKPOOL
				//	System.out.println("BLACKPOOL NAME:"+processName.trim()); // print BLACKPOOL NAME: + name of the pool
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(BpoolMsg)) { //  If in the sentence I will find "The process" + "catches the message"
					
				//	String processName = inputStr.substring((inputStr.indexOf(common.toLowerCase())+common.length()), inputStr.indexOf(BpoolMsg));
				//	String idMsgR = inputStr.substring(inputStr.indexOf(BpoolMsg)+BpoolMsg.length(), inputStr.length());
					
				//	System.out.println("\n" + "BLACKPOOL CATCHING MESSAGE:" + inputStr); // print BLACKPOOL CATCHING MESSAGE
				//	System.out.println("BLACKPOOL NAME:"+processName.trim()); // print BLACKPOOL NAME: + name of the pool
				//	System.out.println("ID-MESSAGE:"+idMsgR.trim()); // print ID-MESSAGE: + the id of the message received.
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(start)&&inputStr.contains(msgR)) { //  If in the sentence I will find "The process" + "starts" + "receives a message"	
					
					//	String processName = inputStr.substring((inputStr.indexOf(common.toLowerCase())+common.length()), inputStr.indexOf(msgR));
					//	String idMsgReceive =inputStr.substring(inputStr.indexOf(msgR)+msgR.length(), inputStr.indexOf(conj));
					//	String label = inputStr.substring(inputStr.indexOf(intrLabel)+intrLabel.length(), inputStr.indexOf(before));
					
					//		System.out.println("\n" + "START RECEIVE-MESSAGE:" + inputStr); // print START RECEIVE-MESSAGE
					//		System.out.println("PROCESS NAME:"+ processName.trim()); // print PROCESS NAME: + name of the process
					//		System.out.println("ID-MESSAGE:"+idMsgReceive.trim()); // print ID-MESSAGE: + id of the message received.
					//		System.out.println("LABEL:"+label.trim()); // print LABEL: + label of the element
				
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(msgR)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(msgR))) { //  If in the sentence I will find "The process" / ""the process" + "receives a message"
					
					//		String processName = inputStr.substring((inputStr.indexOf(common.toLowerCase())+common.length()), inputStr.indexOf(msgR));
					//		String idMsgReceive = inputStr.substring(inputStr.indexOf(msgR)+msgR.length(), inputStr.indexOf(intrLabel));
							String label = inputStr.substring(inputStr.indexOf(intrLabel)+intrLabel.length(), inputStr.indexOf(after));
					
					//		System.out.println("\n" + "INTERMEDIATE RECEIVE-MESSAGE:" + inputStr); // print INTERMEDIATE RECEIVE-MESSAGE
					//		System.out.println("PROCESS NAME:"+ processName.trim()); // print PROCESS NAME: + name of the process
					//		System.out.println("ID-MESSAGE:" + idMsgReceive.trim()); // print ID-MESSAGE: + id of the received message 
					//		System.out.println("LABEL:" + label.trim()); // print LABEL: + label of the element
					
							
					IntermediateCatchEvent intermediateCatchEvent = helpClass.createElement(helpClass.process, label.replace(" ", "")+label.valueOf(random.nextInt()).replace(" ", ""), label, IntermediateCatchEvent.class,
							helpClass.plane, 250, 250, 50, 50, true);

							// ISTEAD OF DOING ALL THE SYSTEM.OUT STEPS, HERE I TRIED TO EFFECTIVELY DRAW THE INTERMEDIATE CATCHEVENT ELEMENT FOR EVERY SENTENCE WHICH SATISFY MY CONDITIONS.
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(start)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(start))) { // If in the sentence I will find "The process" / ""the process" + "starts"
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(start));
						String label = inputStr.substring((inputStr.indexOf(intrLabel)+intrLabel.length()), inputStr.indexOf(before));
					
					//	System.out.println("\n" + "START EVENT:" + inputStr); // printSTART EVENT
					//	System.out.println("PROCESS NAME:"+processName.trim());
					//	System.out.println("LABEL:"+label.trim());
						
					StartEvent startEvent = helpClass.createElement(helpClass.process, "start", label, StartEvent.class,
							helpClass.plane, 15, 15, 50, 50, true); 
					
							// ISTEAD OF DOING ALL THE SYSTEM.OUT STEPS, HERE I TRIED TO EFFECTIVELY DRAW THE START EVENT ELEMENT FOR EVERY SENTENCE WHICH SATISFY MY CONDITIONS.
				

				}
					
				else if(inputStr.contains(common)&&inputStr.contains(msgS)&&inputStr.contains(and)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(msgS))&&inputStr.contains(and)) { // If in the sentence I will find "The process" / ""the process"  + "sends a message" + "and ends"
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(msgS));
						String idMsgSend = inputStr.substring(inputStr.indexOf(msgS)+msgS.length(), inputStr.indexOf(conj));
						String label = inputStr.substring(inputStr.indexOf(intrLabel)+intrLabel.length(), inputStr.indexOf(after));
					
					//		System.out.println("\n" + "END SEND-MESSAGE:" + inputStr); // stampa END SEND-MESSAGE
					//		System.out.println("PROCESS NAME:" + processName.trim());
					//		System.out.println("ID-MESSAGE:" + idMsgSend.trim());
					//		System.out.println("LABEL:" + label.trim());
						
				}
					
				else if(inputStr.contains(common)&&inputStr.contains(msgS)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(msgS))) { // If in the sentence I will find "The process" / ""the process"  + "sends a message"
														
							String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(msgS));
							String idMsgSend = inputStr.substring(inputStr.indexOf(msgS)+msgS.length(), inputStr.indexOf(intrLabel));
							String label = inputStr.substring(inputStr.indexOf(intrLabel)+intrLabel.length(), inputStr.indexOf(after));
						
					//		System.out.println("\n" + "INTERMEDIATE SEND-MESSAGE:" + inputStr); // stampa INTERMEDIATE SEND-MESSAGE
					//		System.out.println("PROCESS NAME:" + processName.trim());
					//		System.out.println("ID-MESSAGE:" + idMsgSend.trim());
					//		System.out.println("LABEL:" + label.trim());
						
						
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(end)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(end))) { // If in the sentence I will find "The process" / "the process"  + "ends"
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(end));
						String label = inputStr.substring(inputStr.indexOf(intrLabel)+intrLabel.length(), inputStr.indexOf(after));

						
						
					//	System.out.println("\n" + "END EVENT:" + inputStr); // stampa END EVENT
					//	System.out.println("PROCESS NAME:" + processName.trim());
					//	System.out.println("LABEL:" + label.trim());
						
						EndEvent EndEvent = helpClass.createElement(helpClass.process, label.replace(" ", "")+label.valueOf(random.nextInt()).replace(" ", ""), label, EndEvent.class,
								helpClass.plane, 15, 15, 50, 50, true);

// ISTEAD OF DOING ALL THE SYSTEM.OUT STEPS, HERE I TRIED TO EFFECTIVELY DRAW THE END EVENT ELEMENT FOR EVERY SENTENCE WHICH SATISFY MY CONDITIONS.

				}
				
				else if(inputStr.contains(common)&&inputStr.contains(task)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(task))) { // If in the sentence I will find "The process" / "the process" + "performs the activity"	
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(task));
						String label = inputStr.substring(inputStr.indexOf(intrLabel)+intrLabel.length(), inputStr.indexOf(after));
							
					//	System.out.println("\n" + "TASK:" + inputStr); // stampa TASK 
					//	System.out.println("PROCESS NAME:" + processName.trim());
					//	System.out.println("LABEL:" + label.trim());
							
						Task Task = helpClass.createElement(helpClass.process, label.replace(" ", "")+label.valueOf(random.nextInt()).replace(" ", ""), label, Task.class,
								helpClass.plane, 25, 25, 80, 80, true);

// ISTEAD OF DOING ALL THE SYSTEM.OUT STEPS, HERE I TRIED TO EFFECTIVELY DRAW THE TASK ELEMENT FOR EVERY SENTENCE WHICH SATISFY MY CONDITIONS.
}

				else if(inputStr.contains(common)&&inputStr.contains(taskS)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(taskS))) { //  If in the sentence I will find "The process" / "the process" + "performs a send message"	
											
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(taskS));
						String idMsgSend = inputStr.substring(inputStr.indexOf(taskS)+taskS.length(), inputStr.indexOf(intrLabel));
						String label = inputStr.substring(inputStr.indexOf(intrLabel)+intrLabel.length(), inputStr.indexOf(after));
					
					//	System.out.println("\n" + "SEND-TASK:" + inputStr); // stampa SEND-TASK
					//	System.out.println("PROCESS NAME:"+ processName.trim());
					//	System.out.println("ID-MESSAGE:" + idMsgSend.trim());
					//	System.out.println("LABEL:" + label.trim());	
							
						SendTask sendTask = helpClass.createElement(helpClass.process, label.replace(" ", "")+label.valueOf(random.nextInt()).replace(" ", ""), label, SendTask.class,
								helpClass.plane, 25, 25, 80, 80, true);

// ISTEAD OF DOING ALL THE SYSTEM.OUT STEPS, HERE I TRIED TO EFFECTIVELY DRAW THE SEND TASK ELEMENT FOR EVERY SENTENCE WHICH SATISFY MY CONDITIONS.

				}					
				
				else if(inputStr.contains(common)&&inputStr.contains(taskR)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(taskR))) { //  If in the sentence I will find "The process" / "the process" + "performs a receive message"	
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(taskR));
						String idMsgR = inputStr.substring(inputStr.indexOf(taskR)+taskR.length(), inputStr.indexOf(intrLabel));
						String label = inputStr.substring(inputStr.indexOf(intrLabel)+intrLabel.length(), inputStr.indexOf(after));

					//	System.out.println("\n" + "RECEIVE-TASK:" + inputStr); // print RECEIVE-TASK
					//	System.out.println("PROCESS NAME:"+ processName.trim());
					//	System.out.println("ID-MESSAGE:" + idMsgR.trim());
					//	System.out.println("LABEL:" + label.trim());
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(xorS)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(xorS))) { //  If in the sentence I will find "The process" / "the process" + "must take a decision"		
								
						String label = inputStr.substring(inputStr.indexOf(xorS.toLowerCase())+xorS.length()+2, inputStr.indexOf(after)-2);
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(xorS));
					
					//	System.out.println("\n" + "XOR-SPLIT:" + inputStr); // print XOR-SPLIT
					//	System.out.println("PROCESS NAME:"+ processName.trim());
						
						ExclusiveGateway exclusiveSplit = helpClass.createElement(helpClass.process, "exclusiveSplit"+"exclusiveSplit".valueOf(random.nextInt()).replace(" ", "") , label,
								ExclusiveGateway.class, helpClass.plane, 120, 120, 50, 50, true); 

// ISTEAD OF DOING ALL THE SYSTEM.OUT STEPS, HERE I TRIED TO EFFECTIVELY DRAW THE EXCLUSIVE GATEWAY FOR EVERY SENTENCE WHICH SATISFY MY CONDITIONS.
}

				else if(inputStr.contains(common)&&inputStr.contains(xorJ)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(xorJ))) { //  If in the sentence I will find "The process" / "the process"  + "completes the decision"		
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(xorJ));
					
					//	System.out.println("\n" + "XOR-JOIN:" + inputStr); // stampa XOR-JOIN
					//	System.out.println("PROCESS NAME:"+ processName.trim());
							
				}					
				
				else if(inputStr.contains(common)&&inputStr.contains(andS)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(andS))) { //  If in the sentence I will find "The process" / "the process"  + "must take a parallel selection"		
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(andS));
					
					//	System.out.println("\n" + "AND-SPLIT:" + inputStr); // stampa AND-SPLIT
					//	System.out.println("PROCESS NAME:"+ processName.trim());
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(andJ)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(andJ))) { // se nella frase trovo "The process"/"the process" + "completes the selection"		
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(andJ));
						
					//		System.out.println("\n" + "AND-JOIN:" + inputStr); // print AND-JOIN
					//		System.out.println("PROCESS NAME:"+ processName.trim());
						
				}					
				
				else if(inputStr.contains(common)&&inputStr.contains(inclS)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(inclS))) { //  If in the sentence I will find "The process" / "the process"  + "must make a choice"		
		
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(inclS));
					
					//	System.out.println("\n" + "INCLUSIVE-SPLIT:" + inputStr); // print INCLUSIVE-SPLIT
					//	System.out.println("PROCESS NAME:" + processName.trim());

				}
				
				else if(inputStr.contains(common)&&inputStr.contains(inclJ)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(inclJ))) { //  If in the sentence I will find "The process" / "the process"  + "completes the choice"		
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(inclJ));
					
					//	System.out.println("\n" + "INCLUSIVE-JOIN:" + inputStr); // print INCLUSIVE-JOIN
					//	System.out.println("PROCESS NAME:" + processName.trim());
					
				}					
				
				
				else if(inputStr.contains(common)&&inputStr.contains(eventBased)||(inputStr.contains(common.toLowerCase())&&inputStr.contains(eventBased))) { //  If in the sentence I will find "The process" / "the process"  + "expects a reply"		
					
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(eventBased));
					
					//	System.out.println("\n" + "EVENT-BASED GATEWAY:" + inputStr); // print EVENT-BASED GATEWAY
					//	System.out.println("PROCESS NAME:" + processName.trim());
					
						EventBasedGateway exclusiveSplit = helpClass.createElement(helpClass.process, "eventBasedSplit"+"eventBasedSplit".valueOf(random.nextInt()).replace(" ", ""), "",
								EventBasedGateway.class, helpClass.plane, 500, 500, 50, 50, true);  

/ ISTEAD OF DOING ALL THE SYSTEM.OUT STEPS, HERE I TRIED TO EFFECTIVELY DRAW THE EVENT BASED SPLIT ELEMENT FOR EVERY SENTENCE WHICH SATISFY MY CONDITIONS.

				}		
				
				else if(inputStr.contains(common)&&inputStr.contains(timerStart1)||inputStr.contains(common.toLowerCase())&&inputStr.contains(timerStart1)) { // If in the sentence I will find "The process" / "the process" + "begins at"
					
						String processName1 = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(timerStart1));
						String label = inputStr.substring(inputStr.indexOf(timerStart1)+timerStart1.length(), inputStr.indexOf(before));

					//System.out.println("\n" + "START-TIMER EVENT:" + inputStr); // print START-TIMER EVENT
					//System.out.println("PROCESS NAME:" + processName1.trim());
					//System.out.println("LABEL:" + label.trim());
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(timerStart2)||inputStr.contains(common.toLowerCase())&&inputStr.contains(timerStart2)){ // If in the sentence I will find "The process" / "the process" + "begins in"		
					
						String processName2 = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(timerStart2));
						String label = inputStr.substring(inputStr.indexOf(timerStart2)+timerStart2.length(), inputStr.indexOf(before));
					
					//System.out.println("\n" + "START-TIMER EVENT:" + inputStr); // print START-TIMER EVENT
					//System.out.println("PROCESS NAME:" + processName2.trim());
					//System.out.println("LABEL:" + label.trim());

				}
				
				else if(inputStr.contains(common)&&inputStr.contains(timerStart3)||inputStr.contains(common.toLowerCase())&&inputStr.contains(timerStart3)){ // If in the sentence I will find "The process" / "the process" + "begins every"		
					
						String processName3 = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(timerStart3));
						String label = inputStr.substring(inputStr.indexOf(timerStart3)+timerStart3.length(), inputStr.indexOf(before));
					
					//System.out.println("\n" + "START-TIMER EVENT:" + inputStr); // print START-TIMER EVENT
					//System.out.println("PROCESS NAME:" + processName3.trim());
					//System.out.println("LABEL:" + label.trim());
				}
				
				else if(inputStr.contains(common)&&inputStr.contains(timerIntermediate)||inputStr.contains(common.toLowerCase())&&inputStr.contains(timerIntermediate)) { // If in the sentence I will find "The process" / "the process" + "waits by"		
				
						String processName = inputStr.substring(inputStr.indexOf(common.toLowerCase())+common.length(), inputStr.indexOf(timerIntermediate));
						String label = inputStr.substring(inputStr.indexOf(timerIntermediate)+timerIntermediate.length(), inputStr.indexOf(after));
					
					//	System.out.println("\n" + "INTERMEDIATE-TIMER EVENT:" + inputStr); // print INTERMEDIATE-TIMER EVENT
					//	System.out.println("PROCESS NAME:" + processName.trim());
					//	System.out.println("LABEL:" + label.trim());

				}			
							 
				else {System.out.println("\n" + "YOU HAVE WRITTEN WRONG THIS ELEMENT: "+ inputStr);
				
				}
				
		}
			
		
			
			//System.out.println("\n" + "------TOTALE ELEMENTI:------ " + result.length);	

			Bpmn.validateModel(helpClass.modelInstance);
			File file = File.createTempFile("bpmn-model-api-", ".bpmn");
			Bpmn.writeModelToFile(file, helpClass.modelInstance); 

// THESE LAST THREE LINES OF CODES ARE NEEDED TO VALIDATE AND CREATE THE MODEL.
}

}

@langfr
I have reported the code of my class.
Now I will explain my objective:
The objective is that I am given a written text, composed of many sentences with a fixed structure.
Every sentence of the text starts with a fixed structure as seen in the code: “The process” + other fixed sentences… The intent of my project is that every time the program meets a “particular” sentence he can be able to generate the correspective BPMN element.
I make an example here below:
Let’s suppose that I have the sentence: “The process e-commerce starts by check login status before perform a send message send ok status”
Since in the sentence there is the string “common” equals to “The process” and also the string “start” equals to “starts”, this element is a Start Event BPMN element. After checking the correspective condition in the proper IF cycle, the program must be able to effectively DRAW a start event element in Camunda modeler.
All of this must be made with every element in the text. Every sentence has its own rules, and they are pretty well done, so I am not asking to correct the rules but simply how to generate all the correspective elements with Fluent API of Camunda.
As you can see, during the declaration of each IF Cycle, I tried to draw some elements (like starts events, task ,end events and intermediate catch events) but I have used the simple API of Camunda which implies to arrange each eleemnts manually in the plane… As asked some posts before, I wanted that each element will be automatically linked together… so it can be done using Fluent API of camunda…
So, please @langfr can you help me how to deal with it?
I am really in trouble!
Please answer me :frowning:

Hi Andrea,

To increase the chances to get voluntary help fom the community, you should make it easier to access your code.
Best option probably is, to create a project at GitHub and share the link here, so that people can clone the repository, build the code and see the result you get.

Regards, Frank

@langfr ok thanks Frank… I never used gitHub sorry, but I tried to do it.

I have uploaded my project folder and I copied this link:

Is this the correct way to do it? thanks :slight_smile:

@langfr
I see from the guide that to create a process with fluent API you just neeed to do this way:

BpmnModelInstance modelInstance = Bpmn.createProcess()
  .startEvent()
  .userTask()
  .endEvent()
  .done();

This is a LINEAR way to create a bpmn model, infact in this example 3 elements are created in one time!

But in my program the situation is different. I have some IF cycles: After the first IF cicle I want to create JUST a startEvent element, and after the second IF cycle I want to create JUST a user task... How I have to do?

My program is like that below:

if(condition){

myProcess = BpmnCreateProcess()
.startEvent()
.done();  // HERE I WANT CREATE JUST A START EVENT

}

else if(condition2){

myProcess = ??? (I do not know how to tell the program to continue with the previous declared process) 
.userTask() // HERE I WANT CREATE JUST A USER TASK
.done();  

}

The problem is that it seems not possible to create JUST a userTask without creating a startEvent immediately before... :( 
PLEASE HELP ME :( IS THAT POSSIBLE?

Hi Andrea,

you can create the process model in steps:

        // first create the process builder itself
        ProcessBuilder processBuilder = Bpmn.createExecutableProcess( "process-payments" );

        // parse your file, and
        // if condition, then create a startEvent
        AbstractFlowNodeBuilder builder = processBuilder.startEvent();

        // if condition, then create a serviceTask
        builder = builder.serviceTask().name( "Process Payment" );

        // if condition, then create an endEvent
        builder = builder.endEvent();

        // at the end, create the model and print / persist it
        BpmnModelInstance process = builder.done();
        System.out.println( Bpmn.convertToString( process ) );

Thanks Frank!!!
You are so patient with me that I am not so much talented in programming!
Thanks for this help!
If I will have any other problems I will tag you here :slight_smile:
Thank you…
Andrea.

@langfr
Hi Frank!
Do you know if there is a command to draw the pool element?
If I try to type .pool() nothing appears…
Please help me.
Thanks.
Andrea.