最新JBoss jBPM 3.1 开始指南之三---创建流程和部署流程

本文来源于:http://www.qqgb.com/Program/Java/JavaBlog/Program_145684.html

Create your own process

创建流程

We have seen the process that comes with jBPM. Let’s now create a new process. Since the existing process is a web order process, lets create a process for returns of orders. This process will start with the buyer returning the item, then shipping receives the order. After that, the original order can be updated, and the money refunded. The process will then be complete.

我们已经学习了jBPM的流程. 现在, 让我们开始创建一个新的流程. 既然已经存在一个web订单流程, 我们就再创建一个订单回复流程. 这个流程在买家返回”item”时开始, 然后接收订单. 之后原始订单可以更新, 也可以退款. 最后此流程结束.

There are three ways to create a process with JBoss jBPM:

*       Draw the process with the visual process designer

*       Write the process in XML format

*       Dynamically create the process through Java business logic

JBoss jBPM有三种创建流程的方式:

*       用可视化的流程设计器绘制流程

*       用XML格式编写流程

*       通过Java业务逻辑动态地创建流程

For this guide, we will be using the visual process designer. The visual process designer is part of the JBoss IDE plugins to the Eclipse platform. This guide assumes that Eclipse is not currently on the workstation, and so we will download the bundled version of Eclipse with the JBoss IDE plugins. Go to the JBoss IDE download page (http://www.jboss.com/products/jbosside/downloads ), select the most recent GA version, and then select the bundled version of the zip. Unzip this download to your hard drive. There should be an eclipse directory where this was installed, with an eclipse.exe in it.

Use this to start eclipse. A dialog box will come up asking where to setup the workspace (Figure 26).

本指南使用可视化流程设计器来绘制流程. 可视化流程设计器是Eclipse平台的JBoss IDE插件之一. 本指南假设机器上还没有安装Eclipse, 所以我们将下载带JBoss IDE插件的捆绑式Eclipse版本. 打开JBoss IDE下载页http://www.jboss.com/products/jbosside/downloads, 选择最新GA版本(当前稳定的最新版本是JBoss Eclipse IDE1.6.0.GA), 然后选择捆绑式zip版本(windows平台用户选择JBossIDE-1.6.0.GA-Bundle-win32.zip, linux用户选择JBossIDE-1.6.0.GA-Bundle-linux-gtk.tar.gz). 解压zip文件到硬盘. 现在单击eclipse安装目录下的eclipse.exe文件, 出现对话框询问工作区(workspace)所在文件夹, 见图26.  

Figure 26. Workspace Selection dialog.

图26. 工作区选择对话框

This is where the project you create will be stored on the hard drive. Choose your workspace location, and select Ok. The next dialog will be the JBoss IDE welcome dialog (Figure 27).

我们创建的项目将存储在指定的文件夹内. 选择工作区地址, 单击OK. 出现JBoss IDE welcome对话框, 见图27.

Figure 27. JBoss IDE Welcome Dialog

图27. JBoss IDE welcome对话框

We don’t need to convert an existing project, so select Cancel. The main eclipse welcome page is shown (Figure 28).

我们不需要转换(convert)已有的项目, 所以单击Cancel. 出现eclipse欢迎页, 见图28.

Figure 28. Eclipse welcome page

图28. Eclipse 欢迎页.

Select the arrow icon in the upper right for the workbench. This will take us to the workbench view (Figure 29).

选择右上脚的肩头图标, 转到eclipse工作台(workbench)视图, 见图29.

Figure 29. Eclipse workbench view.

图29. Eclipse工作台(workbench)视图.

From here, we will create a process project and a process definition. First, select File, new, other… This will show a dialog with a list of projects to create (Figure 30).

下面, 我们开始创建一个流程项目和一个流程定义. 首先, 选择菜单栏中Fileànewàother, 弹出新建对话框, 见图30.

Figure 30. New project wizard selection page.

图30. 新建项目向导选择页.

Select Process Project under the JBoss jBPM folder and click Next. The new process project dialog is shown (Figure 31).

选择”JBoss jBPM”文件夹下的”Process Project”, 单击Next. 出现新建流程项目(process Project)对话框, 见图31.

Figure 31. New Process Project dialog.

图31. 新建流程项目对话框.

Enter the project name, and select Finish. The workbench view is shown again, now with the jBPMStartersProcess project in the left hand window (Figure 32).

输入项目名称, 此处指定” jBPMStartersProcess”, 选择Finish. 出现工作台视图, 见图32.

Figure 32. Workbench with jBPMStarters process.

图32. jBPMStartersProcess项目的工作台.

There is a process already defined in this project. Under the processes/simple folder, we see processdefinition.xml. We will create a new process definition in this same folder. Right click on the processes/simple folder, and select new, other… The new wizard shows again. This time select process definition under the JBoss jBPM folder (Figure 33). (Note: that the project layout is subject to change, and that the screenshots may not be consistent with these textual instructions).

在这个项目中已有一个定义好的流程, 流程定义文件processdefinition.xml在 processes/simple文件夹下. 现在, 我们在同一文件夹下创建一个新的流程, 右击processes/simple文件夹, 选择Newàother, 出现New对话框. 选择”JBoss jBPM”文件夹下的”Process Definition”. (注意, 不同版本的项目布局可能也不同, 所以截图可能跟本指南中的截图不一致.)

Figure 33. New project wizard dialog with Process Definition selected.

图23. 选择流程定义的新建项目向导对话框

Select Next, and the new process definition dialog shows (Figure 34).

单击Next, 出现创建流程定义对话框, 见图34.

Figure 34. New process definition dialog.

图34. 新建流程定义对话框.

Enter the name of the process (StartersProcess), and select Finish. The workbench shows again with the new process in the left hand navigation. In addition, the visual process designer now shows as well (Figure 35).

输入流程名” StartersProcess”, 单击Finish.

Figure 35. Workbench with visual process designer.

图35. 带可视化流程设计器的工作台

Now that we have created a blank process, we can draw the process out. This process will have:

*       a start state

*       a task node

*       a fork

*       two more task nodes

*       a join

*       an end state

Please see Figure 36 as to how these are laid out.

我们已经创建了一个空流程, 现在我们可以开始绘制流程了. 这个流程有:

*       一个开始状态

*       一个任务节点

*       一个分支(fork)

*       两个任务节点

*       一个连接(join)

*       一个结束状态

添加以上内容, 布局见图36.

Figure 36. Node layout for the new process.

图36. 新流程的节点布局.

Note that as you added the nodes, they automatically showed up in the outline on the right hand window. Now that we have nodes, we can add transitions. Click on the transition button, and draw transitions between the nodes. See Figure 37 for how this should look.

下面我们添加变迁(transition). 单击”transition”按钮, 分别单击开始节点和结束节点, 以此类推, 绘制好变迁之后的流程图见图37.

Figure 37. StartersProcess with transitions.

图37. 绘制完变迁后的StartersProcess

Note that the transitions also show up in the outline on the right hand window as well. From here, we will rename some of the nodes and transitions to make the process more readable. To do this, click on the node and the name will become enterable, or double click and use the dialog to enter the new name. See Figure 38 for the process with the names filled in.

现在, 我们来给某些节点和变迁重命名, 以使流程更具可读性. 单击节点选中它, 再单击一次, 就可以重命名此节点; 或者双击节点, 在弹出的对话框中也可以重命名节点; 或者在屏幕下方的属性(properties)窗口重新指定名称. 重命名之后的流程图见图38.

Figure 38. StartersProcess with the nodes and transitions renamed.

图38. 重命名节点和变迁之后的StartersProcess

The StartersProcess has nodes and transitions, so lets add tasks next. Right click on the Ship Order Return node, and select add task. A task will show in the right hand window under that node (Figure 39).

接下来我们来添加任务. 右击” Ship Order Return”节点, 选择”add task”. 一个task将显示在右边”Outline”窗口, 见图39.

Figure 39. Starters Process with a task added.

图39. 添加了一个task的Starters Process.

To customize this task, right click on the task and select properties. The properties dialog shows up (Figure 40).

右击此task, 选择”properties”, 出现”properties”对话框来定制此task, 见图40.

Figure 40. Task general properties dialog.

图40. task general properties对话框.

The general properties dialog has the name for the task. Enter Send Item as the task name. Click on Controller to add a process variable to this task (Figure 41).

在Name后的文本框中输入” Send Item”, 单击左边窗口的”Controller”, 出现图41所示对话框.

Figure 41. Task controller dialog.

图41. Task controller对话框.

Click Add to add a process variable. Change the name to “tracking number”, and select the read, write and required flags (Figure 42).

单击”Add”按钮, 第一列”name”值改为” tracking number”, 选中” read”,” write”和” required”, 见图42.

Figure 42. Task Controller dialog filled in.

图42. Task Controller对话框.

Click OK to finish defining this task. We will now repeat the process to create the other tasks in the process, and assign process variables to each. Right click on the Receive Return node, and add a task. Right click on the task and select properties. Change the name of the task to Receive Item, and add two process variables: “tracking number” (this time only select the read option), and “received date” with read, write and required selected (Figure 43).

单击”OK”结束定义此task. 现在我们重复刚才的过程创建其他流程task并给每个task指派流程变量. 右击” Receive Return”节点, 选择”Add Task”. 右击刚创建的task, 选择”properties”. Task重命名为” Receive Item”, 添加两个流程变量” tracking number”(只选中read)和” received date”(选中read,write和required), 如图43所示.

Figure 43. Controller dialog for the Receive Return task.

图43. “Receive Return” task的Controller对话框.

Click OK to finish defining this task. Right click on the Update Order node, and add a task. Right click on the task and select properties. Change the name of the task to Send Updated Order, and add the process variable “address” with read, write and required selected (Figure 44).

单击”OK”结束流程定义. 右击” Update Order”节点, 选择”Add Task”. 右击task, 选择” properties”. Task重命名为” Send Updated Order”, 添加流程变量”address”, 选中read,write和required, 如图44所示.

Figure 44. Controller dialog for the Send Updated Order task.

图44. “Send Updated Order”task 的Controller对话框.

Click OK to finish defining this task. Right click on the Return Money node, and add a task. Right click on the task and select properties. Change the name of the task to Update Books, and add the process variable “amount” with read, write and required selected (Figure 45).

单击”OK”完成task定义. 右击”Return Money”节点, 选择”Add Task”. 右击task, 选择”properties”. Task重命名为” Update Books”, 添加流程变量”amount”, 选中read, write和required, 如图45.

Figure 45. Controller dialog for the Update Books task.

图45. “Updated Books” task 的Controller对话框.

Click OK to complete the task. The outline on the right hand side now shows all four tasks (Figure 46).

单击”OK” 完成task. 现在所有task都在屏幕右边的outline窗口显示, 见图46.

Figure 46. StartersProcess with tasks defined.

图46. 定义了task的StartersProcess.

The tasks have been defined, but we still need to define who should do each task. We will do this by first creating swimlanes, then assigning tasks to the swimlanes. Click on Swimlanes at the bottom of the process diagram to view the swimlanes page (Figure 47).

任务(task)已经定义, 接下来我们需要定义每一个任务应由谁来执行. 我们首先来创建甬道(swimlane), 然后指派任务给甬道. 单击流程图下方的”Swimlanes”页签, 工作台中将显示甬道页, 见图47.

Figure 47. Swimlanes dialog.

图47. 甬道(Swimlanes)对话框.

Click Add to create an empty swimlane (Figure 48).

单击”Add”创建一个新甬道, 见图48.

Figure 48. Empty swimlane created.

图48. 一个空甬道被创建.

Enter the name of the swimlane as Shipping, and make the assignment type expression. A box appears for the expression. We will do a very simple assignment to a user that has already been setup. Enter “user(grover)” to assign this swimlane to grover (Figure 49).

输入甬道名字”Shipping”, “Assignment type”选择” Expression”, 出现一个” Expression”文本框. 输入” user(grover)”, 则此甬道指派给了grover, 见图49.

Figure 49. Shipping swimlane defined.

图49. 定义的Shipping甬道.

Click add again, and define a swimlane for Sales that will go to “user(ernie)” (Figure 50).

再单击”Add”, 定义”Sales”甬道并把甬道指派给“user(ernie)”, 见图50.

 

Figure 50. Sales swimlane defined.

图50. 定义的Sales甬道.

Click add again, and define a swimlane for Accounting that will go to “user(bert)” (Figure 51).

再次单击”Add”, 定义” Accounting”甬道并把甬道指派给“user(bert)”, 见图51.

Figure 51. Accounting swimlane defined.

图50. 定义的Accounting甬道.

Now that the swimlanes are defined, tasks can be assigned to the swimlanes. Right click on the Receive Item task and select properties. Select the Assignment link on the left hand side to show the assignment dialog. Select Swimlane as the assignment type, and then choose the Shipping swimlane (Figure 52).

现在甬道定义完毕, task可以指派给甬道了. 右击” Receive Item”任务, 选择” properties”. 单击左边的”Assignment”, “assignment type”选择” Swimlane”, 然后选择” Shipping”甬道, 见图52.

Figure 52. Shipping swimlane chosen for task Receive Item.

图52. 为” Receive Item” task选择” Shipping” 甬道.

Click OK. Right click on the Send Updated Order task and select properties. Select the Assignment link on the left hand side to show the assignment dialog. Select Swimlane as the assignment type, and then choose the Sales swimlane (Figure 53).

单击”OK”. 右击 “Send Updated Order” task, 选择” properties”. 单击左边的”Assignment”, “assignment type”选择” Swimlane”, 然后选择 ”Sales” 甬道, 见图53.

Figure 53. Sales swimlane chosen for task Send Updated Order.

图53. 为” Send Updated Order” task选择” Sales” 甬道.

Click OK. Right click on the Update Books task and select properties. Select the Assignment link on the left hand side to show the assignment dialog. Select Swimlane as the assignment type, and then choose the Accounting swimlane (Figure 54).

单击”OK”. 右击 “Updated Books” task, 选择” properties”. 单击左边的”Assignment”, “assignment type”选择” Swimlane”, 然后选择 ” Accounting” 甬道, 见图54.

Figure 54. Accounting swimlane chosen for task Update Books.

图54. 为” Update Books” task选择” Accounting” 甬道.

Click OK. We have now defined the process by adding nodes and transitions, then adding tasks and swimlanes. Click save to save the process definition. We are now ready to deploy the process definition to JBoss jBPM.

单击”OK”. 现在我们添加了节点和变迁, 也添加了任务和甬道. 单击屏幕左上方工具栏中的”save”按钮保存流程定义. 接下来我们就可以把流程定义部署到JBoss jBPM中了.

 

Deploy your process to JBoss jBPM

把流程部署到JBoss jBPM

首先, 确定jBPM服务器已经运行. 然后单击屏幕下方的”Deployment”, 出现图55中的页面. 确定所有参数跟图55相同. 如果JBoss jBPM运行在其他机器上, Server Name 就不是”localhost”要改成那台机器的IP.

图 55. Deployment页.

单击”Deployment”页中的”Test Connection…” 显示如下图:

单击”Deployment”页中的”Deploy process archive…”, 弹出图56所示对话框.

Figure 56. Deployment Successful dialog.

Now that the process is deployed, let’s use the sample web application to run through the process. Bring up Internet Explorer and go to the following URL: http://localhost:8080/jbpm . Log in as “cookie monster” and there are now two options under Create New Process Execution (Figure 57).

流程已经部署成功, 我们打开IE浏览器, 在地址栏中输入http://localhost:8080/jbpm, 以“cookie monster”身份登录, 现在”Create New Process Execution” 列表中已经有两个选项了, 如图57所示.

Figure 57. Home page showing StartersProcess task.

Click the Send Item task. The process definition we created now shows on the page, along with the process variable we created (Figure 58).

单击” Send Item”. 我们创建的流程定义和流程变量显示在页面中, 见图58.

Figure 58. Task page for StartersProcess showing the tracking number process variable.

From here, you can run through the rest of the process execution.

现在, 你就可以自己继续执行流程了.

Congratulations! In this guide, you have:

*       Downloaded and unzipped the JBoss jBPM Starter Kit

*       Executed the JBoss jBPM engine

*       Interacted with the Websale sample process

*       Managed a process that is being executed

*       Created your own process

*       Deployed your process to JBoss jBPM

Congratulations! 通过本指南, 你已经:

*       下载并解压了JBoss jBPM Starter Kit

*       执行了JBoss jBPM 引擎

*       执行了Websale 示例流程

*       管理了正在执行的流程

PicEx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值