Process Definition Deployment via API

Hello,

I’m trying to deploy a process definition from a file using the following code

DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name(definitionName);
deploymentBuilder.addInputStream(definitionName, definitionFileInputStream);
String deploymentId = deploymentBuilder.deploy().getId();
System.out.println(deploymentId);

The above code runs successfully and the new deploymentId is printed out.

Later, I tried to list the deployed process definitions using the following code

List definitions = repositoryService.createProcessDefinitionQuery().list();
System.out.println(definitions.size());

The above code runs successfully but the output is always 0.

I’ve done some investigations and found that in the ACT_GE_BYTEARRAY table an entry with the corresponding deploymentId exists and the BYTES_ column contains that contents of the definitions file.

I have also found that there is no corresponding entry found in ACT_RE_PROCDEF table.

Is there something messing? from the API and the examples I found it seems that the above code shall suffice, or is there a missing step?

Thanks for your help

admin edit: crosspost of https://stackoverflow.com/questions/44518759/camunda-process-definition-deployment-via-api

Hi,

Make sure that definitionName ends on either .bpmn20.xml or .bpmn. Only then will the process engine interpret a deployment resource as a BPMN process definition.

Cheers,
Thorben

Thanks @thorben ! that did solve the issue.

After further testing, the suffix is required for the following definitionName of the code
deploymentBuilder.addInputStream(definitionName, definitionFileInputStream);

Leaving the following definitionName without the suffix is fine
repositoryService.createDeployment().name(definitionName);

Exactly. Please update your stackoverflow question as well, then others can benefit from it.

Hi
I have the same issue as tariqd described. I have a bpmn file called “Review_Camunda.bpmn”
and I copied the above code:

DeploymentBuilder deploymentBuilder = repositoryService.createDeployment()
.name(“Review_Camunda”)
.enableDuplicateFiltering(false)
;
deploymentBuilder.addInputStream(“Review_Camunda.bpmn”, new FileInputStream(bpmnFile));
String deploymentId = deploymentBuilder.deploy().getId();
System.out.println(deploymentId);

The code runs without error, it returns a valid deploymentID, but there are no entries in the above mentioned tables.
ACT_GE_BYTEARRAY, ACT_RE_PROCDEF

When I try to read a processInstance via

ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(“Review_Camunda”);

I get an error

org.camunda.bpm.engine.exception.NullValueException: no processes deployed with key ‘Review_Camunda’: processDefinition is null

What is wrong in my code?
Cheers, Roland

Hi Roland,

Is your process marked as executable, as described in the following post?

Cheers,
Thorben

Hi Thorben
yes, it is marked as executable (as you can also see in the screenshot of the bpmn file)
Cheers, Roland

Can you post the application log for the time at which you make the deployment?

A post was split to a new topic: REST API deployment question

Hi Thorben

where can I find the Camunda log file? Currently I use an embedded engine that is locally started via Spring Boot and Eclipse.

In the meantime I was succesful:

  • I created another BPMN file “Review.bpmn” with the Camunda Modeler and put the BPMN file into the ./diagrams folder of my Spring Boot project. When I start the application, everything works fine, the process will automatically be started during bootstrapping.

  • Than I stopped my application and moved the “Review.bpmn” file from the ./diagram folder to another folder.

  • Afterwards I re-started my application and picked the file during runtime via upload functionality of my UI. This functionality executes the above mentioned code. In this scenario I use

String fileName = convFile.getName();
DeploymentWithDefinitions d = repositoryService.createDeployment()
.addInputStream(“Review.bpmn”,new FileInputStream(convFile))
.name(“Review.bpmn”)
.deployWithResult();
System.out.println(d.getId());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(“Review”);

Now it works, strange! The entries in the DB are there and the process is started.

The differences to the former scenarios are:

  • The name of the BPMN file (and the processKey) changed from “Review_Camunda” to “Review”

  • I used “deployWithResult()” instead of “deploymentBuilder.deploy()”

Cheers Roland

Can we not deploy only from string, Please see following code:

public void deployResource() {
   BpmnModelInstance modelInstance = Bpmn.createProcess()
       .name("Example process")
       .executable()
     .startEvent()
     .userTask()
       .name("Some work to do")
     .endEvent()
     .done();
   ProcessEngines.getDefaultProcessEngine().getRepositoryService().createDeployment()
   .addModelInstance("test.bpmn", modelInstance).deploy();
 }