AEM - 具有作者内容验证的自定义工作流程?

AEM - Custom workflow with Author content validation ?

如何编写 AEM - 带有作者内容验证的自定义工作流程?

例如:我想在激活页面时验证作者 HTML 的内容。 我想检查 Author 内容中的所有 Hyperlink,基于特定的 link 使工作流程失败或通过工作流程以进行激活。

AEM Workflow documentation is very helpful on this subject. You will need to create service that implements the WorkflowProcess interface. Once that is done, you can create a new workflow at http://localhost:4502/workflow or you can update the default activation workflow at http://localhost:4502/cf#/etc/workflow/models/request_for_activation.html。放入一个新的 Process Step,将 Advance Handler 设置为 true 并将 Process 设置为您的服务。不要忘记点击 Save 按钮。

在您的服务中,您可以访问会话,因此可以访问资源解析器以及激活资源的路径。这就是获取资源和 运行 针对其属性的自定义代码所需的全部内容。如果您的自定义验证返回错误,您可以使用 wfsession.terminateWorkflow(item.getWorkflow()) 终止工作流程,否则工作流程将继续,因为您将其设置为自动前进。

这是您的工作流程步骤的粗略大纲:

@Component
@Service
@Properties({
    @Property(name = Constants.SERVICE_DESCRIPTION, value = "Workflow step description"),
    @Property(name = Constants.SERVICE_VENDOR, value = "Company Name"),
    @Property(name = "process.label", value = "Process Label will show in the workflow dropdown") })
public class MyCustomStep implements WorkflowProcess {

    public void execute(WorkItem item, WorkflowSession wfsession, MetaDataMap args) throws WorkflowException {
        ResourceResolver resolver = wfsession.adaptTo(ResourceResolver.class);

        if (resolver != null) {
            // Get the payload: the activated resource
            String path = item.getWorkflowData().getPayload().toString();

            Resource resource = resolver.getResource(path);

            if (resource != null) {
                ValueMap properties = resource.adaptTo(ValueMap.class);
                String propertyToCheck = properties.get("myPropertyName", String.class);

                if (!customValidationMethod(propertyToCheck)) {
                    // Terminate workflow
                    wfsession.terminateWorkflow(item.getWorkflow());
                }
            }
        }
    }
}