<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    網路冷眼@BlogJava

    熙熙攘攘一閑人 以冷靜的眼光觀察技術
    posts - 88, comments - 193, trackbacks - 0, articles - 28
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    1.5.4 Implementing a simple book order process (實現一個簡單的訂書流程)(上)

    It would be a bit of a shame to stop chapter 1 with an example that contains just a start and an end event. So let’s enhance our simple book order process with a script task and a user task, so we can see a bit of action on the Activiti engine. First the script task will print an ISBN number that will be been given as input to the book order process when started. Then a user task will be used to handle the book ordering manually. So this is not the most efficient process, but it’s good for learning about BPMN 2.0 and Activiti.

    用一個只包含開始和結束事件的示例草草了結本章,那會讓人感到羞恥。所以讓我們用腳本任務和用戶任務來加強我們簡單的訂書流程,這樣我們能看見Activiti 引擎的一些動作。首先腳本任務將打印ISBN好,當啟動時將ISBN數字作為訂書流程的輸入。然后采用用戶任務手動處理訂書流程。所以這并不是最有效的流程,但是對于學習BPMN 2.0和Activiti大有裨益。

    Activiti provides the possibility to use the scripting language you want, but Groovy is supported by default. So we’ll use a line of Groovy to print the ISBN process variable. In code listing 1.3 a revised version of the book order process of code listing 1.1 is shown.

    盡管Activiti為使用腳本語言提供了可能性,但是缺省,只提供對Groovy的支持。所以,我們將使用一行Groovy打印ISBN變量。代碼列表1.1的一個修訂的訂書流程如代碼列表1.3所示。

    Listing 1.3 A book order process with a script and user task

    <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"  
        targetNamespace
    ="http://www.bpmnwithactiviti.org"> 
      
    <process id="bookorder" name="bookorder"> 
        
    <startEvent id="startevent1" name="Start"/> 
        
    <scriptTask id="scripttask1"                                         #A 
                    name
    ="Validate order" 
                    scriptFormat
    ="groovy"> 
          
    <script> 
            out:print "validating order for isbn " + isbn + "\n";            #1 
          
    </script> 
        
    </scriptTask> 
        
    <sequenceFlow id="sequenceflow1" name="Validate order"  
            sourceRef
    ="startevent1" targetRef="scripttask1"/> 
        
    <userTask id="usertask1" name="Complete order">                      #2 
          
    <documentation>book order user task</documentation> 
          
    <potentialOwner> 
            
    <resourceAssignmentExpression> 
              
    <formalExpression>sales</formalExpression>                     #B 
            
    </resourceAssignmentExpression> 
          
    </potentialOwner> 
        
    </userTask> 
        
    <sequenceFlow id="sequenceflow2" name="Sending to management" 
            sourceRef
    ="scripttask1" targetRef="usertask1"/> 
        
    <endEvent id="endevent1" name="End"/> 
        
    <sequenceFlow id="sequenceflow3" name="Ending process" 
            sourceRef
    ="usertask1" targetRef="endevent1"/> 
      
    </process> 
    </definitions> 
    #A Definition of a script task 
    #B Assign task to sales group 
    #1 Print the isbn 
    #2 Definition of a user task 

     

    With the two additional tasks added to the process definition, the number of lines of the XML file grows quite a bit. In the next chapter we’ll show the Activiti designer, which abstract you from the XML file when designing the process.

    隨著兩項額外的任務添加到進程的定義,該行數XML的文件增長了不少。下一章我們將討論Activiti設計器,當設計流程時時,讓您從XML文件脫身。

    The script task contains a out:print variable #1, which is a reserved word within the Activiti script task for printing text to the system console. Also notice that the isbn variable can be used directly in the script code without any additional programming.

    腳本任務包含了out:print 變量 #1,它是Activiti腳本任務的保留字,它將文本打印到任務控制臺。也要注意在腳本里可以直接使用isbn變量,而不需任何額外的編程。

    The user task #2 contains a potential owner definition, which means that the task can be claimed and completed by users that are part of the group sales. When we run this process in a minute, we can see in the Activiti Explorer that this user task is available in the task list for the user kermit, who is part of the sales group.

    用戶任務#2包括一個潛在的用戶定義,它意味著Sales組的用戶可以領取和完成任務。當我們運行這個流程一會兒,在Activiti Explorer里,對于用戶kermit的任務列表,有任務可用,因為kermit是sales組的人。

    Now that we added more logic to the process, we also need to change our unit test. One thing we need to add is a process variable isbn when starting the process. And to test if the user task is created, we need to query the Activiti engine database for user tasks that can be claimed by the user kermit. Let’s take a look at the changed unit test in code listing 1.4.

    既然我們把更多的邏輯加入到流程,那么也需要改變我們的單元測試。。當啟動流程時,需要增加的一件事是增加流程變量isbn。為了測試是否建立了用戶任務,我們需要查詢Activiti引擎數據庫能夠由用戶kermit領取的任務。讓來看看代碼列表1.2里的變化的單元測試。

    Listing 1.4 A unit test with a process variable and user task query

    public class BookOrderTest { 
      @Test 
      
    public void startBookOrder() { 
        ProcessEngine processEngine 
    = new ProcessEngineBuilder()  
            .configureFromResource(
    "activiti.cfg.xml")  
            .buildProcessEngine();  
        RuntimeService runtimeService 
    =  
            processEngine.getRuntimeService();  
        RepositoryService repositoryService 
    =  
            processEngine.getRepositoryService(); 
        TaskService taskService 
    = processEngine.getTaskService();            #1 
        repositoryService.createDeployment() 
            .addClasspathResource(
    "bookorder.bpmn20.xml"
            .deploy(); 
        Map
    <String, Object> variableMap = new HashMap<String, Object>(); 
        variableMap.put(
    "isbn""123456"); 
        ProcessInstance processInstance 
    =                                    #2 
            runtimeService.startProcessInstanceByKey(                        #
    2 
                
    "bookorder", variableMap);                                   #2 
        assertNotNull(processInstance.getId()); 
        System.out.println(
    "id " + processInstance.getId() + " "  
            
    + processInstance.getProcessDefinitionId()); 
        List
    <Task> taskList = taskService.createTaskQuery()                  #A 
            .taskCandidateUser(
    "kermit")                                     #A 
            .list()                                                          #A 
        assertEquals(taskList.size(), 
    1); 
        
    for(Task task : taskList) { 
          System.out.println(
    "found task " + task.getName()); 
        } 
      } 

    #
    1 Get a TaskService instance 
    #
    2 Start a process with a variable 
    #A Find tasks available 
    for kermit 

     

    The BookOrderTest unit test has been changed to start a process instance with a map of variables #2 that contains one variable with a name of isbn and a value of 123456. In addition, when the process instance has been started a TaskService instance #1 is used to retrieve the tasks available to claim by the user kermit. Because there is only one process instance running with one user task we test that the number of tasks retrieved is 1.

    BookOrderTest單元測試已經用一個變量#2的map而變化之后啟動了一個流程實例。這個馬屁變量包含名為isbn,值為123456。另外,當流程變量已經啟動TaskService實例#1時,用來檢索用戶kermit所領取的任務。因為只有一個流程變量運行一個用戶任務,所以檢索任務為1.

    With the book order process in place and a new unit test we can run the unit test to see if our changes work. In the console you should see a similar output like:

    因為訂書流程準備就緒,運行一個新的單元測試來檢查我們的改變是否發生作用。在控制臺,您應該看到如下的輸出:

    validating order for isbn 123456

    id 112 bookorder:1

    found task Complete order

    The first line is printed by the Groovy script task in the running process instance. The last line confirms that one user task is available for claim for the user kermit. Because a user task is created we should be able to see this task in the Activiti Explorer. Confirm that Tomcat has been started as part of the installation procedure. If this is not the case you canstart Tomcat with the Ant build script in the setup directory with the following command:

    由運行的流程實例的Groovy腳本任務打印第一行。最后確定用戶Kermit可領取的用戶任務。因為已建立一個用戶任務,所以我們應該在Activiti Explorer里看見這個任務。確認Tomcat已經作為安裝過程的一部分已經啟動。如果不是這種情況,你能夠用setup目錄下的Ant 構建以下面的命令啟動Tomcat:

    ant tomcat.start

    主站蜘蛛池模板: 亚洲另类图片另类电影| 国产成人毛片亚洲精品| eeuss影院www天堂免费| 亚洲成人动漫在线观看| 超清首页国产亚洲丝袜| 女人18毛片免费观看| 国产免费一区二区三区在线观看| 亚洲伊人色一综合网| 亚洲大尺度无码专区尤物| 五月婷婷亚洲综合| 无码国产精品一区二区免费式直播| 日本精品久久久久久久久免费 | 亚洲香蕉免费有线视频| 亚洲国产精品网站在线播放| 亚洲成A人片在线观看无码3D| 男女男精品网站免费观看| 亚洲AV无码一区二区三区电影| 久久99国产亚洲精品观看| 亚洲愉拍99热成人精品热久久| 亚洲AV伊人久久青青草原 | 最新精品亚洲成a人在线观看| 国产一级淫片免费播放| 免费看www视频| 国产hs免费高清在线观看| 免费国产精品视频| 免费国产在线观看| 亚洲无线一二三四区手机| 久久精品国产精品亚洲艾草网美妙| www.亚洲精品| 国产亚洲一区二区三区在线| 亚洲天天在线日亚洲洲精| 亚洲精品福利网站| 亚洲AV无码精品国产成人| 国产亚洲精品AAAA片APP | 免费人成年激情视频在线观看| 免费播放特黄特色毛片| 亚洲av永久无码制服河南实里| 亚洲免费精彩视频在线观看| 亚洲AV日韩综合一区尤物| 特黄特色的大片观看免费视频| 国产免费爽爽视频在线观看 |