你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

适用于 Java 的 Azure Purview 工作流客户端库 - 版本 1.0.0-beta.2

工作流是用户可以在 Microsoft Purview 中创建的,用于验证和协调对其数据实体执行的 CUD(创建、更新、删除)操作的自动化、可重复业务流程。 启用这些流程后,组织可以跟踪更改,强制要求符合策略,并在其整个数据格局中确保数据的质量。

使用 Purview 工作流的客户端库可以:

  • 管理工作流
  • 提交用户请求并监视工作流运行
  • 查看和响应工作流任务

有关如何使用工作流的更多详细信息,请参阅 服务文档

入门

先决条件

身份验证

由于工作流服务使用 Azure Active Directory (AAD) 持有者令牌进行身份验证和标识,因此应将电子邮件地址编码到令牌中,以便在使用工作流时发出通知。 建议将 Azure 标识 库与 UsernamePasswordCredential 一起使用。 将 Azure 标识 库与工作流配合使用之前,应注册 应用程序 并将其用于传递给 UsernamePasswordCredential 的 clientId。

若要使用如下所示的 UsernamePasswordCredential 提供程序或 Azure SDK 提供的其他凭据提供程序,请包含 包 azure-identity

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-identity</artifactId>
    <version>1.10.4</version>
</dependency>

将 AAD 应用程序的客户端 ID、租户 ID 的值设置为环境变量:AZURE_CLIENT_ID、AZURE_TENANT_ID。 将 AAD 用户的用户名和密码的值设置为环境变量:USER_NAME、PASSWORD。

WorkflowClient purviewWorkflowClient = new WorkflowClientBuilder()
    .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint"))
    .credential(new UsernamePasswordCredentialBuilder()
        .clientId(Configuration.getGlobalConfiguration().get("CLIENTID", "clientId"))
        .tenantId(Configuration.getGlobalConfiguration().get("TENANTID", "tenantId"))
        .username(Configuration.getGlobalConfiguration().get("USERNAME", "username"))
        .password(Configuration.getGlobalConfiguration().get("PASSWORD", "password"))
        .build())
    .buildClient();

示例

以下部分提供了几个代码片段,涵盖了一些最常见的方案,包括:

创建工作流

BinaryData workflowCreateOrUpdateCommand =
    BinaryData.fromString(
        "{\"name\":\"Create glossary term workflow\",\"description\":\"\",\"triggers\":[{\"type\":\"when_term_creation_is_requested\",\"underGlossaryHierarchy\":\"/glossaries/20031e20-b4df-4a66-a61d-1b0716f3fa48\"}],\"isEnabled\":true,\"actionDag\":{\"actions\":{\"Startandwaitforanapproval\":{\"type\":\"Approval\",\"inputs\":{\"parameters\":{\"approvalType\":\"PendingOnAll\",\"title\":\"ApprovalRequestforCreateGlossaryTerm\",\"assignedTo\":[\"eece94d9-0619-4669-bb8a-d6ecec5220bc\"]}},\"runAfter\":{}},\"Condition\":{\"type\":\"If\",\"expression\":{\"and\":[{\"equals\":[\"@outputs('Startandwaitforanapproval')['body/outcome']\",\"Approved\"]}]},\"actions\":{\"Createglossaryterm\":{\"type\":\"CreateTerm\",\"runAfter\":{}},\"Sendemailnotification\":{\"type\":\"EmailNotification\",\"inputs\":{\"parameters\":{\"emailSubject\":\"GlossaryTermCreate-APPROVED\",\"emailMessage\":\"YourrequestforGlossaryTerm@{triggerBody()['request']['term']['name']}isapproved.\",\"emailRecipients\":[\"@{triggerBody()['request']['requestor']}\"]}},\"runAfter\":{\"Createglossaryterm\":[\"Succeeded\"]}}},\"else\":{\"actions\":{\"Sendrejectemailnotification\":{\"type\":\"EmailNotification\",\"inputs\":{\"parameters\":{\"emailSubject\":\"GlossaryTermCreate-REJECTED\",\"emailMessage\":\"YourrequestforGlossaryTerm@{triggerBody()['request']['term']['name']}isrejected.\",\"emailRecipients\":[\"@{triggerBody()['request']['requestor']}\"]}},\"runAfter\":{}}}},\"runAfter\":{\"Startandwaitforanapproval\":[\"Succeeded\"]}}}}}");
RequestOptions requestOptions = new RequestOptions();
Response<BinaryData> response =
    purviewWorkflowClient.createOrReplaceWithResponse(
        "4afb5752-e47f-43a1-8ba7-c696bf8d2745", workflowCreateOrUpdateCommand, requestOptions);

提交用户请求

BinaryData userRequestsPayload =
    BinaryData.fromString(
        "{\"comment\":\"Thanks!\",\"operations\":[{\"type\":\"CreateTerm\",\"payload\":{\"glossaryTerm\":{\"name\":\"term\",\"anchor\":{\"glossaryGuid\":\"20031e20-b4df-4a66-a61d-1b0716f3fa48\"},\"nickName\":\"term\",\"status\":\"Approved\"}}}]}");
RequestOptions requestOptions = new RequestOptions();
Response<BinaryData> response =
    userRequestsClient.submitWithResponse(userRequestsPayload, requestOptions);

批准工作流任务

BinaryData approvalResponseComment = BinaryData.fromString("{\"comment\":\"Thanks for raising this!\"}");
RequestOptions requestOptions = new RequestOptions();
Response<Void> response =
    approvalClient.approveWithResponse(
        "69b57a00-f5de-4a17-a44a-6479adae373d", approvalResponseComment, requestOptions);

关键概念

疑难解答

后续步骤

贡献

本项目欢迎贡献和建议。 大多数贡献要求你同意 [参与者许可协议 (CLA) ][cla] 声明你有权并实际授予我们使用您的贡献的权利。

提交拉取请求时,CLA 机器人将自动确定你是否需要提供 CLA,并相应地修饰 PR(例如标签、注释)。 直接按机器人提供的说明操作。 只需使用 CLA 对所有存储库执行一次这样的操作。

此项目已采用 [Microsoft 开放源代码行为准则][coc]。 有关详细信息,请参阅 [行为准则常见问题解答][coc_faq] 或联系 [opencode@microsoft.com][coc_contact] 如有任何其他问题或意见。

曝光数