BPMN Modeler API

294 views
Skip to first unread message

rdl-dev

unread,
Aug 17, 2014, 10:45:58 PM8/17/14
to camunda-...@googlegroups.com
Hi all,

I'm trying to use the Model API found at (http://docs.camunda.org/latest/guides/user-guide/#bpmn-model-api) with the 7.02 version but I'm having several compiling issues. Is there a place where I can find the source code from the examples.

PS: I'm not using the Fluent API.

cheers

thorben....@camunda.com

unread,
Aug 18, 2014, 3:59:56 AM8/18/14
to camunda-...@googlegroups.com, toacy.o...@gmail.com
Hi,

you can find an example here: https://github.com/camunda/camunda-bpm-examples/tree/master/bpmn-model-api/generate-process-fluent-api
Just make sure you have a dependency to the model API lik

<dependency>
<groupId>org.camunda.bpm.model</groupId>
<artifactId>camunda-bpmn-model</artifactId>
<version>7.1.0-Final</version>
</dependency>

If this does not solve your issues, please provide us with more detail on your compile time problems. The fluent API and the model API in general are one artifact.

Cheers,
Thorben

toacy.o...@gmail.com

unread,
Aug 18, 2014, 5:15:14 AM8/18/14
to camunda-...@googlegroups.com, toacy.o...@gmail.com

Hi Thorben and all,

This is what I'm trying to do.

I have a language that I compile to BPMN and it is very hard to have the xml generator up to date so I came across Camunda Model API and believed it would be nice to use.

After reading this link( http://docs.camunda.org/latest/guides/user-guide/#bpmn-model-api), I tried to copy and paste the code that is there and I have some errors. BTW, I'm using version 7.1.0.

The code I am trying is bellow. Lines with the //ERROR comment are those not working.

package org.prisma.test.camunda;

import java.io.File;
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.SequenceFlow;
import org.camunda.bpm.model.bpmn.instance.StartEvent;
import org.camunda.bpm.model.bpmn.instance.UserTask;
import org.camunda.bpm.model.xml.instance.ModelElementInstance;


public class ProcessGen {

void genSimpleProcess(){

// 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(definitions, "process-with-one-task", Process.class); // ERROR

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

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

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

}



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

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

Sebastian Menski

unread,
Aug 18, 2014, 5:38:34 AM8/18/14
to camunda-...@googlegroups.com, toacy.o...@gmail.com
Hi,

is this your complete code or did you simplify it? Cause there are some bugs in it why it would not be compileable.

First you miss the import 
import org.camunda.bpm.model.bpmn.instance.Process;
other wise you will use the java.lang.Process class.

Second your code you handle or pass the possible IOException of File.createTempFile method.

Third in the createElement method you use the variable
modelInstance
which is not defined in this scope. Either you pass it in with the method call
or save it as field in the class when you create it in the genSimpleProcess method.

After these fixes your code is compileable. So did this fix your problem or are there other
errors?

Cheers
Sebastian

rdl-dev

unread,
Aug 18, 2014, 6:17:38 PM8/18/14
to camunda-...@googlegroups.com
Hi Sebastian,

Looks good! Thanks.
Here is the final code...

///
package org.sandbox.camunda;

import java.io.File;
import org.junit.Test;

import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.instance.Process;
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.SequenceFlow;
import org.camunda.bpm.model.bpmn.instance.StartEvent;
import org.camunda.bpm.model.bpmn.instance.UserTask;


public class ProcessGen {

void genSimpleProcess() {

// 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,
"generated-process", 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("User Task");

EndEvent endEvent = createElement(modelInstance, process, "end",
EndEvent.class);

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

// validate and write model to file
Bpmn.validateModel(modelInstance);
File file;
file = new File("generated-process.bpmn");
Bpmn.writeModelToFile(file, modelInstance);

}

protected <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;
}

protected 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;
}

@Test
public void testProcessGen() {

ProcessGen p = new ProcessGen();
p.genSimpleProcess();
// assert true;

}

}
///
Em segunda-feira, 18 de agosto de 2014 06h38min34s UTC-3, Sebastian Menski escreveu:
> Hi,
>
>
> is this your complete code or did you simplify it? Cause there are some bugs in it why it would not be compileable.
>
>
> First you miss the import 
>
>
> import org.camunda.bpm.model.bpmn.instance.Process;other wise you will use the java.lang.Process class.
>
> Second your code you handle or pass the possible IOException of File.createTempFile method.
>
>
> Third in the createElement method you use the variable
>
>
> modelInstancewhich is not defined in this scope. Either you pass it in with the method call
Reply all
Reply to author
Forward
0 new messages