jBPM 6.2 - 如何为当前分配的任务获取传出转换

时间:2015-11-24 14:03:02

标签: java jbpm

我是jBPM的新手,并且正在努力寻找为当前用户任务提取可用传出转换的方法。例如,如果我的工作流程为:

enter image description here

现在,如果我被分配了审核任务,我可以选择修改它,拒绝它或批准它。我想要做的是我想动态地拉出可用的传出转换(修改,拒绝,批准)并将其显示给用户从任何jBPM服务动态地对任务执行操作。请指导我。

1 个答案:

答案 0 :(得分:1)

您希望获得下一个不同网关节点的转换。

首先,您必须获取活动节点(请注意,根据工作流程的复杂程度,可能会有多个节点)

public static List<Node> getProcessActiveNodeList(final StatefulKnowledgeSession inSession,
                                                                 final WorkflowProcessInstanceImpl inInstance) {
    final List<Node> nodes = new ArrayList<>();
    final WorkflowProcess process = (WorkflowProcess) inSession.getKnowledgeBase().getProcess(inInstance.getProcessId());
    for (Node node : process.getNodes()) {
        if (node instanceof EventNode && ((EventNode) node).getFrom() == null) {
            // a free-standing event, without an entry point;  this would be a start of an "optional" branch
            nodes.add(node);
        } else {
            // a node that has an inbound connection;  all nodes on the main branch are of this kind
            List<NodeInstance> nodeInstances = inInstance.getNodeInstances(node.getId());
            if (nodeInstances != null && !nodeInstances.isEmpty()) {
                for (NodeInstance nodeInstance : nodeInstances) {
                    Node nodeInstanceNode = process.getNode(nodeInstance.getNodeId());
                    nodes.add(0, nodeInstanceNode);
                }
            }
        }
    }
    return nodes;
}

接下来,您需要获取下一个不同网关节点的约束:

public static Map<ConnectionRef, Constraint> getNextGatewayConstraints(final StatefulKnowledgeSession inSession,
                                                                       final WorkflowProcessInstanceImpl inInstance,
                                                                       final Node inTaskNode) {
    final Map<ConnectionRef, Constraint> constraints = new HashMap<>();
    final WorkflowProcess process = (WorkflowProcess) inSession.getKnowledgeBase().getProcess(inInstance.getProcessId());
    for (Node node : process.getNodes()) {
        if (!node.equals(inTaskNode)) {
            continue;
        }
        final List<Connection> nodeConnections = node.getOutgoingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
        if (nodeConnections != null && !nodeConnections.isEmpty()) {
            for (Connection c : nodeConnections) {
                final Node nextNode = c.getTo();
                if (nextNode instanceof Split) {
                    constraints.putAll(((Split) nextNode).getConstraints());
                    return constraints;
                }
            }
        }
        break;
    }
    return constraints;
}

每个ConnectionRef指向一个节点,约束应包含条件(修改,拒绝,接受)