General steps for activiti workflows: activiti workflow steps

Source: Internet
Author: User

General steps for activiti workflows: activiti workflow steps

General steps for activiti Workflow

1. Install the activiti plug-in eclipse or Myeclipse;

2. Connect to the database through activiti in the following two forms:

1. link the database through java code:

public void createTableByOracle(){ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();configuration.setJdbcUrl("jdbc:oracle:thin:@");configuration.setJdbcDriver("oracle.jdbc.OracleDriver");configuration.setJdbcUsername("scott");configuration.setJdbcPassword("oracle");configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);ProcessEngine processEngine = configuration.buildProcessEngine();System.out.println("-------------------------------------");System.out.println(processEngine);}

2. Connect to the database through configuration file configuration

(1) configuration file:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="" xmlns:xsi=""  xmlns:context="" xmlns:tx=""  xmlns:jee="" xmlns:aop=""  xsi:schemaLocation="">       <bean id="dataSource"class="org.springframework.jdbc.datasource.SimpleDriverDataSource"><property name="driverClass" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql://" /><property name="username" value="root" /><property name="password" value="123456" /></bean> <bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"><property name="dataSource" ref="dataSource" /><property name="transactionManager" ref="transactionManager" /><property name="databaseSchemaUpdate" value="true" /></bean>  </beans>

(2) the java code reads the configuration file and links it to the database:

public void createTableByXML(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();}

3. Create a bpmn file for the workflow:

4. Deploy bpmn and png workflow file resources: (Note: One workflow can be deployed once. You only need to start one Workflow later)

Public void deployTest () {System. out. println ("start to deploy an approval process"); ProcessEngine processEngine = ProcessEngines. getdefaprocesprocessengine (); Deployment deployment = processEngine. getRepositoryService (). createDeployment (). name ("road expense reimbursement Approval Process "). addClasspathResource ("choiceProcess. bpmn "). addClasspathResource ("choiceProcess.png "). deploy (); System. out. println ("deployment process completed ");}

5. Start a process:

Public void StartProcess () {System. out. println ("start an approval process"); ProcessEngine processEngine = ProcessEngines. getdefaprocesprocessengine (); ProcessInstance processInstance = processEngine. getRuntimeService (). startProcessInstanceByKey ("luFeiBaoXiaoShenPi"); System. out. println (processInstance. getId () + "--------" + processInstance. getActivityId (); System. out. println ("starting process completed ");}

6. view the list of tasks to be completed by a person:

Public void queryProcess () {ProcessEngine processEngine = ProcessEngines. getdefaprocesprocessengine (); String assignee0 = "lsy"; List <Task> zhangSanList = processEngine. getTaskService (). createTaskQuery (). taskAssignee (assignee0 ). orderByTaskCreateTime (). asc (). list (); System. out. println ("****************" + assignee0 + "personal task list ************* **********"); for (Task task: zhangSanList) {System. out. println ("id:" + task. getId () + ", name:" + task. getName () + ", Creation Time" + task. getCreateTime () + ", character:" + task. getAssignee ());}}

7. A person completes a specific task:

1. Without variables:

Public void completeTask () {ProcessEngine processEngine = ProcessEngines. getdefaprocesprocessengine (); processEngine. getTaskService (). complete ("235009"); System. out. println ("finished task ");}

2. variables:

Public void completeTaskByVariables () {ProcessEngine processEngine = ProcessEngines. getdefaprocesprocessengine (); Map <String, Object> variables = new HashMap <String, Object> (); variables. put ("money", 501); processEngine. getTaskService (). complete ("265004", variables); System. out. println ("finished task ");}

8. A person can view the list of completed tasks:

public void queryHistoryTask(){ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();List<HistoricTaskInstance> historicList = processEngine.getHistoryService().createHistoricTaskInstanceQuery().taskAssignee("lsy").list();for (HistoricTaskInstance historicTaskInstance : historicList) {System.out.println(historicTaskInstance.getId()+":"+historicTaskInstance.getProcessDefinitionId()+":"+historicTaskInstance.getAssignee()+":"+historicTaskInstance.getExecutionId()+":"+historicTaskInstance.getStartTime()+":"+historicTaskInstance.getEndTime()+":"+historicTaskInstance.getDurationInMillis());}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.