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:@192.168.1.150:1521:orcl");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="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <bean id="dataSource"class="org.springframework.jdbc.datasource.SimpleDriverDataSource"><property name="driverClass" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql://192.168.1.150:3306/officemanage?characterEncoding=utf8" /><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());}}