简体   繁体   中英

Deploying dynamically created BPMN model using Activiti REST API

I am new to Activiti. I am working on a project in which i should be able to create process dynamically using spring mvc. I have come acrossed http://stacktrace.be/blog/2013/03/dynamic-process-creation-and-deployment-in-100-lines/

Is it possible to deploy the dynamically created process using REST API directly or we should create bpmn-20.xml and deploy it. Also is there any example for creating complex process such as using boundary events dynamically.

Thanks

It is possible through this endpoint /activiti-rest/service/deployment ! Please check this forum thread for further infos + sample code.

You do not have to really create the file on your disk, just simulate it with an InputStream of some sort:

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("deployment", new ByteArrayInputStream((<put-something-here>).toByteArray()), ContentType.DEFAULT_BINARY,"test.bpmn20.xml")

Here is the code for uploading .bpmn file content as string and starting the process at the same time:

@Autowired
private RuntimeService runtimeService;

@PostMapping("/deployAndStartProcess")
public void deployAndStartProcess(@RequestBody DeployWorkflow dw, @RequestParam(required = false) HashMap<String, Object> variables) {
  String processXml = dw.getBpmnFile();
  String processId = dw.getProcessKey();
  ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
  DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment().name(processId);
  deploymentBuilder.addString(processId + ".bpmn", processXml);
  deploymentBuilder.deploy();
  runtimeService.startProcessInstanceByKey(processId, variables);
}

Reference: Look at heymjo's answer in the last

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM