Starting a activiti process outside activiti explorer and completing it inside activiti explorer

2.1k views Asked by At

Im relatively new to activiti I was wondering is there any way to deploy or even start a process in activiti explorer using just java code i.e. run a java application to create a task for kermit and then log in to activiti explorer and complete it..

2

There are 2 answers

0
Ben On

Sure, this is possible via the Activiti REST API and via the Activiti Java APIs.

If you want to start processes inside your own java application, you can setup a java maven project and import the necessary Activiti APIs (http://activiti.org/community.html)

The Activiti Explorer contains its own Activiti Process Engine instance. Your application would also have its own instance. It is a common approach that both applications share the same database (e.g. MySQL)

Look at this picture taken from the Book "Activiti in Action":

enter image description here

For the Activiti Java API, look at the Activiti Java Guide:http://activiti.org/javadocs/

To start a process, you can use the RuntimeService like this:

ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault()
.buildProcessEngine();

RuntimeService runtimeService = processEngine.getRuntimeService();

ProcessInstance processInstance = 
runtimeService.startProcessInstanceByKey("processId");

Lets assume you defined the first Task as UserTask with kermit as assignee. After your java code was executed, Kermit can login into the Activiti Explorer and he will see his task. To achieve this, both applications must share the same database.

The deployment of process-definitions is possible, too. Look at the RepositoryService.

0
Shailendra On

As very well explained by @Ben the key to interaction with the process engine is usually the decision whether the process engine is bootstrapped in the same process as your application or it is already running inside another web application which has provided REST API (activiti-rest web application) or another web application which may not provide direct REST API but can be used to perform many workflow related tasks through UI (Activiti explorer web application probably does the interaction using direct activiti java API). This way Activiti is quite flexible.