Activiti 用户界面 Spring 应用集成

Activiti User interface Spring App integration

我有以下 Activiti 6 应用程序 运行 来自官方提供的 .WAR 文件。已成功将这些部署到我的本地主机

到目前为止,我可以使用activiti-app生成BPMN文件并使用该接口启动应用程序。到目前为止一切顺利。

然而,我想做的是编写我自己的 Spring 应用程序,但能够使用 activiti UI 应用程序查看它们 运行。

因此查看 baeldung-activiti 教程。您可以启动应用程序。

@GetMapping("/start-process")
public String startProcess() {
    runtimeService.startProcessInstanceByKey("my-process");
    return "Process started. Number of currently running process instances = " + runtimeService.createProcessInstanceQuery().count();
}

以上 returns 每次到达端点时都会增加一个值。

我的问题是这样的。

如何使用 activiti 工具(运行 on localhost:8008)查看进程。我如何 link 独立 java 应用程序。 (运行 在 localhost:8081 上)与 Activiti ui 接口?

如果您配置了 activity-rest 和 运行,那将非常容易。 REST API 已记录 here

因此您只需对正确的 API 端点执行 Web 服务调用。例如,要列出您需要向 repository/process-definitions 端点发出 GET 请求的所有进程。

注意:其余 API 使用基本身份验证。

public void loadProcesses(){
    // the username and password to access the rest API (same as for UI)
    String plainCreds = "username:p@ssword";
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);
    RestTemplate restTemplate = new RestTemplate();
    HttpEntity<String> request = new HttpEntity<>(headers);
    ResponseEntity<String> responseAsJson = restTemplate.exchange("http://localhost:8080/activiti-rest/repository/process-definitions", HttpMethod.GET, request, String.class);
}

以下 API 调用的响应将是 JSON 类似

{
  "data": [
  {
    "id" : "oneTaskProcess:1:4",
    "url" : "http://localhost:8182/repository/process-definitions/oneTaskProcess%3A1%3A4",
    "version" : 1,
    "key" : "oneTaskProcess",
    "category" : "Examples",
    "suspended" : false,
    "name" : "The One Task Process",
    "description" : "This is a process for testing purposes",
    "deploymentId" : "2",
    "deploymentUrl" : "http://localhost:8081/repository/deployments/2",
    "graphicalNotationDefined" : true,
    "resource" : "http://localhost:8182/repository/deployments/2/resources/testProcess.xml",
    "diagramResource" : "http://localhost:8182/repository/deployments/2/resources/testProcess.png",
    "startFormDefined" : false
  }
  ],
  "total": 1,
  "start": 0,
  "sort": "name",
  "order": "asc",
  "size": 1
 }