User Task Assignment Person:
1. User tasks can be assigned directly to a user, which can be defined by the Humanperformer element. Humanperformer definition requires a resourceassignmentexpression
To actually define the user
eg
<UsertaskID= ' Thetask 'name= ' Important Task ' > <Humanperformer> <resourceassignmentexpression> <formalexpression>Kermit</formalexpression> </resourceassignmentexpression> </Humanperformer> </Usertask>
The task is only one user when in Activiti, the user is called the performer. The task that owns the performer does not appear in the other person's task list, but only in the performer's personal task list.
Tasks that are directly assigned to users can be obtained through taskservice like this:
list<task> tasks = Taskservice.createtaskquery (). Taskassignee ("Kermit"). List ();
2. Tasks can also be added to the candidate list of people. You need to use the Potentialowner element. The usage is similar to the Humanperformer element, noting that it needs to specify each
Whether the project is a person or a group (the engine can't guess).
eg
<UsertaskID= ' Thetask 'name= ' Important Task ' > <Potentialowner> <resourceassignmentexpression> <formalexpression>User (Kermit), Group (management)</formalexpression> </resourceassignmentexpression> </Potentialowner> </Usertask>
Tasks assigned to a list or group of candidate users can be obtained through taskservice like this:
list<task> tasks = Taskservice.createtaskquery (). Taskcandidateuser ("Kermit"). List (); list<task> tasks = Taskservice.createtaskquery (). Taskcandidategroup ("Kermit"). List ();
At this time the corresponding person must pick up the task, can handle the success, the task was picked up by one of the people, the other people can not see this task
Task Pickup Method:
Processengine.gettaskservice (). Claim (taskId, userId);
PS: If a user or group is not displayed for the specified setting, the engine will default to group processing. So the following settings are the same as using the Group (accountancy) effect.
< formalexpression >Accountancy</formalexpression>
3.Activiti Extensions to task assignments
User and group settings are cumbersome when allocations are not complex. To avoid complexity, you can use custom extensions for user tasks.
Assignee property: This custom extension can assign a user task directly to a specified user.
<id= "Thetask" name= "My task" Activiti:assignee = "Kermit"/>
It is exactly the same as using the Humanperformer effect defined above.
Candidateusers property: This custom extension can set a candidate for a task.
<id= "Thetask" name= "My task" activiti:candidateusers = "Kermit, Gonzo"/>
It is exactly the same as using the Potentialowner effect defined above. Note that it does not need to be declared as using Potentialowner through the user (Kermit), because this property can only be used by people.
Candidategroups property: This custom extension can set the candidate group for the task.
<usertask id= "Thetask" name= "My Task" activiti:candidategroups= "management, accountancy"/>
PS: These three attributes can be dynamically specified by a process variable, and multiple values need to be separated by commas
4. If the above method does not meet the requirements, you can also use the task listener to create the event to implement the custom allocation logic:
<UsertaskID= "Task1"name= "My task" > <extensionelements> <Activiti:tasklistenerEvent= "Create"class= "Org.activiti.MyAssignmentHandler" /> </extensionelements></Usertask>
Delegatetask is passed to the Tasklistener implementation, through which it can set the executor, candidate and candidate groups:
Public class Implements Tasklistener { publicvoid notify (Delegatetask delegatetask) { // Execute Custom identity lookups here//And then for example call following methods: Delegatetask.setassignee ("Kermit"); Delegatetask.addcandidateuser ("Fozzie"); Delegatetask.addcandidategroup ("Management"); ... }}
5. When using spring, you can use an expression to set the task listener as the spring agent's bean, allowing the listener to listen for task creation events.
In the following example, the performer is obtained by invoking the Findmanagerofemployee method of the spring bean Ldapservice.
The process variable EMP is passed as a parameter to the bean.
<id= "task" name= "My task" activiti:assignee= "${ Ldapservice.findmanagerforemployee (EMP)} "/>
can also be used to set up candidates and candidate groups:
<id= "task" name= "My task" activiti:candidateusers = "${ldapservice.findallsales ()}" />
PS: Note The method return type can only be String or collection<string> (corresponding candidates and candidate groups):
Public class Fakeldapservice { public string Findmanagerforemployee (String employee) { Return "Kermit the Frog"; } Public List<string> findallsales () { return arrays.aslist ("Kermit", "Gonzo", "Fozzie" ); }}
[Go]activiti5 User Task assignment