Programmatic process definition and deployment (without xml)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2011 12:41 PM
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
- Labels:
-
Archive

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2011 12:26 PM
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.setVariable("userId", "myTest");
processInstance.start();
To test it, I went ahead and looked up the activities that I ended up with. I got the expected activity.
List activeIds = processInstance.findActiveActivityIds();
Assert.assertNotNull(activeIds);
PvmActivity activity = processInstance.getActivity();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2011 01:47 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2011 01:19 PM
can you clarify what you mean by not public? I took these examples from PvmTest and ProcessDefinitionTest in the examples project. Do you mean these methods are not part of services api? Are there "public" ones I should be using?
Thanks
Hieu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2011 05:40 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2011 06:21 AM
Here is the source code I'm writing, the assertion at the bottom of the code fails, since no tasks are being found:
@Test
public void createProcessDefinition() {
ProcessDefinitionBuilder processDefinitionBuilder = new ProcessDefinitionBuilder();
//a map with tasks descriptions
List<Map<String, String>> activities = new ArrayList<Map<String, String>>();
Map<String, String> activity;
activity = new HashMap<String, String>();
activity.put("id", "UT1");
activity.put("name", "User task 1");
activities.add(activity);
activity = new HashMap<String, String>();
activity.put("id", "UT2");
activity.put("name", "User task 2");
activities.add(activity);
activity = new HashMap<String, String>();
activity.put("id", "UT3");
activity.put("name", "User task 3");
activities.add(activity);
// creating process definition
int len = activities.size();
for (int i = 0; i < len; i++) {
processDefinitionBuilder.createActivity(activities.get(i).get("id"));
if (i == 0) {
processDefinitionBuilder.initial();
}
processDefinitionBuilder.behavior(new ActivitiWaitState());
if (i + 1 < len) {
processDefinitionBuilder.transition(activities.get(i+1).get("id"));
}
}
PvmProcessDefinition processDefinition = processDefinitionBuilder.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
TaskQuery taskQuery = activitiTaskService.createTaskQuery();
List<Task> tasks = taskQuery.list();
Assert.assertTrue(tasks.size() > 0);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2011 03:45 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2011 04:44 PM
I tried creating the xml file in java and then deploying it from String in memory, everything works fine

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2011 02:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2011 02:12 AM

