Activiti Integrated Development Example Summary

Source: Internet
Author: User
Tags addall

Reference manual: http://www.mossle.com/docs/activiti/

I. XML file introducing Activiti-related configuration in Applicationcontext.xml

<!--begin: Workflow-related configuration start-to-    <import resource= "classpath:com/future/sem/resource/activiti/config/ Activiti-core-context.xml "/><!--end: Workflow-related configuration ended--

Second, Activiti-core-context.xml

<?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 "default-lazy-init=" true "> <! --Configure Process Engine Definition--<bean id= "processengineconfiguration" class= " Org.activiti.spring.SpringProcessEngineConfiguration "> <!--Spring XML is already configured--
     <property name= "DataSource" ref= "DataSource"/> <property name= "TransactionManager" ref= "Txmanager"/> <!--processing policy on database table structure when workflow engine starts and shuts down false (default), True,create,create-drop---<property name= " Databaseschemaupdate "value=" true "/> <!--the component of the thread that activates the timer and asynchronous messages True (default), False--<property name=" Jobexecutoractivate "value=" false "/> <property name=" enabledatabaseeventlogging "value=" true "/> <proper Ty name= "History" value= "full"/> <property name= "databasetype" value= "Oracle"/> <property name= "Activityf Ontname "value=" Microsoft Ya Black "/><property name=" Labelfontname "value=" Microsoft Ya Black "/><!--automatic deployment, each reboot will be reloaded-->< Property Name= "Deploymentresources" value= "CLASSPATH*:/COM/FUTURE/SEM/RESOURCE/ACTIVITI/DIAGRAMS/*.BPMN"/> </bean> <bean id= "Processengine" class= "Org.activiti.spring.ProcessEngineFactoryBean" destroy-method= " Destroy "> <property name=" processengineconfiguration "ref=" ProcessenginEConfiguration "/> </bean> <!--create various services provided by Activiti-<bean id=" Repositoryservice "factory-bean=" PR Ocessengine "factory-method=" Getrepositoryservice "/> <bean id=" Runtimeservice "factory-bean=" ProcessEngine " factory-method= "Getruntimeservice"/> <bean id= "Taskservice" factory-bean= "Processengine" factory-method= " Gettaskservice "/> <bean id=" Formservice "factory-bean=" Processengine "factory-method=" GetFormService "/> <bean id= "Historyservice" factory-bean= "Processengine" factory-method= "Gethistoryservice"/> <bean id= " Managementservice "factory-bean=" Processengine "factory-method=" Getmanagementservice "/> <bean id=" Identityservice "factory-bean=" Processengine "factory-method=" Getidentityservice "/> </beans>

Iii. *.BPMN Process-related documents

Use Elipse to add process-related plugins

Plugin Address: http://activiti.org/designer/update/


Activiti requires a third-party dependency library: Graphiti
Address: http://download.eclipse.org/graphiti/updates/0.9.0

Example diagram:

Installation Diagram Description:

Iv. Main Service Code

Repositoryservice: Provides methods for obtaining information about various processes and deployment files.

Taskservice: Provides various actions related to the task

Identityservice: Manage users and user groups.

Formservice: Gets or binds data to the process instance

Runtimeservice: Provides methods for manipulating deployment files, process files, and process instances.

Managementservice: Provides administrator monitoring of the process engine, regardless of the process Engine service application.

Historyservice: Provides various process instance information that is being executed and executed in the past

Processengine processengine = Processengines.getdefaultprocessengine ();  Runtimeservice Runtimeservice = Processengine.getruntimeservice ();  Repositoryservice Repositoryservice = Processengine.getrepositoryservice ();  Taskservice Taskservice = Processengine.gettaskservice ();  Managementservice Managementservice = Processengine.getmanagementservice ();  Identityservice Identityservice = Processengine.getidentityservice ();  Historyservice Historyservice = Processengine.gethistoryservice ();  Formservice Formservice = Processengine.getformservice ();  

Examples of specific service classes in the project:

Package Com.future.sem.common.activiti.service;import Java.text.simpledateformat;import java.util.ArrayList; Import Java.util.date;import java.util.list;import Java.util.map;import Java.util.resourcebundle;import Javax.annotation.resource;import Org.activiti.engine.formservice;import Org.activiti.engine.HistoryService; Import Org.activiti.engine.identityservice;import Org.activiti.engine.managementservice;import Org.activiti.engine.repositoryservice;import Org.activiti.engine.runtimeservice;import Org.activiti.engine.taskservice;import Org.activiti.engine.history.historicprocessinstance;import Org.activiti.engine.identity.group;import Org.activiti.engine.identity.user;import Org.activiti.engine.repository.deployment;import Org.activiti.engine.repository.processdefinition;import Org.activiti.engine.runtime.processinstance;import Org.activiti.engine.task.task;import Org.apache.commons.lang3.stringutils;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import Org.springframework.stereoType. Service;import Org.springframework.transaction.annotation.transactional;import Com.future.sem.common.util.ResourceUtil, @Service ("Activiticoreservice") @Transactionalpublic class Activiticoreservice {/** * print log */private static Logger Logger = Loggerfactory.getlogger (activiticoreservice.class); @ Resourceprivate repositoryservice repositoryservice, @Resourceprivate runtimeservice runtimeservice;@ Resourceprivate taskservice taskservice, @Resourceprivate formservice formservice; @Resourceprivate historyservice Historyservice, @Resourceprivate managementservice managementservice; @Resourceprivate identityservice identityservice;//public static final String Processdefinitionid = "myprocess";  Process id/** * Get the process ID configured in the resource file * * @return Process ID * @ description process naming rules */public string Getprocessdefid (String groupId) {ResourceBundle RB = Resourceutil.getbundle ("Sem_system_config");//Read the sem_system_config.properties file under the SRC root, call the unused process string key = " Com.future.sem.activiti.process. "+ groupid+" Processdefinitionid "; reTurn rb.getstring (key);} /** * Method: Deployment Process * * @title: Deploymentactiviti * @param * @return void */public void Deploymentactiviti (String path) {//RE Positoryservice.createdeployment (). Addclasspathresource (path). deploy ();////Simple deployment process// Repositoryservice.deletedeployment ("Depolyid"); Delete process//Repositoryservice.createdeploymentquery (). List ();//query process try {simpledateformat SDF = new SimpleDateFormat (" Yyyymmddhhmmss ");D eployment dep = repositoryservice.createdeployment (). Category (" Personnel review process "). Name (Sdf.format (New Date ()) + "Test Flow"). Addclasspathresource (path). deploy (); Logger.debug ("\n\t file: {} deployment succeeded!\n\t name: {}\n\tid:{}\n\t deployment time: {}\n\ T category: {} ", new object[] {path,dep.getname (), Dep.getid (), New SimpleDateFormat (" Yyyy-mm-dd HH:mm:ss:SSS "). Format ( Dep.getdeploymenttime ()), Dep.getcategory ()}), Logger.debug ("\n\t>>>> currently deployed process {}!", new object[] { Repositoryservice.createdeploymentquery (). Count ()});} catch (Exception e) {logger.error ("process deployment Failed");}} /** * Method: Start the process * * @title: Startprocessinstancebykey * @param * @return processinstance */public processinstance startprocessinstancebykey (String businesskey,string userId, Map< String, object> varsmap,string processdefinitionid) {processinstance pi = null;try { Identityservice.setauthenticateduserid (userId);//The person who set the START process idpi = Runtimeservice.startprocessinstancebykey ( Processdefinitionid,businesskey, Varsmap); Logger.info ("\n\tnumber of Process instances:" + Runtimeservice.createprocessinstancequery (). Count () + "\n\tprocessid:" + pi.getid () + "\n\tbusinesskey:" + Pi.getbusinesskey () + "\n\tprocessdefinitionid:" + pi.getprocessdefinitionid () + "\n\tprocessinstanceid:" + Pi.getprocessinstanceid () + "\n\tsuspend:" + pi.issuspended ()); catch (Exception e) {e.printstacktrace ();} return pi;} /** * Method: Process Task List for role * * @title: Findtaskbyprocessid * @param * @return list<task> */public list<task> findtask Bygroupname (String groupname) {list<task> list = null;try {list = Taskservice.createtaskquery (). Taskcandidategroup (groupname). List (); for (Task tAsk:list) {String a = Task.getassignee (); Logger.info ("task========:" + task.getname () + "------------" + Task.getid ());} } catch (Exception e) {e.printstacktrace ();} return list;} /** * Method assigns a task to a specified person * @title: Claimtask * @param * @return void */public void Claimtask (Task task, String username) {Try {//Claim itif (Stringutils.isblank (Task.getassignee ())) {Taskservice.claim (Task.getid (), username);}} catch (Exception e) {e.printstacktrace ();}}  /** * Method: Task Recipient * * @title: Setassignee * @param * @return void */public void Setassignee (String taskid, string username) {try {Taskservice.setassignee (TaskID, username);} catch (Exception e) {e.printstacktrace ();}} /** * Method: Get Task * * @title: Getcurrenttaskbyuserid * @param * @return Task */public Task Getcurrenttaskbyuserid (String use RID) {Task task = null;try {list<task> refusetasklist = Taskservice.createtaskquery (). Taskassignee (UserId). Active (). Orderbytaskpriority (). Desc (). Orderbytaskcreatetime (). DESC (). list (); catch (Exception e) {E.PRIntstacktrace ();} return task;} /** * Method: Get the current active task * * @title: Getcurrentactivetaskbypid * @param * @return Task */public Task Getcurrentactivetaskbypid (String Processinstanceid) {Task task = null;try {task = Taskservice.createtaskquery (). Processinstanceid (Processinstanceid). Active (). Singleresult ();} catch (Exception e) {e.printstacktrace ();} return task;} /** * Method: Complete the current task * * @title: Completetask * @param * @return void */public void Completetask (String taskid, Map<strin G, object> Varsmap) {try {taskservice.complete (TaskID, Varsmap);} catch (Exception e) {e.printstacktrace ();}} /** * Method: View Agent list according to User ID * * @title: Findundotask * @param * @return list */public list Findundotask (string userId, String Processdefinitionid) {//Sign up for unfinished tasks list<task> todolist = Taskservice.createtaskquery (). Processdefinitionkey ( Processdefinitionid). Taskassignee (userId). Active (). Orderbytaskpriority (). Desc (). Orderbytaskcreatetime (). DESC () . List (); Logger.info ("\ n User" + UserId + "sign unfinished task:" + todolist.siZe () + "A."); /non-signed task list<task> unsignedtasks = Taskservice.createtaskquery (). Processdefinitionkey (ProcessDefinitionId). Taskcandidateuser (userId). Active (). Orderbytaskpriority (). Desc (). Orderbytaskcreatetime (). DESC (). list (); Logger.info ("\ n User" + UserId + "non-signed task:" + unsignedtasks.size () + "each"); list<task> alllist = new arraylist<task> (); Alllist.addall (todolist); Alllist.addall (unsignedTasks); return alllist;} /** * Method: The user has already published the process (the user created the end of the process) * * @title: Findpublishedoffinishedtasklist * @param * @return list */public list find Publishedoffinishedtasklist (String userId) {list

V. Method of Invocation

Get the process ID, start a different process string processdefid = Activiticoreservice.getprocessdefid (groupId); ProcessInstance pi = Activiticoreservice.startprocessinstancebykey (Businesskey, Userid,varsmap, processDefId);
/View current task Node task = Activiticoreservice.getcurrentactivetaskbypid (Person.getprocessinstanceid ());
Assign Task Activiticoreservice.claimtask (task, userId);

  

  

  

  

 

Activiti Integrated Development Example Summary

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: info-contact@alibabacloud.com 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.