`

Dynamic Process Creation Using API [JBPM 5.1]

 
阅读更多
http://atulkotwale.blogspot.com/2012/01/dynamic-process-creation-using-api-jbpm.html
Hi Friends,

As you guys all know jbpm has came up with new version. It has some beautiful features. In this post I will show you how can we make dyanamic process using JBPM 5 API.  While it is recommended to define processes using the graphical editor or the underlying XML (to shield yourself from internal APIs) but sometime we come across such scenario where this feature would really helpful.

Using this API  you can
Create process and set the attributes.
Create task and add to that process. Also you can set the task related attributes.
Establish connections between task.
Get the xml representation of process.
Last but not least we can validation the process and can get the list of errors which were found during validation.
Isn't it great!!!! Let see how can we do it.

Here I created simple process with human task .
package com.sample;

import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.bpmn2.xml.XmlBPMNProcessDumper;
import org.jbpm.process.workitem.wsht.WSHumanTaskHandler;
import org.jbpm.ruleflow.core.RuleFlowProcessFactory;
import org.jbpm.ruleflow.core.factory.HumanTaskNodeFactory;

/**
 * This is a sample file to launch a process.
 */
public class ProcessTest {

    public static final void main(String[] args) {
        try {

            RuleFlowProcessFactory factory =

            RuleFlowProcessFactory.createProcess("org.jbpm.createLetter");

            //creating process dynamically
            factory = factory.name("LetterCreation").version("1.0")
                    .packageName("org.atul");

            
            // adding start node
            factory.startNode(1).name("start").done();

            // adding human task
            HumanTaskNodeFactory nodefactory = factory.humanTaskNode(2);
            nodefactory.name("atul").actorId("department").done();

            // adding end node
            factory.endNode(3).name("end").done();

            // making connections
            factory.connection(1, 2);
            factory.connection(2, 3);

            System.out.println("id is:-"
                    + factory.validate().getProcess().getId());

            // We can get xml for the process using following code.
            String asXml = XmlBPMNProcessDumper.INSTANCE.dump(
                    factory.getProcess(), XmlBPMNProcessDumper.NO_META_DATA);
            System.out.println(asXml);

            //adding to the knowledge base
            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
                    .newKnowledgeBuilder();
            kbuilder.add(ResourceFactory
                    .newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(
                            factory.getProcess()).getBytes()),
                    ResourceType.BPMN2);

            StatefulKnowledgeSession ksession = kbuilder.newKnowledgeBase()
                    .newStatefulKnowledgeSession();
            ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
                    new WSHumanTaskHandler());
            
            // start a new process instance
            ksession.startProcess("org.jbpm.createLetter");
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}


As you can see in the example that we can create process using "createProcess" method if  "RuleFlowProcessFactory" class. This class also provides method to set the attributes of the process. It provides method to create start, end node.you can see that these methods return a specific NodeFactory, that allows you to set the properties of that node. Once you have finished configuring that specific node, the done() method returns you to the current RuleFlowProcessFactory so you can add more nodes, if necessary.  Using "connection" method we can establish connections between the task.

Using following code we can get xml presentation of the process.
            String asXml = XmlBPMNProcessDumper.INSTANCE.dump(
                    factory.getProcess(), XmlBPMNProcessDumper.NO_META_DATA);


Finally once you done with creation of the process, you can validate the process by validate() method.

We can add the process in to the knowledge base as BPMN2 process.
            kbuilder.add(ResourceFactory
                    .newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(
                            factory.getProcess()).getBytes()),
                    ResourceType.BPMN2);

 


Please let me know your view and suggestion to make this post better !!!
分享到:
评论

相关推荐

    jbpm5.1文档(英文).rar

    jbpm5.1是Java Business Process Management(Java业务流程管理)的一个版本,它是一个开源的工作流管理系统,由JBoss社区开发并维护。该系统基于Drools,一个强大的规则引擎,使得jbpm5.1在处理业务流程时具有灵活...

    jbpm5.1学习资源整合

    5. **持久化**:jbpm5.1利用JPA(Java Persistence API)实现数据持久化,确保流程实例和历史数据的安全存储。 **三、学习资源介绍** 1. **jBPM5_用户手册-中文版.doc**:这是一份中文版的用户手册,详细介绍了jbpm...

    jbpm5.1开发手册

    - jBPM (Java Business Process Model) 是一款高度灵活的业务流程管理 (BPM) 套件,旨在为业务分析师与开发人员之间搭建一座桥梁。 - 与传统 BPM 引擎相比,jBPM 不仅仅关注技术层面,同时也重视非技术人员的使用...

    JBPM5.1入门学习

    ### JBPM5.1入门学习知识点详解 #### 1. 什么是JBPM JBPM,全称为Java Business Process Management(业务流程管理),是一款开源的、轻量级且高度可扩展的业务流程管理框架。该框架旨在帮助企业管理和优化其业务...

    JBPM5.1入门手册

    ### jBPM 5.1 入门手册详解 #### 一、jBPM 概述 jBPM 是一款灵活且强大的业务流程管理(BPM)解决方案,它旨在搭建起业务分析师与软件开发者之间的桥梁。传统的 BPM 引擎往往侧重于技术细节,对非技术人员不够友好...

    JBPM 5.1官方文档

    官方指南加+API文档,手工下载,手工打包CHM

    Business Process Management with JBoss jBPM.pdf

    3. **流程定义与执行**:书中详细阐述了如何使用JBoss jBPM定义业务流程,并解释了如何通过API调用来启动和管理这些流程实例。此外,还涉及到了任务分配、消息传递等高级功能,帮助读者深入理解jBPM的工作原理。 4....

    Business Process Management with JBoss jBPM

    《Business Process Management with JBoss jBPM》一书由Matt Cumberlidge撰写,旨在为业务分析师提供实用指南,教授如何利用JBoss jBPM平台构建高效的业务流程。 #### 二、业务流程管理(BPM)概述 业务流程管理...

    jbpm5.4 api javadocs

    jbpm(Java Business Process Management)是一款开源的工作流管理系统,它允许开发者设计、执行和管理业务流程。这个API文档是开发者理解和使用jbpm进行流程自动化开发的重要参考资料。 在jbpm 5.4.0.Final版本中...

    jBPM4.4 详解 API 中文

    ### jBPM4.4 API 详解:工作流自动化的核心技术 #### 一、工作流基础知识 工作流,作为业务过程的部分或整体自动化,旨在通过计算机应用环境实现文档、信息或任务在多个参与者间的自动传递,以达到预期的业务目标...

    jbpm51介绍(2.docx

    jbPM 5.1是其一个版本,提供了一套完整的工具集,包括流程建模、部署、执行以及监控等功能。以下是jbPM 5.1的一些关键知识点: 1. **jbPM 下载与安装**: - 可从SourceForge.net下载jbPM的二进制文件、源码、...

    JBPM_6.0.1_API(最新API)

    **JBPM 6.0.1 API:流程自动化与业务规则管理详解** JBPM,全称为JBoss Business Process Management,是Red Hat公司提供的一款开源的工作流管理系统,它为企业的业务流程自动化提供了强大的支持。JBPM 6.0.1 API是...

    JBPM工作流程API和Jar.zip

    JBPM(Java Business Process Management)是一个开源的工作流和业务流程管理系统,它允许开发者设计、执行、管理和监控复杂的业务流程。这个压缩包“JBPM工作流程API和Jar.zip”包含的是JBPM的相关API文档和必要的...

    jbpm4.4API

    【JBPM4.4 API】是Java Business Process Management(JBPM)系统的一个版本,它提供了一个全面的工作流和业务流程管理框架。JBPM是一个开源项目,由Red Hat维护,广泛应用于企业级应用中,用于管理和执行业务流程。...

    JBPM5.3 API+USERGUID

    **JBPM5.3 API+USERGUID** JBPM5.3是Java Business Process Management(Java工作流管理系统)的一个重要版本,它提供了一整套用于设计、执行和管理业务流程的框架和服务。API(应用程序编程接口)是软件开发的核心...

    jbpm3.1API

    jbpm(Java Business Process Management)是一款开源的工作流管理系统,专为业务流程自动化设计,提供了强大的工作流引擎和API,用于实现复杂的业务流程管理。jbpm3.1版本是其早期的一个重要版本,尽管现在jbpm已经...

Global site tag (gtag.js) - Google Analytics