"Application" Activiti the simple application of the combination of listening and business particles (III.) __ Workflow

Source: Internet
Author: User
Tags cdata

Activiti simple application, the application of monitoring to achieve a simple business particles and workflow integration, so that the process driven business particles to carry out the process, the flow chart of the application of multiple branches, and the process of judgment value set as parameters, from the foreground pass past.

New normal Java class:

Package Com.tgb.itoo.activiti.controller;

public class XS {public

	static void SayHello () {
		System.out.println ("88xvshu");
	}
	
	

New Activiti Listener class:

Package Com.tgb.itoo.activiti.controller;

Import Org.activiti.engine.delegate.DelegateTask;
Import Org.activiti.engine.delegate.TaskListener;

public class Xvshudelegate implements tasklistener{
	/**
	 * */
	private static final long Serialversionuid = 1L;

	@Override public
	void Notify (Delegatetask delegatetask) {		
		xs. SayHello ();
	}
		

Similar Java classes and listening classes need to create 3 more

Business flow chart as shown:


The process variable's property setting (Jingyuan-${result==flowjingyuan},milaoshi-${result==flowmilaoshi}) is shown in the figure:



The resulting configuration file is as follows:

<?xml version= "1.0" encoding= "UTF-8"?> <definitions xmlns= "Http://www.omg.org/spec/BPMN/20100524/MODEL" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "Http://www.w3.org/2001/XMLSchema" xmlns: Activiti= "HTTP://ACTIVITI.ORG/BPMN" xmlns:bpmndi= "Http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc= "http://" Www.omg.org/spec/DD/20100524/DC "xmlns:omgdi=" Http://www.omg.org/spec/DD/20100524/DI "typelanguage=" http:// Www.w3.org/2001/XMLSchema "expressionlanguage=" Http://www.w3.org/1999/XPath "targetnamespace=" http:// Www.activiti.org/test "> <process id=" myprocess "name=" My Process "isexecutable=" true "> <startevent id=" s Tartevent1 "Name=" "Start" ></startEvent> <usertask id= "Xvshu" name= "Xvshu" > &LT;EXTENSIONELEMENTS&G
        T <activiti:tasklistener event= "Create" class= "Com.tgb.itoo.activiti.controller.xvshuDelegate" ></activiti :tasklistener> </extensionElements> </userTask> <sequenceflow ID= "Flow1" sourceref= "Startevent1" targetref= "Xvshu" "></sequenceFlow> <usertask id=" Jingyuan "Name=" Jingyuan "> <extensionElements> <activiti:tasklistener event=" Create "class=" Com.tgb.itoo.activit
    I.controller.jingyuandelegate "></activiti:taskListener> </extensionElements> </userTask> <usertask id= "Usertask1" name= "Guhaiyan" > <extensionElements> <activiti:tasklistener event= "Create" class= "Com.tgb.itoo.activiti.controller.guhaiyanDelegate" ></activiti:taskListener> </ extensionelements> </userTask> <endevent id= "endevent1" name= "End" ></endEvent> <sequen Ceflow id= "flow4" sourceref= "Usertask1" targetref= "endevent1" ></sequenceFlow> <exclusivegateway "id=" Exclusivegateway1 "Name=" Exclusive Gateway "></exclusiveGateway> <sequenceflow id=" flow5 "sourceref=" Xvshu "targetref=" Exclusivegateway1 "></sequenceflow> <sequenceflow id= "flow6" name= "Jingyuan" sourceref= "Exclusivegateway1" targetref= "Jingyuan" > <c Onditionexpression xsi:type= "Tformalexpression" ><! [cdata[${result==flowjingyuan}]]></conditionexpression> </sequenceFlow> <usertask id= "Usertask2 "Name=" Guhaiyan "> <extensionElements> <activiti:tasklistener event=" Create "class=" Com.tgb.itoo . activiti.controller.guhaiyanDelegate "></activiti:taskListener> </extensionElements> </usertas k> <sequenceflow id= "flow13" name= "Guhaiyan" sourceref= "Exclusivegateway1" targetref= "Usertask2" > <c Onditionexpression xsi:type= "Tformalexpression" ><! [cdata[${result==flowhaiyan}]]></conditionexpression> </sequenceFlow> <usertask id= "Milaoshi" NA Me= "Milaoshi" activiti:async= "true" > <extensionElements> <activiti:tasklistener event= "Create" C Lass= "Com.tgb.itoo.activiti.controlLer.milaoshidelegate "></activiti:taskListener> </extensionElements> </userTask> <seq Uenceflow id= "Flow14" name= "Milaoshi" sourceref= "Exclusivegateway1" targetref= "Milaoshi" > <conditionexpressio n xsi:type= "Tformalexpression" ><! [cdata[${result==flowmilaoshi}]]></conditionexpression> </sequenceFlow> <sequenceflow id= "Flow1 5 "sourceref=" Milaoshi "targetref=" Endevent1 "></sequenceFlow> <sequenceflow id=" Flow16 "sourceref=" Usertask2 "targetref=" Endevent1 "></sequenceFlow> <sequenceflow id=" flow17 "name=" Guhaiyan "sourceref=" Exclusivegateway2 "targetref=" Usertask1 "> <conditionexpression xsi:type=" tformalexpression "><!"  [cdata[${result==flowhaiyan}]]></conditionexpression> </sequenceFlow> <sequenceflow id= "FLOW18" sourceref= "Exclusivegateway2" targetref= "Endevent1" ></sequenceFlow> <exclusivegateway id= " Exclusivegateway2 "Name="Exclusive Gateway" ></exclusiveGateway> <sequenceflow id= "flow19" sourceref= "Jingyuan" targetref= " Exclusivegateway2 "></sequenceFlow> </process> <bpmndi:bpmndiagram id=" Bpmndiagram_myprocess " > <bpmndi:bpmnplane bpmnelement= "myprocess" id= "bpmnplane_myprocess" > <bpmndi:bpmnshape bpmnElement= "Startevent1" id= "Bpmnshape_startevent1" > <omgdc:bounds height= "35.0" width= "35.0" x= "60.0" y= "150.0" >&lt 
        ;/omgdc:bounds> </bpmndi:BPMNShape> <bpmndi:bpmnshape bpmnelement= "Xvshu" id= "Bpmnshape_xvshu" > <omgdc:bounds height= "55.0" width= "105.0" x= "140.0" y= "140.0" ></omgdc:Bounds> </bpmndi:bpmns hape> <bpmndi:bpmnshape bpmnelement= "Jingyuan" id= "Bpmnshape_jingyuan" > <omgdc:bounds height= "55 .0 "width=" 105.0 "x=" 400.0 "y=" 140.0 "></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:bpmnshape Bpmnelement= "Usertask1" id= "Bpmnshape_usErtask1 "> <omgdc:bounds height=" 55.0 width= "105.0" x= "630.0" y= "140.0" ></omgdc:Bounds> </ bpmndi:bpmnshape> <bpmndi:bpmnshape bpmnelement= "endevent1" id= "Bpmnshape_endevent1" > <omgdc:bou NDS height= "35.0" width= "35.0" x= "745.0" y= "270.0" ></omgdc:Bounds> </bpmndi:BPMNShape> &LT;BPMN Di:bpmnshape bpmnelement= "Exclusivegateway1" id= "Bpmnshape_exclusivegateway1" > <omgdc:bounds height= "40.0" W Idth= "40.0" x= "290.0" y= "147.0" ></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:bpmnshape Bpmnel Ement= "Usertask2" id= "Bpmnshape_usertask2" > <omgdc:bounds height= "55.0" width= "105.0" x= "350.0" y= "14.0" > </omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:bpmnshape bpmnelement= "Milaoshi" id= "Bpmnshape_mila Oshi "> <omgdc:bounds height=" 55.0 width= "105.0" x= "258.0" y= "260.0" ></omgdc:Bounds> </bpm
      Ndi:bpmnshape><bpmndi:bpmnshape bpmnelement= "Exclusivegateway2" id= "Bpmnshape_exclusivegateway2" > <omgdc:bounds height=  "40.0" width= "40.0" x= "539.0" y= "147.0" ></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:bpmnedge
        Bpmnelement= "Flow1" id= "Bpmnedge_flow1" > <omgdi:waypoint x= "95.0" y= "167.0" ></omgdi:waypoint> <omgdi:waypoint x= "140.0" y= "167.0" ></omgdi:waypoint> </bpmndi:BPMNEdge> &LT;BPMNDI:BPMN 
        Edge bpmnelement= "flow4" id= "bpmnedge_flow4" > <omgdi:waypoint x= "735.0" y= "167.0" ></omgdi:waypoint> <omgdi:waypoint x= "762.0" y= "173.0" ></omgdi:waypoint> <omgdi:waypoint x= "762.0" y= "270.0" & gt;</omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:bpmnedge bpmnelement= "flow5" id= "bpmnedge_flow5" "> <omgdi:waypoint x=" 245.0 "y=" 167.0 "></omgdi:waypoint> <omgdi:waypoint x=" 290.0 "y=" 16 7.0 "></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:bpmnedge bpmnelement= "flow6" id= "bpmnedge_flow6" > <o Mgdi:waypoint x= "330.0" y= "167.0" ></omgdi:waypoint> <omgdi:waypoint x= "400.0" y= "167.0" ></omgdi: waypoint> <bpmndi:BPMNLabel> <omgdc:bounds height= "14.0" width= "40.0" x= "339.0" y= "179.0" ;</omgdc:bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:bpmnedge Bpmnelem Ent= "Flow13" id= "bpmnedge_flow13" > <omgdi:waypoint x= "310.0" y= "147.0" ></omgdi:waypoint> &L T;omgdi:waypoint x= "310.0" y= "41.0" ></omgdi:waypoint> <omgdi:waypoint x= "350.0" y= "41.0" ></omgdi :waypoint> <bpmndi:BPMNLabel> <omgdc:bounds height= "14.0" width= "44.0" x= "310.0" y= "91.0" ;</omgdc:bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:bpmnedge Bpmnelem Ent= "Flow14" id= "bpmnedgE_flow14 "> <omgdi:waypoint x=" 310.0 "y=" 187.0 "></omgdi:waypoint> <omgdi:waypoint x=" 310. 0 "y=" 260.0 "></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:bounds height=" 14.0 "width=" 3 8.0 "x=" 310.0 "y=" 219.0 "></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> & Lt;bpmndi:bpmnedge bpmnelement= "FLOW15" id= "BPMNEDGE_FLOW15" > <omgdi:waypoint x= "363.0" y= "287.0" ></om
      gdi:waypoint> <omgdi:waypoint x= "745.0" y= "287.0" ></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:bpmnedge bpmnelement= "Flow16" id= "Bpmnedge_flow16" > <omgdi:waypoint x= "455.0" y= "41.0" >&  lt;/omgdi:waypoint> <omgdi:waypoint x= "762.0" y= "41.0" ></omgdi:waypoint> <omgdi:waypoint x= "762.0" y= "270.0" ></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:bpmnedge bpmnelement= "flow "Id=" BPMNEDGE_FLOW17 "> <omgdi:waypoint x= "579.0" y= "167.0" ></omgdi:waypoint> <omgdi:waypoint x= "630.0" y= "167 .0 "></omgdi:waypoint> <bpmndi:BPMNLabel> <omgdc:bounds height=" 14.0 "width=" 100.0 "x=" 578.0 "y=" 150.0 "></omgdc:Bounds> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmnd I:bpmnedge bpmnelement= "flow18" id= "bpmnedge_flow18" > <omgdi:waypoint x= "559.0" y= "187.0" &GT;&LT;/OMGDI:WAYP oint> <omgdi:waypoint x= "559.0" y= "287.0" ></omgdi:waypoint> <omgdi:waypoint x= "745.0" y= "287.0" ></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:bpmnedge bpmnelement= "flow19 id=" Bpmne Dge_flow19 "> <omgdi:waypoint x=" 505.0 "y=" 167.0 "></omgdi:waypoint> <omgdi:waypoint x=" 53 9.0 "y=" 167.0 "></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:bpmnd Iagram> </definitiOns> 

Start the code for the process:

Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.util.HashMap;

Import Java.util.Map;
Import Org.activiti.engine.ProcessEngine;
Import org.activiti.engine.ProcessEngineConfiguration;
Import Org.activiti.engine.RepositoryService;
Import Org.activiti.engine.RuntimeService;
Import Org.activiti.engine.TaskService;
Import org.activiti.engine.runtime.ProcessInstance;

Import Org.activiti.engine.task.Task; public class Namedemo {private static string Readdatafromconsole (String prompt) {bufferedreader br = new Bufferedrea
		Der (New InputStreamReader (system.in));
		String str = NULL;
			try {System.out.print (prompt);

		str = Br.readline ();
		catch (IOException e) {e.printstacktrace ();
	return str;
		public static void Main (string[] args) {string str = readdatafromconsole (' Please input String: ');
		
		SYSTEM.OUT.PRINTLN ("The Information from console:" + str); Create a process engine processengineconfiguration ProcessenginEConfiguration = processengineconfiguration. Createstandaloneprocessengineconfiguration ();
		The configuration of the connection database Processengineconfiguration.setjdbcdriver ("Com.mysql.jdbc.Driver"); Processengineconfiguration. Setjdbcurl ("jdbc:mysql://localhost:3306/activitiexam?useunicode=true&
		Characterencoding=utf8 ");
		Processengineconfiguration.setjdbcusername ("root");
		Processengineconfiguration.setjdbcpassword ("root");
		
		Processengine processengine = processengineconfiguration. Buildprocessengine (); Use spring to manage the creation of the workflow engine/* processengine processengine = processengineconfiguration. Createprocessengin  Econfigurationfromresource ("Applicationcontext-common.xml"). Buildprocessengine ();
		* * SYSTEM.OUT.PRINTLN (processengine);

		Get the Process Storage Service component Repositoryservice Repositoryservice = Processengine. Getrepositoryservice ();

		Gets the runtime service component Runtimeservice Runtimeservice = Processengine.getruntimeservice (); Get Process Task Component Taskservice Taskservice= Processengine.gettaskservice (); 1. Deployment process file Repositoryservice.createdeployment (). Name ("Myprocess"). Addclasspathresource ("diagrams/" + str + ". BPMN"

		). deploy (); 2, start the process--according to key deployment is the default to find the latest version processinstance ProcessInstance = Runtimeservice. Startprocessinstancebykey ("myprocess
		
		"); String end= "0";//processinstance.getid ()!= null while (End.equalsignorecase ("0")) {//circular query task tasks = TA		
			Skservice.createtaskquery (). Processinstanceid (Processinstance.getid ()). Singleresult ();
			map<string, object> variables = new hashmap<string, object> ();
				if (task==null) {end= "1";
				SYSTEM.OUT.PRINTLN ("The task is over");
			Break
				}else{str = readdatafromconsole ("Please input result:");
				String flowjingyuan=readdatafromconsole ("Please input Flowjingyuan:");
				String flowhaiyan=readdatafromconsole ("Please input Flowhaiyan:");
				
				String flowmilaoshi=readdatafromconsole ("Please input Flowmilaoshi:"); Variables.put ("Result", StR);
				Variables.put ("Flowjingyuan", Flowjingyuan);
				Variables.put ("Flowhaiyan", Flowhaiyan);
								
				Variables.put ("Flowmilaoshi", Flowmilaoshi);	Taskservice.complete (Task.getid (), variables); Completing the Task}}}

Execution results:




Summarize:

The first explanation is that all of the pauses that exist on the client are non-existent in real-world development, here just to pass the variable, tell the workflow how to continue to execute to the next node, in the real development business is different people to handle different tasks, each query only query their own tasks, Workflows are automatically executed only when their own tasks are completed.

Explain the results of the execution:




The Xvshu node is executed immediately after the workflow is started, but the parameters of the next node need to be entered when the Xvshu node is processed, and when the input Result==flowjingyuan, the Jingyuan node is executed immediately, and the output jingyuan88, Processing Jingyuan nodes also need to enter the next node parameters, when the input content Result==flowhaiyan immediately execute Haiyan node, output 88guhaiyan, processing Guhaiyan node, you need to enter the next node parameters, Because the next node of the Haiyan node ends and there is no condition limit, entering any information will end.




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: 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.