Cannot create diagram elements using Fluent Api

I am trying to get familiar with Fluent API and using 7.7.0-alpha1 maven library. I took an example from the documents and created following class in java :

public class DataLineageImplHelper {

public static void createXml() {
    //easyExample();
    easyExampleWithDetails();
    //thirdExample();
    First();
}

public static  <T extends BpmnModelElementInstance> T createElement(BpmnModelInstance modelInstance,
                                                               BpmnModelElementInstance parentElement, String id, Class<T> elementClass) {
    T element = modelInstance.newInstance(elementClass);
    element.setAttributeValue("id", id, true);
    parentElement.addChildElement(element);
    return element;
}

public static SequenceFlow createSequenceFlow(BpmnModelInstance modelInstance, Process process, FlowNode from, FlowNode to) {
    String identifier = from.getId() + "-" + to.getId();
    SequenceFlow sequenceFlow = createElement(modelInstance, process, identifier, SequenceFlow.class);
    process.addChildElement(sequenceFlow);
    sequenceFlow.setSource(from);
    from.getOutgoing().add(sequenceFlow);
    sequenceFlow.setTarget(to);
    to.getIncoming().add(sequenceFlow);
    return sequenceFlow;
}

public static void easyExampleWithDetails() {
    // create an empty model
    BpmnModelInstance modelInstance =  Bpmn.createEmptyModel();
    Definitions definitions = modelInstance.newInstance(Definitions.class);
    definitions.setTargetNamespace("http://camunda.org/examples");
    modelInstance.setDefinitions(definitions);

    // create the process
    Process process = createElement(modelInstance, definitions, "process-with-one-task", Process.class);

    // create start event, user task and end event
    StartEvent startEvent = createElement(modelInstance, process, "start", StartEvent.class);
    UserTask task1 = createElement(modelInstance, process, "task1", UserTask.class);
    task1.setName("Process 1");
    EndEvent endEvent = createElement(modelInstance, process, "end", EndEvent.class);

    // create the connections between the elements
    createSequenceFlow(modelInstance, process, startEvent, task1);
    createSequenceFlow(modelInstance, process, task1, endEvent);

    Bpmn.validateModel(modelInstance);
    String xmlString = Bpmn.convertToString(modelInstance);
    System.out.println(xmlString);
    File file = new File("Desktop/BPMN/bpmn files/Second.bpmn");
    Bpmn.writeModelToFile(file, modelInstance);
}

}

This generates a .bpmn file without any Diagram elements. The output looks like this :

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<definitions id="definitions_0a80c816-2df6-4658-9739-7d600837fa81" targetNamespace="http://camunda.org/examples" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL">
  <process id="process-with-one-task">
    <startEvent id="start">
      <outgoing>start-task1</outgoing>
    </startEvent>
    <userTask id="task1" name="Process 1">
      <incoming>start-task1</incoming>
      <outgoing>task1-end</outgoing>
    </userTask>
    <endEvent id="end">
      <incoming>task1-end</incoming>
    </endEvent>
    <sequenceFlow id="start-task1" sourceRef="start" targetRef="task1"/>
    <sequenceFlow id="task1-end" sourceRef="task1" targetRef="end"/>
  </process>
</definitions>

Can someone please help me what is the missing piece in the code to generate diagram elements?

Diagram Interchange data only gets generated when you use the fluent builder. See https://github.com/camunda/camunda-bpm-examples/tree/master/bpmn-model-api/generate-process-fluent-api for an example. Also, I recommend you switch from 7.7.0-alpha1 to 7.7.0 for additional features and bug fixes.

Cheers,
Thorben

Hello,
Maybe you need to add BpmnEdge and Waypoint in createSequenceFlow.

Example;

UserTask task = createElement(modelInstance, process, “task”, “GeneralUserTaskModel”, UserTask.class, plane, 50d, 50d, 75d, 100d, true);

public SequenceFlow createSequenceFlow(BpmnModelInstance modelInstance, Process process, FlowNode from, FlowNode to, BpmnPlane plane,
Integer… 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;
}