JBPM Express Business processes (process definition language)

Source: Internet
Author: User
Tags jbpm

The business process consists of three parts:

    1. Active activity/node nodes (there are many kinds, different types have different functions, must have a start activity)
    2. Connection Transition/Transfer (from one activity to another activity)
    3. Events Event
Transition

There can be only one connection in the start activity, and once a process instance is started, it stops at an activity after the start of the activity, so there can only be one start activity and connection. There is no connection to the end event. Other activities can be connected in one or more lines. You must leave the current activity with the specified line name, without specifying that the line name defaults to null and that there can be at most one line name named NULL. The corresponding syntax is:

Taskservice.completetask (taskId, outcome);

The name of the specified line must be the same as the line name on the flowchart, including spaces. If no corresponding connection is found, an exception is thrown.

There are many places in the jBPM4.4 to use the name of the connection, its API also has a lot of names, such as outcome, Signalname, Transionname are the name of the transition. variables, Parameters is a collection map representing the process variables.

Activity

There are two types of activities: pre-defined activities and custom activities. Pre-defined activities are activities that can be used directly, such as Start,end.

Here's a description of several common predefined activities:

Start Activity/start

Represents the beginning of a process, and there can be only one start in a flowchart. And start must have and only have one transition. No other transition point to start, and when the process instance starts, it leaves the start activity.

End Activity/end

Represents the end of the process, and a flowchart can have 0 or more end. For example:

If there is no end, the process is finished after an activity with no transition is executed.

If there is more than one end, the process is finished by executing to either end.

Task Activity/task

The rep needs a person to do things here, and the process can continue backwards when things are done.

When you specify a task person, you can specify it by using the assignee property.

When a task is generated, only the designated person can see the task and handle the task by default.

Judging activity/decision

When using decision, you specify a Decisionhandler implementation class to handle. For example, there is a process example:

If it is not greater than 2000, then the department manager directly, more than 2000 to find the general manager. To make this logical judgment, use decision to create a class that implements the Decisionhandler interface:

@SuppressWarnings ("Serial") Public classDecisionhandlerimplImplementsDecisionhandler {//calculate, and return the name of the line that should be used@Override PublicString Decide (openexecution execution) {intMoney = (Integer) execution.getvariable ("Reimbursement Amount"); System.out.println ("Decisionhandlerimpl.decide ()---> Reimbursement amount =" +Money ); if(Money > 2000) {            return"To general manager for approval"; } Else {            return"To End1"; }    } }

We say that the life cycle of the process variable is the same as the life cycle of the process instance, and the amount is taken over by the process variable. The processor class is specified in the handler class attribute of decision.

Branch/Aggregation fork/join

Fork and join are used in pairs. Multiple branches separated from a fork must go back to the same join. When the process executes into a fork, the processinstance is split into multiple sub-execution that are executed in parallel. Because ProcessInstance inherits from execution and is a markup interface, ProcessInstance is just a concept, it is to represent the execution of the entire execution, that is, the execution of the main line.

 Public Interface extends Execution {}

Off the topic, back to continue. When the process executes to the fork, it is divided into several sub-execution that are executed concurrently, and the process will continue to execute after the join when all the branches have finished reaching the join:

The above process example refers to: when the department manager and the general manager agree, regardless of who first agreed to continue to carry out.

Status Activity/state

The state activity can be understood as: if the task is waiting for someone to handle it, then it is waiting for the computer to handle it. Because there is no property other than the property of the name, there is no other attribute, and the process executes to state and it will stop. It will not execute until you tell it to continue. The only thing you can do is give it a "signal". Suppose there is such a process instance:

There are two state, you will encounter State1 when the process instance is started, then stop, wait for "signal", said on the above. Outcome, Signalname, Transionname is the name of the transition. But unlike other activities, other activities, such as task, throw exceptions when no corresponding transition are found, while state does nothing:

//let the process take one step backwards@Test Public voidSingal () {//allows the specified execution to leave the current node and proceed backwardsString Executionid = "test.380007"; //when there is only one transition, use this transition to leave the current activity//If there are multiple transition, but do not specify which one to use, it will not leave the node, nor error. //Processengine.getexecutionservice (). Signalexecutionbyid (Executionid); //When you have more than one transition, you must refer to the name of the transition you want to use. Processengine.getexecutionservice (). Signalexecutionbyid (Executionid, "to State2");}

Anything you can do in the predefined activities above can be done through custom activities.

Custom activity has only two properties, a name, a class's full pathname, to its class to implement the Externalactivitybehaviour interface, assuming I want to send mail in this activity, can do this:

@SuppressWarnings ("Serial") Public classExternalactivitybehaviourimplImplementsExternalactivitybehaviour {//What to do when the process is in the current activity. @Override Public voidExecute (activityexecution execution)throwsException {//get the person to notify and the information to be notified through the process variablesString subject = (string) execution.getvariable ("Subject"); String[] Users= (string[]) execution.getvariable ("Users")); //Simulation for Notifications         for(String user:users) {System.out.println (user+ ", there is a meeting today 5 o'clock in the afternoon, the theme of the meeting is:" + Subject + ". "); }         //do not leave after execution, wait until the Singal method is called. //execution.waitforsignal (); //leaves the current activity with a line with the specified name. //Execution.take (transitionname); //Use the default (1th in the configuration) transition to leave the current activity. execution.takedefaulttransition (); //If none of the above methods are called, the default is to leave the current activity after execution.     }     //what to do before explicitly calling the signal method outside of the current activity@Override Public voidSignal (activityexecution execution, String signalname, Map parameters)throwsException {System.out.println ("---> externalactivitybehaviourimpl.signal ()"); }}

We just have to write the Execute () method at will, and we can do what we want to do. The data that needs to be used in it is still going through the process variables.

How task is assigned

Way One:

A task can be set through the assignee property, is a specific person, or you can specify a process variable that uses the computed result (the result is a string type) to represent the person who handled it.

Way two:

Using a class to implement a Assignmenthandler interface, such as:

@SuppressWarnings ("Serial") Public classAssignmenthandlerimplImplementsAssignmenthandler {@Override Public voidAssign (assignable assignable, openexecution execution)throwsException {//Calculate the task of the person (perhaps to get the process variables, may be the query database, or other)//execution.getvariable (key);String userId = "Zhao Liu"; //the person who specified the taskAssignable.setassignee (userId); System.out.println ("----> Assignmenthandlerimpl.assign ()"); } }

Set the final result (string type) with the Setassignee () method. This requires that you first add the Assignment-handler tag to the XML file and write the full classpath name:

<Taskname= "Task1"g= "86,175,92,52">    <Assignment-handlerclass= "Cn.zhangao.AssignmentHandlerImpl">assignment-handler><transitionname= "to End1" to= "End1"g= " -47,-17" />task>

Way three:

Specified directly in the program, the type of UserID is a string:

Processengine.gettaskservice (). Assigntask (TaskId, userId);

These three ways can only be assigned to individuals, the following three ways may be assigned to groups:

Way One:

Specifies the Candidate-users property, which can be specified as a specific string (separated by commas in English), or as a process variable, using the computed result (if the string type is separated by commas) to represent the candidate.

Way two:

Implement Assignmenthandler interface, add a group member (candidate) using the Assignable.addcandidateuser (userId) method

Way three:

specified in the program:

Processengine.gettaskservice (). Addtaskparticipatinguser (TaskId, UserId, participation.candidate);

Note that the group task must be queried for the group's task list to see:

//query A person's group Task list (in the name of the group to query)@Test Public voidfindgrouptasks () {//String userId = "3";String userId = "King 5"; //Enquiry//List List = Processengine.gettaskservice (). Findgrouptasks (userId);List List = Processengine.gettaskservice ()//. Createtaskquery ()//. Candidate (UserId)// . List (); //ShowSystem.out.println ("=========== [" + UserId + "] Group Task List ==========");  for(Task t:list) {System.out.println ("Id=" + T.getid ()//+ ", name=" + t.getname ()//the name of the task+ ", assignee=" + T.getassignee ()//the person who handles the task+ ", createtime=" + t.getcreatetime ()//when the task was created+ ", executionid=" + T.getexecutionid ());//ID of the execution to which the task belongs    }}

In the individual can not be seen, to find their own group of tasks, through the "pick" task to turn the task into a personal task, so that they can handle:

// Pickup Task @Test  Public void Taketask () {    = "450008";     = "Wang 5";     Processengine.gettaskservice (). Taketask (TaskId, userId);}

After it becomes a personal task, it is not found in the Group task query.

Event/event

Events can only be added manually in the XML file themselves.

    1. In the root element, or in a node element, an element is used to specify an event, where the event property represents the type of events.
    2. In using child elements, specify the class to be processed, requiring the specified class to implement the EventListener interface

Event Type:

    • element in the root element (), you can specify the event as start or end to indicate the beginning and ending of the process.
    • element is placed in a node element, you can specify event as start or end, which indicates the entry and exit of the node
    • There is only an end event in the start node and only the start event in the end node.
    • Write directly in the element, which is the configuration event. (because there is only one event here, so do not write on and type)
    • The Assign event can also be configured in the element, which is triggered when the task is assigned.

This article transferred from: http://blog.csdn.net/zhangao0086/article/details/6327406

JBPM Express Business processes (process definition language)

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.