最新JBoss jBPM 3.1 開始指南之---創建流程和部署流程

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 示例流程

*       管理了正在執行的流程

*       創建了你自己的流程

*       部署了你自己的流程在JBoss jBPM上

Here are some further resources to use when exploring JBoss jBPM:

*       JBoss jBPM User Guide 3.1 http://docs.jboss.com/jbpm/v3/userguide/

*       JBoss jBPM Javadoc 3.1 http://docs.jboss.com/jbpm/v3/javadoc/

*       JBoss jBPM Process Designer Getting Started 3.0 http://docs.jboss.com/jbpm/v3/gpd/

*       JBoss jBPM Training http://www.jboss.com/services/training/jbpm

*       JBoss jBPM Book (Upcoming)

這裏是進一步學習JBoss jBPM的資料:

*       JBoss jBPM User Guide 3.1 http://docs.jboss.com/jbpm/v3/userguide/

*       JBoss jBPM Javadoc 3.1 http://docs.jboss.com/jbpm/v3/javadoc/

*       JBoss jBPM Process Designer Getting Started 3.0 http://docs.jboss.com/jbpm/v3/gpd/

*       JBoss jBPM Training http://www.jboss.com/services/training/jbpm

*       JBoss jBPM Book (Upcoming)

 
發佈了11 篇原創文章 · 獲贊 6 · 訪問量 27萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章