You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AEM 6.5工作流中如何从ParticipantStepChooser返回多用户组

AEM工作流ParticipantStepChooser返回多用户组解决方案

ParticipantStepChooser完全支持返回多用户组,核心是重写getParticipants方法时返回包含多个组标识的Set<String>集合,具体实现如下:

1. 自定义ParticipantStepChooser实现类

重写getParticipants方法,返回存储用户组的集合。用户组支持两种指定格式:

  • group:[组ID](推荐,写法简洁)
  • 完整JCR路径,比如/groups/my-site/marketing-team

示例代码:

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowSession;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.adobe.granite.workflow.step.ParticipantStepChooser;
import java.util.HashSet;
import java.util.Set;
import java.util.List;

public class MultiGroupParticipantChooser implements ParticipantStepChooser {

    @Override
    public Set<String> getParticipants(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        Set<String> participantGroups = new HashSet<>();
        
        // 从工作流historyItem中提取预存的用户组列表
        List<com.adobe.granite.workflow.exec.HistoryItem> historyItems = workItem.getWorkflow().getHistoryItems();
        for (com.adobe.granite.workflow.exec.HistoryItem item : historyItems) {
            // 假设用户组列表以逗号分隔存储在historyItem元数据的"targetGroups"键中
            String groupsStr = item.getMetaDataMap().get("targetGroups", String.class);
            if (groupsStr != null && !groupsStr.isEmpty()) {
                String[] groups = groupsStr.split(",");
                for (String group : groups) {
                    participantGroups.add("group:" + group.trim());
                }
            }
        }
        
        // 若historyItem无数据,添加默认组示例
        if (participantGroups.isEmpty()) {
            participantGroups.add("group:content-editors");
            participantGroups.add("/groups/my-site/approval-team");
        }
        
        return participantGroups;
    }
}

2. 关键注意事项

  • 确保指定的用户组在AEM中真实存在,否则工作流会抛出用户/组不存在的异常
  • 从historyItem读取数据时,要和存入时的元数据键保持一致(示例中用的是targetGroups)
  • 工作流步骤配置时,在「参与者」选项中选择该自定义Chooser类,运行时任务会自动分配给所有指定组的成员

内容的提问来源于stack exchange,提问作者Scarecrow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 04:50:24