Search in sources :

Example 1 with NodeContainer

use of org.kie.api.definition.process.NodeContainer in project drools by kiegroup.

the class WorkingMemoryLogger method createNodeId.

private String createNodeId(NodeInstance nodeInstance) {
    Node node = nodeInstance.getNode();
    if (node == null) {
        return "";
    }
    Object uniqueIdObj = node.getMetaData().get("UniqueId");
    String nodeId;
    if (uniqueIdObj == null) {
        nodeId = "" + node.getId();
    } else {
        nodeId = (String) uniqueIdObj;
    }
    NodeContainer nodeContainer = node.getNodeContainer();
    while (nodeContainer != null) {
        if (nodeContainer instanceof Node) {
            node = (Node) nodeContainer;
            nodeContainer = node.getNodeContainer();
            // TODO fix this filter out hidden compositeNode inside ForEach node
            if (!(nodeContainer.getClass().getName().endsWith("ForEachNode"))) {
                nodeId = node.getId() + ":" + nodeId;
            }
        } else {
            break;
        }
    }
    return nodeId;
}
Also used : Node(org.kie.api.definition.process.Node) NodeContainer(org.kie.api.definition.process.NodeContainer)

Example 2 with NodeContainer

use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.

the class ChecklistItemFactory method getRelevantNodes.

private static void getRelevantNodes(NodeContainer container, Map<String, String> result) {
    for (Node node : container.getNodes()) {
        if (node instanceof NodeContainer) {
            getRelevantNodes((NodeContainer) node, result);
        }
        String docs = (String) node.getMetaData().get("Documentation");
        if (docs != null) {
            int position = docs.indexOf("OrderingNb=");
            if (position >= 0) {
                int end = docs.indexOf(";", position + 1);
                String orderingNumber = docs.substring(position + 11, end);
                String nodeId = (String) node.getMetaData().get("UniqueId");
                if (nodeId == null) {
                    nodeId = ((NodeImpl) node).getUniqueId();
                }
                result.put(nodeId, orderingNumber);
            }
        }
    }
}
Also used : HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) StartNode(org.jbpm.workflow.core.node.StartNode) Node(org.kie.api.definition.process.Node) NodeContainer(org.kie.api.definition.process.NodeContainer)

Example 3 with NodeContainer

use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.

the class XmlBPMNProcessDumper method getUniqueNodeId.

public static String getUniqueNodeId(Node node) {
    String result = (String) node.getMetaData().get("UniqueId");
    if (result != null) {
        return result;
    }
    result = node.getId() + "";
    NodeContainer nodeContainer = node.getNodeContainer();
    while (nodeContainer instanceof CompositeNode) {
        CompositeNode composite = (CompositeNode) nodeContainer;
        result = composite.getId() + "-" + result;
        nodeContainer = composite.getNodeContainer();
    }
    return "_" + result;
}
Also used : CompositeNode(org.jbpm.workflow.core.node.CompositeNode) NodeContainer(org.kie.api.definition.process.NodeContainer)

Example 4 with NodeContainer

use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.

the class BPMNPlaneHandler method processNodeInfo.

private boolean processNodeInfo(NodeInfo nodeInfo, Node[] nodes) {
    if (nodeInfo == null || nodeInfo.getNodeRef() == null) {
        return false;
    }
    for (Node node : nodes) {
        String id = (String) node.getMetaData().get("UniqueId");
        if (nodeInfo.getNodeRef().equals(id)) {
            ((org.jbpm.workflow.core.Node) node).setMetaData("x", nodeInfo.getX());
            ((org.jbpm.workflow.core.Node) node).setMetaData("y", nodeInfo.getY());
            ((org.jbpm.workflow.core.Node) node).setMetaData("width", nodeInfo.getWidth());
            ((org.jbpm.workflow.core.Node) node).setMetaData("height", nodeInfo.getHeight());
            return true;
        }
        if (node instanceof NodeContainer) {
            boolean found = processNodeInfo(nodeInfo, ((NodeContainer) node).getNodes());
            if (found) {
                return true;
            }
        }
    }
    return false;
}
Also used : Node(org.kie.api.definition.process.Node) NodeContainer(org.kie.api.definition.process.NodeContainer)

Example 5 with NodeContainer

use of org.kie.api.definition.process.NodeContainer in project jbpm by kiegroup.

the class ProcessHandler method linkAssociations.

public static void linkAssociations(Definitions definitions, NodeContainer nodeContainer, List<Association> associations) {
    if (associations != null) {
        for (Association association : associations) {
            String sourceRef = association.getSourceRef();
            Object source = null;
            try {
                source = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, sourceRef, "Could not find source [" + sourceRef + "] for association " + association.getId() + "]");
            } catch (IllegalArgumentException e) {
            // source not found
            }
            String targetRef = association.getTargetRef();
            Object target = null;
            try {
                target = findNodeOrDataStoreByUniqueId(definitions, nodeContainer, targetRef, "Could not find target [" + targetRef + "] for association [" + association.getId() + "]");
            } catch (IllegalArgumentException e) {
            // target not found
            }
            if (source == null || target == null) {
            // TODO: ignoring this association for now
            } else if (target instanceof DataStore || source instanceof DataStore) {
            // TODO: ignoring data store associations for now
            } else if (source instanceof EventNode) {
                EventNode sourceNode = (EventNode) source;
                Node targetNode = (Node) target;
                checkBoundaryEventCompensationHandler(association, sourceNode, targetNode);
                // make sure IsForCompensation is set to true on target
                NodeImpl targetNodeImpl = (NodeImpl) target;
                String isForCompensation = "isForCompensation";
                Object compensationObject = targetNodeImpl.getMetaData(isForCompensation);
                if (compensationObject == null) {
                    targetNodeImpl.setMetaData(isForCompensation, true);
                    logger.warn("Setting {} attribute to true for node {}", isForCompensation, targetRef);
                } else if (!Boolean.parseBoolean(compensationObject.toString())) {
                    throw new IllegalArgumentException(isForCompensation + " attribute [" + compensationObject + "] should be true for Compensation Activity [" + targetRef + "]");
                }
                // put Compensation Handler in CompensationHandlerNode
                NodeContainer sourceParent = sourceNode.getNodeContainer();
                NodeContainer targetParent = targetNode.getNodeContainer();
                if (!sourceParent.equals(targetParent)) {
                    throw new IllegalArgumentException("Compensation Associations may not cross (sub-)process boundaries,");
                }
                // connect boundary event to compensation activity
                ConnectionImpl connection = new ConnectionImpl(sourceNode, NodeImpl.CONNECTION_DEFAULT_TYPE, targetNode, NodeImpl.CONNECTION_DEFAULT_TYPE);
                connection.setMetaData("UniqueId", null);
                connection.setMetaData("hidden", true);
                connection.setMetaData("association", true);
            // Compensation use cases:
            // - boundary event --associated-> activity
            // - implicit sub process compensation handler + recursive?
            /**
             * BPMN2 spec, p.442:
             *   "A Compensation Event Sub-process becomes enabled when its parent Activity transitions into state
             *  Completed. At that time, a snapshot of the data associated with the parent Acitivity is taken and kept for
             *  later usage by the Compensation Event Sub-Process."
             */
            }
        }
    }
}
Also used : BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) Association(org.jbpm.bpmn2.core.Association) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) DataStore(org.jbpm.bpmn2.core.DataStore) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) StateNode(org.jbpm.workflow.core.node.StateNode) RuleSetNode(org.jbpm.workflow.core.node.RuleSetNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) FaultNode(org.jbpm.workflow.core.node.FaultNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) EventNode(org.jbpm.workflow.core.node.EventNode) Node(org.kie.api.definition.process.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) NodeContainer(org.kie.api.definition.process.NodeContainer)

Aggregations

NodeContainer (org.kie.api.definition.process.NodeContainer)18 Node (org.kie.api.definition.process.Node)12 StartNode (org.jbpm.workflow.core.node.StartNode)9 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)8 ActionNode (org.jbpm.workflow.core.node.ActionNode)7 EndNode (org.jbpm.workflow.core.node.EndNode)7 EventNode (org.jbpm.workflow.core.node.EventNode)6 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)6 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)6 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)6 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)5 FaultNode (org.jbpm.workflow.core.node.FaultNode)5 StateNode (org.jbpm.workflow.core.node.StateNode)5 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)4 NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)4 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)4 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3