cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically Create Activiti Pool, Lane using java code

smadhu
Champ in-the-making
Champ in-the-making
Hi,

    I have tried to create and add Pool and Lane to a model within a sample activiti java program. Can anybody help on how to programmatically create Pool and Lane using java code.

thanks

Sud
5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
You mean using the BpmnModel approach? or something else?

smadhu
Champ in-the-making
Champ in-the-making
Yes. I wrote a sample java class with the BpmnModel, and tried adding a Pool and then also a lane. But it just fails at the last line of the following code with a message error creating XML. 

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
BpmnModel model = new BpmnModel();
Process process = new Process();
model.addProcess(process);
process.setId(processName);

// Progammatically creating lanes seems an issue , commented to make the code compile and run
//Lane tempLane = new Lane();
//Pool tempPool = new Pool();
//tempLane.setParentProcess(process);
//process.getLanes().add(tempLane);

process.addFlowElement(createStartEvent();
process.addFlowElement(createUserTask();
process.addFlowElement(createEndEvent());
RepositoryService repositoryService = processEngine.getRepositoryService();
RuntimeService runtimeService = processEngine.getRuntimeService();
Deployment deployment = repositoryService.createDeployment().addBpmnModel(bpmnModelName, model).name(description).deploy();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processName);  
//Fails on the below line with a message error creating XML
InputStream processDiagram = processEngine.getRepositoryService().getProcessDiagram(processInstance.getProcessDefinitionId());
FileUtils.copyInputStreamToFile(processDiagram, new File(diagramFileName));

trademak
Star Contributor
Star Contributor
Hi,

The pool should have a reference to the process identifier with the setProcessRef method.
And you should add the pool to the BpmnModel.
Finally the process instance id should be the same as the pool process reference.

Best regards,

smadhu
Champ in-the-making
Champ in-the-making
Hi,

     I will try your suggestion and get back to you. Can you also suggest is it possible to display labels on SequenceFlow. I tried adding in the setName(), though it gets generated and Iam able to see the same in the XML, but the label does not display on the generated PNG diagram.

But when I try to add a Name to a SequenceFlow from the Activiti Designer, it appears in the diagram. Perfect. Why does it not display the label when it is set from java code. Whats the difference ? and can you please guide me ?

jbarrez
Star Contributor
Star Contributor
> but the label does not display on the generated PNG diagram.

No, it doesn't do that yet.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.