private List<FlowNode> flowNodes = null;

/**
 * 获取并行网关内的任务节点
 */
private void getParallelGatewayInsideNode() {
    List<FlowElement> flowElements = (List<FlowElement>)bpmnModel.getMainProcess().getFlowElements();
    FlowNode currFlowNode = null;
    flowNodes = new ArrayList<>();
    // 找到流程中第一个并行网关
    for (FlowElement flowElement : flowElements) {
        if (flowElement instanceof ParallelGateway) {
            currFlowNode = (FlowNode)flowElement;
            break;
        }
    }

    if (currFlowNode != null) {
        List<SequenceFlow> outgoingFlows = currFlowNode.getOutgoingFlows();
        getForwardNodeList(outgoingFlows);
    }
}

private void getForwardNodeList(List<SequenceFlow> outgoingFlows) {
    for (SequenceFlow sequenceFlow : outgoingFlows) {
        String targetNodeId = sequenceFlow.getTargetRef();
        FlowNode targetNode = (FlowNode)bpmnModel.getMainProcess().getFlowElement(targetNodeId);

        String gatewayType = targetNodeId.substring(targetNodeId
                .lastIndexOf("_") + 1);
        // 并行网关必须成对出现,配置的id必须以_start、_end结尾
       if (targetNode instanceof ParallelGateway && "END".equals(gatewayType.toUpperCase())) {
            continue;
        }

        if (targetNode instanceof UserTask && !flowNodes.contains(targetNode)) {
            flowNodes.add(targetNode);
        }

        getForwardNodeList(targetNode.getOutgoingFlows());
    }
}
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐