Process Tasks-User Tasks

Source: Internet
Author: User
Tags vars

The user task is the most common task, and when the process arrives at the user's task, it is assigned to a specific user or group of users.

A task candidate is a group of potential users with permissions to work on the task, which has the authority to process or complete the task.

The Task assignee refers to the person who actually performs the task, one can have multiple task candidates, but only one task assignee.

1. Set up a task candidate

Code settings

Set candidate Taskservice.addcandidateuser (...) Set group Taskservice.addcandidategroup (...)

XML configuration

<usertask id= "Usertask1" name= "Task1" > <potentialOwner> <resourceAssignmentExpression>  < Formalexpression>
User (Angus), Group (management), Boss <!--not using user or group, are considered directly as id--> </formalExpression> </ Resourceassignmentexpression> </potentialOwner></userTask>

View:

// query tasks based on user groups list<task> tasks = Taskservice.createtaskquery (). Taskcandidategroup ("Boss"). List (); System.out.println ("Number of tasks assigned to the Boss User group:" + tasks.size ()); // depending on the user query task Tasks = Taskservice.createtaskquery (). Taskcandidateuser ("Angus"). List (); System.out.println ("The number of tasks under User Angus is:" + tasks.size ());

Note: The specified user group or user does not need to be present in the table.

2. Set up the Task assignee

Code

Assignee_ field Taskservice.setassignee (...) corresponding to Act_ru_task

XML configuration

<UsertaskID= "Usertask1"name= "Task 1">    <Humanperformer>        <resourceassignmentexpression>            <formalexpression>User1</formalexpression>        </resourceassignmentexpression>    </Humanperformer></Usertask>

View available Taskquery.taskassignee (...)

3. Using the Acitivi permission Assignment extension (activiti:assignee/activiti:candidateusers/activiti:candidategroups)

    <UsertaskID= "Usertask1"name= "Assignee"Activiti:assignee= "User1"></Usertask>    <UsertaskID= "Usertask2"name= "Candidate User"activiti:candidateusers= "User1,user2"></Usertask>    <UsertaskID= "Usertask3"name= "Candidate Group"activiti:candidategroups= "Group1,group2"></Usertask>

4. In a business system, user groups or users are subject to change, so you can write task listeners for dynamic permission assignment

4.1 Implementing the Tasklistener interface

 Public class Implements Tasklistener {    publicvoid  notify (Delegatetask delegatetask) {        SYSTEM.OUT.PRINTLN ("Use task Listener to set task Permissions");        Delegatetask.setassignee ("user1");        Delegatetask.addcandidategroup ("group1");}            }

4.2 Configuring monitoring

<UsertaskID= "Usertask1"name= "Assignee">    <extensionelements>        <Activiti:tasklistenerEvent= "Create" <!--task creation time--class= "Org.bestmyself.activiti.UserTaskListener">        </Activiti:tasklistener>    </extensionelements></Usertask>

View:list<task> tasks = Taskservice.createtaskquery (). Taskassignee ("user1"). List ();

5. Assigning permissions using Juel (activiti default support Juel)

<UsertaskID= "Usertask2"name= "Task 1"Activiti:assignee= "${authservice.getuserassignee ()}"></Usertask><UsertaskID= "Usertask3"name= "Task 2"activiti:candidateusers= "${authservice.getcandidateusers ()}"></Usertask><UsertaskID= "Usertask4"name= "Task 3"activiti:candidategroups= "${authservice.getcandidategroups ()}"></Usertask><UsertaskID= "Usertask5"name= "Task 4"Activiti:assignee= "${authservice.lastuser}"> <!--to have a corresponding Getter/setter method--</Usertask>
Note: The Authservice instance needs to be set to the process parameters
   New Hashmap<string, object>();   Vars.put (new  authservice ());    // starts the process, serializes the Authservice instance into Act_ge_bytearray   ProcessInstance pi = Runtimeservice.startprocessinstancebykey ("Process1", VARs);

                                                                                       

 

Process Tasks-User Tasks

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.