1. Overview
1.概述
In our previous articles (based on Activiti API with Java and Spring), we saw how to manage processes programmatically. If we want to set up a demo, along with the UI for Activiti, we have two webapps which will allow us to do so in just a few minutes.
在我们以前的文章中(基于Activiti API与Java和Spring),我们看到如何以编程方式管理流程。如果我们想建立一个演示,连同Activiti的用户界面,我们有两个webapps,可以让我们在短短几分钟内完成。
activiti-app offers a user interface through which a user can perform any identity management and task management related operations, create users and groups.
activiti-app提供了一个用户界面,用户可以通过该界面执行任何身份管理和任务管理相关的操作,创建用户和组。
Similarly, activiti-rest is a webapp that provides the REST API for performing any operation on a process, task, process, etc.
同样,activiti-rest是一个提供REST API的webapp,用于对进程、任务、流程等执行任何操作。
In this article, we’ll look into how to use these webapps, and what functionalities they provide.
在这篇文章中,我们将研究如何使用这些网络应用程序,以及它们提供了哪些功能。
2. Downloads
2.下载
We can download the war files for both webapps from Activiti Website itself.
我们可以从Activiti网站本身下载两个webapp的war文件。
For v6.0.0, we can just download the activiti-6.0.0.zip, extract it, and the war files can be found in activiti-6.0.0/wars directory.
对于6.0.0版本,我们只需下载activiti-6.0.0.zip,解压缩,war文件可以在activiti-6.0.0/wars目录中找到。
3. Activiti Kickstart App
3.Activiti Kickstart应用程序
We’ll need a working Java runtime and an Apache Tomcat installation to deploy the app. Any web container would work, but Activiti is tested on Tomcat primarily.
我们需要一个有效的Java运行时和Apache Tomcat安装来部署该应用程序。任何网络容器都可以使用,但Activiti主要在Tomcat上进行测试。
Now, we need just to deploy the war on Tomcat and access it using http://localhost:8080/activiti-app.
现在,我们只需要在Tomcat上部署战争,并使用http://localhost:8080/activiti-app访问它。
The home page should look like this:
主页应该看起来像这样。
3.1. Database
3.1.数据库[/strong]
By default, it uses the H2 in-memory database. If we want to change the DB configuration, we can check out the code and modify the activiti-app.properties file.
默认情况下,它使用H2内存数据库。如果我们想改变DB配置,我们可以查看代码并修改activiti-app.properties文件。
After doing this, we need to re-generate the war file, which can be done by running the start.sh script. This will build the activiti-app along with the required dependencies.
完成这些工作后,我们需要重新生成战争文件,这可以通过运行start.sh脚本来完成。这将构建activiti-app以及所需的依赖项。
3.2. Kickstart App
3.2.启航应用程序
When we click on the Kickstart App, we get the options for working with a Process. We can create/import processes and run them from here.
当我们点击Kickstart应用程序时,我们得到了使用进程的选项。我们可以从这里创建/导入进程并运行它们。
Let’s create a small process that has a single User Task, which receives a message from a user. Once in the Kickstart App, to create a process select the Processes tab, and click on Create Process:
让我们创建一个小进程,它有一个用户任务,接收一个用户的信息。一旦进入Kickstart应用程序,要创建一个进程,选择进程标签,并点击创建进程。
Process editor will open where we can drag and drop various symbols for start events, various types of tasks and end events to define a Process.
进程编辑器将被打开,我们可以拖放各种符号,用于启动事件、各种类型的任务和结束事件,以定义一个进程。
As we’re adding a User Task to our process, we need to assign it to someone. We can do it by clicking on assignments from the options for this task and selecting an Assignee.
由于我们要在流程中添加一个用户任务,我们需要将其分配给某人。我们可以通过点击该任务的选项中的分配,并选择一个受让人来完成。
For simplicity, let’s assign the task to the process initiator:
为了简单起见,让我们把任务分配给进程发起人。
We also want this User Task to get an input message from the user. To achieve this, we need to associate a Form, with a single text field, with this task.
我们还希望这个用户任务能从用户那里获得一个输入信息。为了实现这一点,我们需要将一个带有单个文本字段的表格与该任务相关联。
Select the User Task and select Referenced Form. Currently, there’s no Form associated with the task, so click on New Form, and add the required details:
选择用户任务并选择参考表格。目前,没有与该任务相关的表格,所以点击新表格,并添加所需细节。
After this, it’ll take us to the Forms section where we can drag and drop various fields that we want in our form and also set labels for them:
之后,它将带我们到表格部分,在那里我们可以拖放我们想在表格中使用的各种字段,还可以为它们设置标签。
Notice that we’ve ticked the Required, which means the User task cannot complete without entering the Message.
请注意,我们已经勾选了Required,,这意味着User任务在没有输入Message时无法完成。
Once done, we’ll save it and go to Apps tab. To be able to run the process we created, we need to create a Process App.
一旦完成,我们将保存它并进入Apps标签。为了能够运行我们创建的进程,我们需要创建一个进程应用程序。
In the Process App, we can add one or more Process Definitions. After doing this, we need to publish this App, so that the Processes are made available to other users:
在进程应用程序中,我们可以添加一个或多个进程定义。做完这些后,我们需要发布这个应用程序,以便将进程提供给其他用户。
3.3. Task App
3.3.任务应用程序
In the Task App, there’re two tabs: Tasks – for currently running tasks, and Processes – for currently running Processes.
在任务应用程序中,有两个标签。任务 – 当前正在运行的任务,以及进程 – 当前正在运行的进程。
Once we click on the Start Process in Processes tab, we get the list of available processes that we can run. From this list, we’ll select our process and click on the start button:
一旦我们点击Processes标签中的Start Process,我们就会得到我们可以运行的可用进程列表。从这个列表中,我们将选择我们的进程并点击启动按钮。
Our process contains only a single task, and it is a User Task. Hence, the process is waiting for a user to complete this task. When we click on the task that the process is waiting on, we can see the form that we created:
我们的进程只包含一个任务,而且是一个用户任务。因此,该进程正在等待一个用户来完成这个任务。当我们点击进程正在等待的任务时,我们可以看到我们创建的表单。
If we click on Show Diagram, it’ll not only show us the Process diagram but also highlight the tasks that are completed and the one which is pending. In our case, the User Task is still pending, which is highlighted:
如果我们点击显示图,它不仅会显示流程图,还会突出显示已完成的任务和待完成的任务。在我们的例子中,用户任务仍在等待中,它被突出显示。
To complete this task, we can click on the Complete button. As mentioned earlier we’ll need to enter the Message, as we have kept it mandatory. Hence, after entering the Message, we can Complete the task.
要完成这项任务,我们可以点击Complete button.如前所述,我们需要输入Message,,因为我们保留了它的强制性。因此,在输入Message,后,我们可以Complete任务。
3.4. Identity Management App
3.4.身份管理应用程序
Apart from managing a process, we’ve got an Identity Management App, that allows us to add users and groups. We can also define roles for the users.
除了管理一个流程之外,我们还有一个身份管理应用程序,它允许我们添加用户和组。我们还可以为用户定义角色。
4. Activiti REST
4.Activiti REST
Activiti provides a REST API for the Activiti Engine that can be installed by deploying the activiti-rest.war file to a servlet container like Apache Tomcat.
Activiti为Activiti引擎提供了一个REST API,可以通过将activiti-rest.war文件部署到Apache Tomcat等servlet容器中来安装。
By default, the Activiti Engine will connect to an in-memory H2 database. Just like we saw in activiti-app, here we can change the database settings in the db.properties file in the WEB-INF/classes folder and recreate the war file.
默认情况下,Activiti引擎将连接到内存中的H2数据库。就像我们在activiti-app中看到的那样,这里我们可以在WEB-INF/classes文件夹中的db.properties文件中改变数据库设置,并重新创建war文件。
With the app up and running, we can use this base URL for all the requests:
随着应用程序的启动和运行,我们可以使用这个基础URL来处理所有的请求。
http://localhost:8080/activiti-rest/service/
By default, all REST resources require a valid Activiti user to be authenticated. Basic HTTP access authentication should be used for every REST call.
默认情况下,所有的REST资源都需要一个有效的Activiti用户来进行认证。每个REST调用都应使用基本HTTP访问认证。
4.1. Creating and Running a Process
4.1.创建和运行一个进程
To create a process, first, we need the BPMN file for our process. We can either create the file as described in our previous articles based on Activiti with Java, or it can be downloaded from the Kickstart App’s Process section.
要创建一个流程,首先,我们需要流程的BPMN文件。我们可以按照以前的文章中描述的方式,基于Activiti with Java创建该文件,或者从Kickstart App的流程部分下载。
We need to make a POST request, along with the contentType: multipart/form-data, where we’ll upload the BPMN file for our new process:
我们需要发出一个POST请求,以及contentType: multipart/form-data,在这里我们将为我们的新流程上传BPMN文件。
POST repository/deployments
When we make this call by passing the BPMN file for the process we created, it’ll give the following output:
当我们通过传递我们创建的流程的BPMN文件来进行这个调用时,它将给出以下输出。
{
"id": "40",
"name": "user_msg.bpmn20.xml",
"deploymentTime": "2017-10-04T17:28:07.963+05:30",
"category": null,
"url": "http://localhost:8080/activiti-rest/service/repository/deployments/40",
"tenantId": ""
}
Now, we can see our process definition listed, if we get all the process definitions:
现在,我们可以看到我们的流程定义被列出,如果我们得到所有的流程定义。
GET repository/process-definitions
Next, we can run this process using the processKey that we have mentioned in the BPMN file:
接下来,我们可以使用BPMN文件中提到的processKey运行这个流程。
POST /runtime/process-instances
With this request body:
有了这个请求体。
{
"processDefinitionKey":"user_msg"
}
The response will be:
回复将是。
{
"id": "44",
"url": "http://localhost:8080/activiti-rest/service/runtime/process-instances/44",
"businessKey": null,
"suspended": false,
"ended": false,
"processDefinitionId": "user_msg:1:43",
"processDefinitionUrl": "http://localhost:8080/activiti-rest/service/repository/process-definitions/user_msg:1:43",
"processDefinitionKey": "user_msg",
//other details...
}
We can see the diagram of our running process using the id of the process instance returned with the previous response:
我们可以使用前一个响应返回的进程实例的id来查看我们正在运行的进程的图示。
GET runtime/process-instances/44/diagram
As mentioned earlier, the process is waiting for the User Task to finish, and hence it is highlighted in the diagram:
如前所述,该进程正在等待用户任务的完成,因此在图中被突出显示。
4.2. Completing a Task
4.2.完成一项任务
Let’s now take a look at our pending task using:
现在让我们来看看我们的待办任务使用情况。
GET runtime/tasks
The response will have a list of pending tasks. Currently, there’s only one task – our User Task:
响应将有一个待办任务的列表。目前,只有一个任务–我们的User Task。
{
"data": [
{
"id": "49",
"url": "http://localhost:8080/activiti-rest/service/runtime/tasks/49",
"owner": null,
"assignee": "$INITIATOR",
"delegationState": null,
"name": "User Input Message",
"description": "User Task to take user input",
"createTime": "2017-10-04T17:33:07.205+05:30",
"dueDate": null,
// other details...
}
}
At last, let’s complete this task using the task id 49:
最后,让我们使用任务id 49完成这项任务。
POST runtime/tasks/49
This is a POST request, and we need to send the action field indicating what we want to do with the task. We can “resolve”, “complete” or “delete” a task. Also, we can pass an array of variables, required by the task to complete.
这是一个POST请求,我们需要发送action字段,表明我们要对该任务做什么。我们可以 “解决”、”完成 “或 “删除 “一项任务。此外,我们还可以传递一个变量数组,这是任务完成所需的。
In our case, we’ve to pass a field “message”, which is the is of out User Message text field. So our request body is:
在我们的例子中,我们必须传递一个字段 “message”,它是用户信息文本字段。所以我们的请求体是。
{
"action": "complete",
"variables": [{
"name": "message",
"value": "This is a User Input Message"
}]
}
5. Conclusion
5.总结
In this article, we discussed how we could use the Activiti Kickstart App and the provided REST API.
在这篇文章中,我们讨论了如何使用Activiti Kickstart App和提供的REST API。
More information about activiti-rest can be found in the User Guide, and activiti-app details can be found in the documentation by Alfresco.
关于activiti-rest的更多信息可在用户指南中找到,而activiti-app的详细信息可在Alfresco的文档中找到。