The seventh day of the house urgent to send the item note! (jbpm Workflow and introduction--Rights Management model) _ Home Rush Project

Source: Internet
Author: User
Tags php framework jbpm
I. Review of the first day's core content
1, JBPM is what. What to bring to my project.
Workflow is to automate the business process, not manually, control the execution of the task--------all business Process execution information can be stored in the database
JBPM is currently very popular an open source workflow framework
When project business processes are numerous and complex, using workflows to manage projects and reduce business operations errors, all business references

2, JBPM Workflow use
The first aspect: Carry on workflow business process design Install GPD plug-in
The second aspect: using the JBPM API to complete workflow framework operations Processengine, Repositoryservice, Executionservice, Taskservice
Jar Package Import (JBPM will be integrated into the BOS home delivery Project today)

3. Business Process Definition Management
1 Publishing Business process classpath file release, zip compressed file release
Configuration-----processengine----repositoryservice (process definition related services)-----createdeployment ()
---Add resource ddresourcefromclasspath/addresourcesfromzipinputstream----Deploy () Publishing method
* Operation deployment, LOB, Deployprop three sheets

2) query
Repositoryservice.createprocessdefinitionquery () query process definition
3) Delete
Repositoryservice.deletedeploymentcascade (java.lang.String Deploymentid)

4 Start the process, the default start of the latest version of the process Startprocessdefinitionbykey; How to get the latest version process information ORDERDESC (process ID)---take the first

4. Business Process Execution Management
1) Start process instance Executionservice.startprocessdefinitionbykey
Insert records by default to Jbpm4_execution (instance execution information) Jbpm4_hist_procinst (instance execution history)
According to Task Action Jbpm4_task (Task table), Jbpm4_hist_task (History task table), Jbpm4_hist_actinst (Activity record table)

2 Query My task (define the task, make Assignee for the task)
Query must first create corresponding query object, then complete
First Kind
Taskservice.createtaskquery (). Assignee (java.lang.String userId). List ()----can be paged, sorted
Second Kind
Taskservice.findpersonaltasks (java.lang.String userId)

3) Handling Tasks
Taskservice.completetask (java.lang.String taskId)

4) Backward flow of one (mainly for multiple transition, state node)
Executionservice.signalexecutionbyid (java.lang.String Executionid) executes a process instance step backward

5. The variables during the operation of the instance
Set up process instance variables through Executionservice, taskservice----as long as the same process instance can get the variable
Complex object Save (PO class/Implementation Serializable interface in Hibernate configuration)

====================================================================================
Second, Process definition language (predefined activity node)
1, <process name= "HelloWorld" xmlns= "Http://jbpm.org/4.4/jpdl" key= "holiday" > Process definition Node
Name: Process definition Names
Key: Process key (key value), if not write default key value is the name value, in the program through the key value to start a process instance
Version: Must be stored in the database to specify the number (if the version already exists, the error), do not specify, the database to complete the increase
xmlns: Introduce schema constraints, write a file hint effect HTTP://JBPM.ORG/4.4/JPDL no hint effect
JBPM Unzip the directory/src/jpdl-4.4.xsd configure a hint

2, Flow Transition node
Activities can be added transition flow, add one or more (start only one, end no)
Specify a Flow node
The first way: When the task is completed Gettaskservice (). Completetask (Task.getid (), transition);
The second way: through Executionservice.signalexecutionbyid (java.lang.String executionid,transition) primarily for state nodes

Configure JPDL prompts, select NAMESPACE:HTTP://JBPM.ORG/4.4/JPDL

3, Flow control node (activity node Activities)------Drawing and UML activity diagram
1) Start node
2 End node (end normal End-cancel cancel process End-error Process exception termination)

3 State node (automatically completes some task nodes, such as sending a confirmation message)----The node will stay
Through Executionservice.signalexecutionbyid (java.lang.String executionid,transition)

4) Decision Judgment node
For branch cases
Specifies that the handler must implement the interface Decisionhandler
According to the variables in the process, determine which transition to move to

5) Fork/join Branch, merge node
Fork used to represent branching, be sure to perform tasks in parallel, and after using fork, be sure to merge the branches with joins
Decistion representative in satisfying characteristic condition, branch optional One

Obtain all name:pi.findActiveActivityNames ();
Activitycoordinates C = Processengine.getrepositoryservice ()
. Getactivitycoordinates (Processdefinitionid, activityname);
Get the node coordinates "x-axis y ordinate width height"
System.out.println ("x=" + c.getx ()
+ ", y=" + c.gety ()
+ ", width=" + c.getwidth ()
+ ", height=" + c.getheight ());

6 Task Node
The person in charge, the designated person responsible for the task

Three ways of assigning tasks (personal tasks)
First: When drawing, specify <task name= "handle" assignee= "John" > Disadvantage: Responsible person fixed, not conducive to maintenance
Specify the owner as a variable format #{variable name} <task name= "Transact" assignee= "#{userid}" >
The second: Write <assignment-handler class= in <task> "" > by the specified class responsible for specifying the owner, which must implement the Assignmenthandler
Assignable.setassignee ("Person in charge");
Add logic, such as process variables, variables to specify, no process variables, set default owner
Third: Before the task is completed, you can replace the owner Taskservice.assigntask (task ID, responsible person)

Three ways of assigning tasks (group tasks)------There is a task that is done by a specified group of people, each of whom has the ability to complete the task.
The first: assignment type:candidate-users expression: Xiao Wang, Xiao Li, Xiao Zhang
Jbpm4_participation Table Storage Group Task user Information
Query Personal group Tasks java.util.list<task> findgrouptasks (java.lang.String userId)
Users can query group tasks as long as they are in the group
Pickup task: A user within a group that transforms a group task into a personal task Taskservice.taketask (taskid, user);
After the operation of the pickup task: 1 small Li pick up the task after completion of Taskservice.completetask 2) Xiao Li did not have time to do, change the Task Manager taskservice.assigntask 3) Xiao Li did not have time to do, can not find the person in charge, the task returned to any Service Group
Second: Write <assignment-handler class= in <task> "" > Designated by Handler
Assignable.addcandicateuser (Group task User)
Third: Add a group user to a task that already exists
Processengine.gettaskservice (). Addtaskparticipatinguser (Taskid,userid, participation.candidate);

====================================================================================
Three, custom Activity node
Draw a flowchart to add the custom node to the diagram (custom activity node)
JBPM provides an activity interface that represents an active, predefined activity implementation Activitybehaviour interface, if the custom Activity node is implemented Externalactivitybehaviour

@Override
public void execute (activityexecution activityexecution) throws Exception {
This activity has been implemented
}

@Override
public void signal (Activityexecution activityexecution, String s,
Map<string,?> map) throws Exception {
Represents a process that stops at the current node and performs before leaving
}
Custom activities, the default does not stay in the node------not stay, will not signal
Actions in the Execute method
1,activityexecution.waitforsignal (), waiting at the current node.
2,activityexecution.takedefaulttransition (), using the default transition to leave, the first defined in the current node is the default.
3,activityexecution.take (String transitionname), using the specified transition to leave
4,activityexecution.end (), ending process instance

Iv. event objects during process Execution (understanding)
JBPM allows you to specify events for each node in the activity

1, the definition listener implements EventListener interface

2, in the root element, or in the node element, use the <on event= "" > element to specify the event, where the event property represents the type
A <on> element in the root element (<process>), you can specify that the event is start or end, which indicates the beginning and ending of the process.
b <on> element is placed in the node element, you can specify the event as start or end to indicate the entry and departure of the node
c there is only an end event in the start node, and only the start event in the end node.
(d) Write <event-listener class= "" in the <transition> element directly, that is, configure the event. (because there is only one event here, so do not write on and type)
E The Assign event can also be configured in the <task> element, which is triggered when the task is assigned.

====================================================================================
V. Integrate JBPM into the project
1, will be integrated after the jar package replication Bos/webroot/web-inf/lib (86 jar package)
2. configuration file Integration
Jbpm:jbpm.cfg.xml Jbpm.hibernate.cfg.xml log4j.properties

Integrate Jbpm.cfg.xml Jbpm.hibernate.cfg.xml two files into Bos
Jbpm.hibernate.cfg.xml essence is Hibernate configuration file (Hibernate configuration to Dao.xml)
<property name= "Mappingresources" >
<list>
<value>jbpm.repository.hbm.xml</value>
<value>jbpm.execution.hbm.xml</value>
<value>jbpm.history.hbm.xml</value>
<value>jbpm.task.hbm.xml</value>
<value>jbpm.identity.hbm.xml</value>
</list>
</property>

Jbpm.cfg.xml needs and spring consolidation
Jbpm-4.4/doc/devguide/html_single/index.html
1) Copy the Jbpm.cfg.xml Bos/config
Change the <import resource= "Jbpm.tx.hibernate.cfg.xml"/> to <import resource= "Jbpm.tx.spring.cfg.xml"/>
2) configuration of jbpm Processengine
<bean id= "Springhelper" class= "Org.jbpm.pvm.internal.processengine.SpringHelper" >
<property name= "jbpmcfg" value= "Jbpm.cfg.xml" ></property>
</bean>
<bean id= "Processengine" factory-bean= "Springhelper" factory-method= "Createprocessengine"/>

3) want to directly get JBPM service object
<bean id= "Repositoryservice" factory-bean= "Processengine" factory-method= "Getrepositoryservice"/>
<bean id= "Executionservice" factory-bean= "Processengine" factory-method= "Getexecutionservice"/>

====================================================================================
Introducing the Rights Management model
1, the most simple Rights Management model (Javaweb)
Suitable for: Not many users, system features are not particularly complex
To add a role field to a user table, and use a field to distinguish which type of role the user belongs to

Benefits: Easy to use, little coding
Disadvantages: Management granularity is coarse, maintenance inconvenient, not flexible enough---not reusable

============ role and resource path relationship, fixed in program, via config file xml/txt

2. Standard Rights Management Module
function table, Permission table, role table, user table

Benefits: The system menu can be dynamically customized, easy to maintain, control granular----REUSABLE
Disadvantages: Developing complex

3. Complex permission System
Oracle Rights control: System permissions, object permissions

CREATE table----belong to system permissions
Select Table user, delete table customer------belong to object permissions

Reference PHP Framework Cake permission Model
User Add/view/list/delete
New Add/view/list/delete

Table structure
User Numbering module function point
1 News Add---------number 1th users can add a press
4 User List--------number 4th users can query all users






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.