Search in sources :

Example 1 with NodeImpl

use of org.jbpm.workflow.core.impl.NodeImpl in project jbpm by kiegroup.

the class DynamicProcessTest method insertNodeInBetween.

private static void insertNodeInBetween(RuleFlowProcess process, long startNodeId, long endNodeId, NodeImpl node) {
    if (process == null) {
        throw new IllegalArgumentException("Process may not be null");
    }
    NodeImpl selectedNode = (NodeImpl) process.getNode(startNodeId);
    if (selectedNode == null) {
        throw new IllegalArgumentException("Node " + startNodeId + " not found in process " + process.getId());
    }
    for (Connection connection : selectedNode.getDefaultOutgoingConnections()) {
        if (connection.getTo().getId() == endNodeId) {
            process.addNode(node);
            NodeImpl endNode = (NodeImpl) connection.getTo();
            ((ConnectionImpl) connection).terminate();
            new ConnectionImpl(selectedNode, NodeImpl.CONNECTION_DEFAULT_TYPE, node, NodeImpl.CONNECTION_DEFAULT_TYPE);
            new ConnectionImpl(node, NodeImpl.CONNECTION_DEFAULT_TYPE, endNode, NodeImpl.CONNECTION_DEFAULT_TYPE);
            return;
        }
    }
    throw new IllegalArgumentException("Connection to node " + endNodeId + " not found in process " + process.getId());
}
Also used : NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) Connection(org.kie.api.definition.process.Connection) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl)

Example 2 with NodeImpl

use of org.jbpm.workflow.core.impl.NodeImpl 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)

Example 3 with NodeImpl

use of org.jbpm.workflow.core.impl.NodeImpl in project jbpm by kiegroup.

the class ProcessHandler method linkConnections.

public static void linkConnections(NodeContainer nodeContainer, List<SequenceFlow> connections) {
    if (connections != null) {
        for (SequenceFlow connection : connections) {
            String sourceRef = connection.getSourceRef();
            Node source = findNodeByIdOrUniqueIdInMetadata(nodeContainer, sourceRef, "Could not find source node for connection:" + sourceRef);
            if (source instanceof EventNode) {
                for (EventFilter eventFilter : ((EventNode) source).getEventFilters()) {
                    if (eventFilter instanceof EventTypeFilter) {
                        if ("Compensation".equals(((EventTypeFilter) eventFilter).getType())) {
                            // BPMN Method & Style, 2nd Ed. (Silver), states this on P. 131
                            throw new IllegalArgumentException("A Compensation Boundary Event can only be *associated* with a compensation activity via an Association, not via a Sequence Flow element.");
                        }
                    }
                }
            }
            String targetRef = connection.getTargetRef();
            Node target = findNodeByIdOrUniqueIdInMetadata(nodeContainer, targetRef, "Could not find target node for connection:" + targetRef);
            Connection result = new ConnectionImpl(source, NodeImpl.CONNECTION_DEFAULT_TYPE, target, NodeImpl.CONNECTION_DEFAULT_TYPE);
            result.setMetaData("bendpoints", connection.getBendpoints());
            result.setMetaData("UniqueId", connection.getId());
            if ("true".equals(System.getProperty("jbpm.enable.multi.con"))) {
                NodeImpl nodeImpl = (NodeImpl) source;
                Constraint constraint = buildConstraint(connection, nodeImpl);
                if (constraint != null) {
                    nodeImpl.addConstraint(new ConnectionRef(target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
                }
            } else if (source instanceof Split) {
                Split split = (Split) source;
                Constraint constraint = buildConstraint(connection, split);
                split.addConstraint(new ConnectionRef(target.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE), constraint);
            }
        }
    }
}
Also used : NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) Constraint(org.jbpm.workflow.core.Constraint) SequenceFlow(org.jbpm.bpmn2.core.SequenceFlow) 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) Connection(org.jbpm.workflow.core.Connection) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) EventFilter(org.jbpm.process.core.event.EventFilter) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Split(org.jbpm.workflow.core.node.Split) ConnectionRef(org.jbpm.workflow.core.impl.ConnectionRef)

Example 4 with NodeImpl

use of org.jbpm.workflow.core.impl.NodeImpl in project jbpm by kiegroup.

the class ProcessHandler method assignLanes.

private void assignLanes(NodeContainer nodeContainer, Map<String, String> laneMapping) {
    for (Node node : nodeContainer.getNodes()) {
        String lane = null;
        String uniqueId = (String) node.getMetaData().get("UniqueId");
        if (uniqueId != null) {
            lane = laneMapping.get(uniqueId);
        } else {
            lane = laneMapping.get(XmlBPMNProcessDumper.getUniqueNodeId(node));
        }
        if (lane != null) {
            ((NodeImpl) node).setMetaData("Lane", lane);
            if (node instanceof HumanTaskNode) {
                ((HumanTaskNode) node).setSwimlane(lane);
            }
        }
        if (node instanceof NodeContainer) {
            assignLanes((NodeContainer) node, laneMapping);
        }
    }
}
Also used : NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) 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) NodeContainer(org.kie.api.definition.process.NodeContainer) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode)

Example 5 with NodeImpl

use of org.jbpm.workflow.core.impl.NodeImpl in project jbpm by kiegroup.

the class ProcessHandler method handleIntermediateOrEndThrowCompensationEvent.

protected void handleIntermediateOrEndThrowCompensationEvent(ExtendedNodeImpl throwEventNode) {
    if (throwEventNode.getMetaData("compensation-activityRef") != null) {
        String activityRef = (String) throwEventNode.getMetaData().remove("compensation-activityRef");
        NodeContainer nodeParent = (NodeContainer) throwEventNode.getNodeContainer();
        if (nodeParent instanceof EventSubProcessNode) {
            boolean compensationEventSubProcess = false;
            List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers();
            CESP_CHECK: for (Trigger trigger : startTriggers) {
                if (trigger instanceof EventTrigger) {
                    for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
                        if (((EventTypeFilter) filter).getType().equals("Compensation")) {
                            compensationEventSubProcess = true;
                            break CESP_CHECK;
                        }
                    }
                }
            }
            if (compensationEventSubProcess) {
                // BPMN2 spec, p. 252, p. 248: intermediate and end compensation event visibility scope
                nodeParent = (NodeContainer) ((NodeImpl) nodeParent).getNodeContainer();
            }
        }
        String parentId;
        if (nodeParent instanceof RuleFlowProcess) {
            parentId = ((RuleFlowProcess) nodeParent).getId();
        } else {
            parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId");
        }
        String compensationEvent;
        if (activityRef.length() == 0) {
            // general/implicit compensation
            compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + parentId;
        } else {
            // specific compensation
            compensationEvent = activityRef;
        }
        DroolsConsequenceAction compensationAction = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", \"" + compensationEvent + "\");");
        if (throwEventNode instanceof ActionNode) {
            ((ActionNode) throwEventNode).setAction(compensationAction);
        } else if (throwEventNode instanceof EndNode) {
            List<DroolsAction> actions = new ArrayList<DroolsAction>();
            actions.add(compensationAction);
            ((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) NodeImpl(org.jbpm.workflow.core.impl.NodeImpl) ExtendedNodeImpl(org.jbpm.workflow.core.impl.ExtendedNodeImpl) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) NodeContainer(org.kie.api.definition.process.NodeContainer) EventFilter(org.jbpm.process.core.event.EventFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) EndNode(org.jbpm.workflow.core.node.EndNode) List(java.util.List) ArrayList(java.util.ArrayList) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Aggregations

NodeImpl (org.jbpm.workflow.core.impl.NodeImpl)16 Node (org.kie.api.definition.process.Node)8 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)6 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)6 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)6 ExtendedNodeImpl (org.jbpm.workflow.core.impl.ExtendedNodeImpl)5 ActionNode (org.jbpm.workflow.core.node.ActionNode)5 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)5 EndNode (org.jbpm.workflow.core.node.EndNode)5 StartNode (org.jbpm.workflow.core.node.StartNode)5 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)4 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)4 EventNode (org.jbpm.workflow.core.node.EventNode)4 FaultNode (org.jbpm.workflow.core.node.FaultNode)4 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)4 StateBasedNode (org.jbpm.workflow.core.node.StateBasedNode)4 List (java.util.List)3 EventFilter (org.jbpm.process.core.event.EventFilter)3 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)3 StateNode (org.jbpm.workflow.core.node.StateNode)3