Search in sources :

Example 1 with StateBasedNode

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

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

the class ProcessHandler method linkBoundaryEvents.

public static void linkBoundaryEvents(NodeContainer nodeContainer) {
    for (Node node : nodeContainer.getNodes()) {
        if (node instanceof EventNode) {
            final String attachedTo = (String) node.getMetaData().get("AttachedTo");
            if (attachedTo != null) {
                for (EventFilter filter : ((EventNode) node).getEventFilters()) {
                    String type = ((EventTypeFilter) filter).getType();
                    Node attachedNode = findNodeByIdOrUniqueIdInMetadata(nodeContainer, attachedTo, "Could not find node to attach to: " + attachedTo);
                    // 
                    if (!(attachedNode instanceof StateBasedNode) && !type.equals("Compensation")) {
                        throw new IllegalArgumentException("Boundary events are supported only on StateBasedNode, found node: " + attachedNode.getClass().getName() + " [" + attachedNode.getMetaData().get("UniqueId") + "]");
                    }
                    if (type.startsWith("Escalation")) {
                        linkBoundaryEscalationEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Error-")) {
                        linkBoundaryErrorEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Timer-")) {
                        linkBoundaryTimerEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.equals("Compensation")) {
                        linkBoundaryCompensationEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (node.getMetaData().get("SignalName") != null || type.startsWith("Message-")) {
                        linkBoundarySignalEvent(nodeContainer, node, attachedTo, attachedNode);
                    } else if (type.startsWith("Condition-")) {
                        linkBoundaryConditionEvent(nodeContainer, node, attachedTo, attachedNode);
                    }
                }
            }
        }
    }
}
Also used : StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EventNode(org.jbpm.workflow.core.node.EventNode) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) 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) EventFilter(org.jbpm.process.core.event.EventFilter)

Example 3 with StateBasedNode

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

the class TimerHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    Element element = parser.endElementBuilder();
    StateBasedNode parent = (StateBasedNode) parser.getParent();
    String id = element.getAttribute("id");
    emptyAttributeCheck(localName, "id", id, parser);
    String delay = element.getAttribute("delay");
    String period = element.getAttribute("period");
    Timer timer = new Timer();
    timer.setId(new Long(id));
    if (delay != null && delay.length() != 0) {
        timer.setDelay(delay);
    }
    if (period != null && period.length() != 0) {
        timer.setPeriod(period);
    }
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    DroolsAction action = null;
    if (xmlNode instanceof Element) {
        Element actionXml = (Element) xmlNode;
        action = AbstractNodeHandler.extractAction(actionXml);
    }
    parent.addTimer(timer, action);
    return null;
}
Also used : StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) DroolsAction(org.jbpm.workflow.core.DroolsAction) Timer(org.jbpm.process.core.timer.Timer) Element(org.w3c.dom.Element)

Example 4 with StateBasedNode

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

the class EventBasedNodeBuilder method build.

public void build(Process process, ProcessDescr processDescr, ProcessBuildContext context, Node node) {
    super.build(process, processDescr, context, node);
    Map<Timer, DroolsAction> timers = ((StateBasedNode) node).getTimers();
    if (timers != null) {
        for (DroolsAction action : timers.values()) {
            buildAction(action, context, (NodeImpl) node);
        }
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) StateBasedNode(org.jbpm.workflow.core.node.StateBasedNode) Timer(org.jbpm.process.core.timer.Timer)

Aggregations

StateBasedNode (org.jbpm.workflow.core.node.StateBasedNode)4 Timer (org.jbpm.process.core.timer.Timer)3 DroolsAction (org.jbpm.workflow.core.DroolsAction)3 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)2 EventNode (org.jbpm.workflow.core.node.EventNode)2 EventFilter (org.jbpm.process.core.event.EventFilter)1 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)1 CancelNodeInstanceAction (org.jbpm.process.instance.impl.CancelNodeInstanceAction)1 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)1 ActionNode (org.jbpm.workflow.core.node.ActionNode)1 CompositeContextNode (org.jbpm.workflow.core.node.CompositeContextNode)1 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)1 EndNode (org.jbpm.workflow.core.node.EndNode)1 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)1 FaultNode (org.jbpm.workflow.core.node.FaultNode)1 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)1 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)1 StartNode (org.jbpm.workflow.core.node.StartNode)1 StateNode (org.jbpm.workflow.core.node.StateNode)1 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)1