Search in sources :

Example 1 with EventNode

use of org.jbpm.workflow.core.node.EventNode in project jbpm by kiegroup.

the class EventNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    EventNode eventNode = (EventNode) node;
    writeNode("eventNode", eventNode, xmlDump, includeMeta);
    String variableName = eventNode.getVariableName();
    if (variableName != null && variableName.length() != 0) {
        xmlDump.append("variableName=\"" + variableName + "\" ");
    }
    String scope = eventNode.getScope();
    if (scope != null && scope.length() != 0) {
        xmlDump.append("scope=\"" + scope + "\" ");
    }
    xmlDump.append(">" + EOL);
    if (includeMeta) {
        writeMetaData(eventNode, xmlDump);
    }
    xmlDump.append("      <eventFilters>" + EOL);
    for (EventFilter filter : eventNode.getEventFilters()) {
        if (filter instanceof EventTypeFilter) {
            xmlDump.append("        <eventFilter " + "type=\"eventType\" " + "eventType=\"" + ((EventTypeFilter) filter).getType() + "\" />" + EOL);
        } else {
            throw new IllegalArgumentException("Unknown filter type: " + filter);
        }
    }
    xmlDump.append("      </eventFilters>" + EOL);
    endNode("eventNode", xmlDump);
}
Also used : EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) EventFilter(org.jbpm.process.core.event.EventFilter)

Example 2 with EventNode

use of org.jbpm.workflow.core.node.EventNode in project jbpm by kiegroup.

the class ProcessHandler method linkBoundaryConditionEvent.

private static void linkBoundaryConditionEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    String processId = ((RuleFlowProcess) nodeContainer).getId();
    String eventType = "RuleFlowStateEvent-" + processId + "-" + ((EventNode) node).getUniqueId() + "-" + attachedTo;
    ((EventTypeFilter) ((EventNode) node).getEventFilters().get(0)).setType(eventType);
    boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity");
    if (cancelActivity) {
        List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<DroolsAction>();
        }
        DroolsConsequenceAction action = new DroolsConsequenceAction("java", null);
        action.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
        actions.add(action);
        ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) CancelNodeInstanceAction(org.jbpm.process.instance.impl.CancelNodeInstanceAction) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction)

Example 3 with EventNode

use of org.jbpm.workflow.core.node.EventNode in project jbpm by kiegroup.

the class ProcessHandler method linkBoundaryTimerEvent.

private static void linkBoundaryTimerEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity");
    StateBasedNode compositeNode = (StateBasedNode) attachedNode;
    String timeDuration = (String) node.getMetaData().get("TimeDuration");
    String timeCycle = (String) node.getMetaData().get("TimeCycle");
    String timeDate = (String) node.getMetaData().get("TimeDate");
    Timer timer = new Timer();
    if (timeDuration != null) {
        timer.setDelay(timeDuration);
        timer.setTimeType(Timer.TIME_DURATION);
        compositeNode.addTimer(timer, new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Timer-" + attachedTo + "-" + timeDuration + "-" + node.getId() + "\", kcontext.getNodeInstance().getId());"));
    } else if (timeCycle != null) {
        int index = timeCycle.indexOf("###");
        if (index != -1) {
            String period = timeCycle.substring(index + 3);
            timeCycle = timeCycle.substring(0, index);
            timer.setPeriod(period);
        }
        timer.setDelay(timeCycle);
        timer.setTimeType(Timer.TIME_CYCLE);
        compositeNode.addTimer(timer, new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Timer-" + attachedTo + "-" + timeCycle + (timer.getPeriod() == null ? "" : "###" + timer.getPeriod()) + "-" + node.getId() + "\", kcontext.getNodeInstance().getId());"));
    } else if (timeDate != null) {
        timer.setDate(timeDate);
        timer.setTimeType(Timer.TIME_DATE);
        compositeNode.addTimer(timer, new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Timer-" + attachedTo + "-" + timeDate + "-" + node.getId() + "\", kcontext.getNodeInstance().getId());"));
    }
    if (cancelActivity) {
        List<DroolsAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<DroolsAction>();
        }
        DroolsConsequenceAction cancelAction = new DroolsConsequenceAction("java", null);
        cancelAction.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
        actions.add(cancelAction);
        ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
    }
}
Also used : StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) DroolsAction(org.jbpm.workflow.core.DroolsAction) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) CancelNodeInstanceAction(org.jbpm.process.instance.impl.CancelNodeInstanceAction) Timer(org.jbpm.process.core.timer.Timer) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction)

Example 4 with EventNode

use of org.jbpm.workflow.core.node.EventNode 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 5 with EventNode

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

Aggregations

EventNode (org.jbpm.workflow.core.node.EventNode)36 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)21 ActionNode (org.jbpm.workflow.core.node.ActionNode)21 EndNode (org.jbpm.workflow.core.node.EndNode)21 StartNode (org.jbpm.workflow.core.node.StartNode)21 ArrayList (java.util.ArrayList)18 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)16 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)14 DroolsAction (org.jbpm.workflow.core.DroolsAction)13 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)13 FaultNode (org.jbpm.workflow.core.node.FaultNode)12 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)12 Node (org.kie.api.definition.process.Node)12 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)11 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)11 StateNode (org.jbpm.workflow.core.node.StateNode)11 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)10 EventFilter (org.jbpm.process.core.event.EventFilter)9 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)9 Join (org.jbpm.workflow.core.node.Join)9