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

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

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

    網(wǎng)路冷眼@BlogJava

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

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

    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.

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

    隨著兩項額外的任務添加到進程的定義,該行數(shù)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組的用戶可以領(lǐng)取和完成任務。當我們運行這個流程一會兒,在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引擎數(shù)據(jù)庫能夠由用戶kermit領(lǐng)取的任務。讓來看看代碼列表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單元測試已經(jīng)用一個變量#2的map而變化之后啟動了一個流程實例。這個馬屁變量包含名為isbn,值為123456。另外,當流程變量已經(jīng)啟動TaskService實例#1時,用來檢索用戶kermit所領(lǐng)取的任務。因為只有一個流程變量運行一個用戶任務,所以檢索任務為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:

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

    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可領(lǐng)取的用戶任務。因為已建立一個用戶任務,所以我們應該在Activiti Explorer里看見這個任務。確認Tomcat已經(jīng)作為安裝過程的一部分已經(jīng)啟動。如果不是這種情況,你能夠用setup目錄下的Ant 構(gòu)建以下面的命令啟動Tomcat:

    ant tomcat.start

    主站蜘蛛池模板: 91久久精品国产免费一区| 亚洲AV区无码字幕中文色| 亚洲人成免费电影| 本免费AV无码专区一区| 亚洲AV综合色区无码一二三区| 亚洲成人精品久久| 成人午夜亚洲精品无码网站| 四虎影视在线永久免费观看| 可以免费看黄的网站| 香蕉免费一区二区三区| a级毛片免费网站| 无码天堂亚洲国产AV| 中文字幕亚洲精品无码| a毛片在线看片免费| 国产午夜亚洲精品不卡电影| 亚洲欧美日韩综合久久久| 免费又黄又爽又猛的毛片| 一个人免费观看www视频| 亚洲AV无码片一区二区三区| 国产成人精品亚洲2020| gogo全球高清大胆亚洲| 久久爰www免费人成| 成在人线av无码免费高潮喷水| 一级毛片免费在线| 未满十八私人高清免费影院| 国产亚洲综合一区二区三区| 亚洲精品无码久久久久A片苍井空 亚洲精品无码久久久久YW | 国产大片91精品免费观看不卡| 亚洲国产av玩弄放荡人妇 | 1000部夫妻午夜免费| 无码精品一区二区三区免费视频 | 久久精品国产亚洲AV果冻传媒| 久久久亚洲精品蜜桃臀| 亚洲精品国产日韩无码AV永久免费网 | 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 国产午夜亚洲精品午夜鲁丝片| 久久精品国产亚洲Aⅴ蜜臀色欲| 亚洲色图综合在线| 国产精品亚洲美女久久久 | 国产一级婬片A视频免费观看| 两性色午夜视频免费播放|