I am having issues integrating Camunda BPMN with springboot, I created file containing the Camunda engine configuration
@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() {
SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
log.info("--------------------SpringProcessEngineConfiguration ");
config.setDataSource(datasource);
PlatformTransactionManager platformTransactionManager=new JpaTransactionManager(entityManagerFactory);
config.setTransactionManager(platformTransactionManager);
config.setDatabaseSchemaUpdate("true");
config.setHistory("audit");
config.setJobExecutorActivate(true);
config.setApplicationContext(applicationContext);
return config;
}
@Bean
public ProcessEngineFactoryBean processEngine() {
log.info("--------------------processEngine ");
ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
factoryBean.setApplicationContext(applicationContext);
return factoryBean;
}
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine) {
log.info("--------------------repositoryService ");
return processEngine.getRepositoryService();
}
@Bean
public RuntimeService runtimeService(ProcessEngine processEngine) {
log.info("--------------------runtimeService ");
return processEngine.getRuntimeService();
}
@Bean
public TaskService taskService(ProcessEngine processEngine) {
log.info("-------------------- taskService ");
return processEngine.getTaskService();
}
I did succeed to deploy the process, I guess: I found 2 tables only with data, ACT_RE_DEPLOYMENT
and ACT_GE_BYTEARRAY
.
However, I am always getting error while trying to start an instance from any process deployed .
ProcessEngine processEngine = restProcessEngineProvider.getDefaultProcessEngine();
log.info("processEngine {} ",processEngine.getName());
RuntimeService runtimeService = processEngine.getRuntimeService();
log.info("runtimeService");
RepositoryService repositoryService = processEngine.getRepositoryService();
log.info("repositoryService");
InputStream stream = new ByteArrayInputStream(process.getLastXmlDefinition().getBytes(Charset.defaultCharset()));
DeploymentEntity deploymentResult;
try {
deploymentResult = (DeploymentEntity) repositoryService.createDeployment()
.name(name)
.addInputStream(name, stream).deploy();
List<ProcessDefinition> processes= deploymentResult.getDeployedProcessDefinitions();
if (processes!=null)
{
log.info("process not null {} ",processes.size());
}
else
{
log.info("process null");
}
} finally {
stream.close();
}
//read the result
String deploymentId = deploymentResult.getId();
log.info("deployement id {} ",deploymentId);
ProcessDefinition processDef = repositoryService.createProcessDefinitionQuery()
.processDefinitionName(name)
.singleResult();
log.info("process def ...");
//return the process definition id for later query
String processDefinitionId="";
if (processDef!=null)
{
if (processDef.getId()!=null)
processDefinitionId = processDef.getId();
else
log.info("process def id is null");
}
else
{
log.info("process def null ");
}
log.info("deployed success {} ",processDefinitionId);
runtimeService.startProcessInstanceByKey(name);
always getting null process def org.camunda.bpm.engine.exception.NullValueException: no processes deployed with key ...
I found a way to answer my own question and I thought I should post it here
String fileXML=""; // set here process xml
ProcessEngine processEngine = restProcessEngineProvider.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
InputStream stream = new ByteArrayInputStream(fileXML);
DeploymentEntity deploymentResult;
String deploiementBuild = name + "deploiement";
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name(deploiementBuild);
String definitionName = name + ".bpmn";
deploymentBuilder.addInputStream(definitionName, stream);
String deploymentId = deploymentBuilder.deploy().getId();
log.info("depoiement -------------> {}", deploymentId);
List definitions = repositoryService.createProcessDefinitionQuery().list();
log.info("depoiement size ------------> {} ",definitions.size());