cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatic process definition and deployment (without xml)

hieu_ho
Champ in-the-making
Champ in-the-making
Hi everyone

I'm new to Activiti and wanted to see if it will work for a project we're migrating.

I couldn't find a good example of creating a processDefinition and deploying it programatically.  I took point from ProcessDefinitionsTest, and a few others, but they seem to be deploying a process by reading from an existing xml resource or from a process string. (ie. DeploymentBuilder.addClasspathResource and addString)

I have a requirement where I am reading from external sources (ie. lists from db and flat files).  I want to avoid having to preprocess and convert them all to bpmn xml files.  I have List objects created from them, and would like to see if I can create a process definition from it, using something similar to the following


ProcessDefinitionBuilder processDefinitionBuilder = new ProcessDefinitionBuilder(someName);

processDefinitionBuilder = processDefinitionBuilder.createActivity(top.getName())
                                                               .initial()
                                                               .behavior(new BaseServiceTaskHandler("start node"))
                                                               .transition(startName)
                                                               .endActivity();

for (int i = 0; i < myChecklist.size(); i++) {
                    if(i<myChecklist.size() - 1) {
                        processDefinitionBuilder = processDefinitionBuilder.createActivity(myChecklist.get(i).getName())
                                                             .behavior(new ReminderActivityHandler())
                                                             .transition(myChecklist.get(i + 1).getName())
                                                             .endActivity();
                    } else {
                        processDefinitionBuilder = processDefinitionBuilder.createActivity(top.getRoutine().get(i).getName())
                                                             .endActivity();
                    }
                }

PvmProcessDefinition processDefinition = processDefinitionBuilder.buildProcessDefinition();


How do I deploy this now?  Would this be the best way to do this?  Is there an example you can point me to?

Thanks
12 REPLIES 12

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
That is at least 'guaranteed' to be stable 🙂

vincentbonnet
Champ in-the-making
Champ in-the-making
Is it a joke… /:/   to generate xml from my object/PvmProcessDefinition  then re-import  in the ProcessEngine via stream resource reading ?
PvmProcessDefinition should not be the centric language/model/template of work of the process engine ?

heymjo
Champ on-the-rise
Champ on-the-rise
I had a need for this and since 5.9 (thanks to http://jira.codehaus.org/browse/ACT-831)  you can generate and execute a subprocess dynamically.

- your base (non dynamic) processdefinition should have a callActivity with a variable as calledElement

<callActivity id="callCheckCreditProcess" name="Check credit" calledElement="${dynamicProcess}" />
- just before this callactivity you put a service task to generate and deploy the processdefinition

  String processXml = generateMyProcessDefinitionXml();
  String processId = …. ; // the process id referenced in processXml
  DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment().name(..);
  // make sure that the name ends with .bpmn20.xml otherwise it won't deploy
  deploymentBuilder.addString("dynamicprocess.bpmn20.xml",processXml);     
  deploymentBuilder.deploy();
  execution.setVariable("dynamicProcess", processId);
- then when the callActivity kicks in it will lookup the newly deployed process and execute it