Integration of jbpm with business systems-implemented by customizing task instances

Source: Internet
Author: User
Tags jbpm
Recently, during jbpm consulting/training, customers often asked this question: JBoss jbpm is good, but it can only provide us with a workflow engine and a business flow mechanism, but it cannot handle business problems and manage business data for us. How can we combine developed business systems and jbpm process engines to run them together?

After integrating the jbpm process system with the customer's business system, the final analysis is to associate the task instance and business instance in the process of running the process, there are two methods:

1. Save the reference of the task instance in the business system. The system is business-oriented and can obtain contextual data such as its position in the process from a business transaction.

2. saves business instance references in the jbpm process system. The system is process-oriented and provides business tasks to users through the workflow task list, obtain the bound business data based on the additional data of the task instance.

Generally, I recommend method 1 because it does not intrude the workflow system. You only need to modify the business system and add a column in the business table to save the task instance id, this step is generally pre-structured in the business system design phase.

However, if the business system has been finalized, and the existing business system needs to be added to workflow management without intrusion, method 1 is obviously inappropriate, so how to implement method 2? There are two ideas:

1. save the reference of the business system as the process/task instance varialbes variable in the jbpm system, you can use the process/task instance to query the data of the Business instance based on the Business Reference variables it binds. We know that the variable system of jbpm can store any serializable objects, so we can even save the Java objects of the entire business instance in the jbpm Workflow System (this may be crazy, because database access to binary data and Object Sequence/deserialization affect efficiency ).

2. This is an idea officially recommended by jbpm. Modify the jbpm taskinstance database table! That is, modify the original table structure of jbpm and extend its source code. Please note that I am using extensions, because this will not modify any jbpm source code, but just extensions. This is also a good habit of open-source application software: do not modify its source code, instead, try to use the mechanism provided by it to "Expand" The functions you need.

Core of idea 2: first, add a column in the taskinstance table, for example, "biz_id", to save the reference of the business system, such as "Order ID", "contract number "......
Create a custom taskinstance class, and create its HBM description file (do not say you don't understand hibernate, that's the same for the gods ), both of them must inherit the original taskinstance definition of jbpm, for example:

  1. Public class ctaskinstance extends taskinstance {
  2. Private Static final long serialversionuid = 1270139435455649329l;
  3. Protected string bizid;
  4. Public ctaskinstance (){
  5. }
  6. Public ctaskinstance (string taskname ){
  7. This. Name = taskname;
  8. }
  9. Public ctaskinstance (string taskname, string actorid ){
  10. This. Name = taskname;
  11. This. actorid = actorid;
  12. }
  13. Public String getbizid (){
  14. Return bizid;
  15. }
  16. Public void setbizid (string bizid ){
  17. This. bizid = bizid;
  18. }
  19. }
  1. <? XML version = "1.0"?>
  2. <! Doctype hibernate-mapping public
  3. "-// Hibernate/hibernate mapping DTD 3.0 // en"
  4. Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd>
  5. <Hibernate-mapping auto-import = "false" default-access = "field">
  6. <Subclass name = "org. jbpm. Customer. ctaskinstance. ctaskinstance"
  7. Discriminator-value = "C"
  8. Extends = "org.jbpm.taskmgmt.exe. taskinstance">
  9. <Property name = "bizid" column = "bizid _"/>
  10. </Subclass>
  11. </Hibernate-mapping>

What do you think we should do next? That's right. Add the description of this persistence type to hibernate. cfg. xml of jbpm. This is not a specific table.
At this time, architects will ask: how can we let the jbpm system know our custom task instance and use it instead of the original task instance when the process is running? Therefore, we need to replaceJbpm. task. instance. Factory attribute configuration, replace this task instance factory with our own implementation, this is completely clear.
Custom task instance factory needs to be implementedOrg. jbpm. taskmgmt. taskinstancefactory interface, for example:

  1. Public class ctaskinstancefactoryimpl implements taskinstancefactory {
  2. Private Static final long serialversionuid = 1l;
  3. Public taskinstance createtaskinstance (executioncontext ){
  4. Ctaskinstance ctaskin = new ctaskinstance ();
  5. Ctaskin
  6. . Setbizid (new date (system. currenttimemillis ())
  7. + "_ U bizid here ");
  8. Return ctaskin;
  9. }
  10. }

At this time, experienced readers may have questions: Where can we insert our business data ID into a custom task instance? Or two ways to choose :-)

1. See the aboveTaskinstancefactoryImplementation: You canWhen createtaskinstance is used, set the business data ID. The prompt is: You can useThe executioncontext object obtains the business data ID from the process instance variable to meet more flexible scenarios. Of course, you need to set this variable in the process instance in advance.
2. You can write/set the task controller to set the business data ID for each customer task instance at start and end. Similarly, the data can come from the variable pre-bound to the process instance.

Therefore, when our customer task instance is submitted persistently, the business data ID can be stored in the database with the custom task instance object.
In the official User Guide (3.2.3), you can briefly describe how to expand task instances for your reference:
12.10. Customizing task instances

Task instances can be customized. The easiest way to do this is
To create a subclassTaskinstance. Then create
Org. jbpm. taskmgmt. taskinstancefactoryImplementation and
Configure it by setting the configuration PropertyJbpm. task. instance. Factory
To the fully qualified class name in the jbpm. cfg. xml. If you use a subclass
Taskinstance, also create a hibernate
Mapping File For the subclass (using the hibernate
Extends = "org.jbpm.taskmgmt.exe. taskinstance"). Then
Add that mapping file to the list of Mapping Files in
Hibernate. cfg. xml

You are welcome to repost it. Please note the author: Hu Qi

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.