Search in sources :

Example 1 with EventTrigger

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

the class StartEventHandler method addTriggerWithInMappings.

private void addTriggerWithInMappings(StartNode startNode, String triggerEventType) {
    EventTrigger trigger = new EventTrigger();
    EventTypeFilter eventFilter = new EventTypeFilter();
    eventFilter.setType(triggerEventType);
    trigger.addEventFilter(eventFilter);
    String mapping = (String) startNode.getMetaData("TriggerMapping");
    if (mapping != null) {
        trigger.addInMapping(mapping, startNode.getOutMapping(mapping));
    }
    startNode.addTrigger(trigger);
}
Also used : NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Example 2 with EventTrigger

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

the class StartEventHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    StartNode startNode = (StartNode) node;
    writeNode("startEvent", startNode, xmlDump, metaDataType);
    xmlDump.append(" isInterrupting=\"");
    if (startNode.isInterrupting()) {
        xmlDump.append("true");
    } else {
        xmlDump.append("false");
    }
    xmlDump.append("\">" + EOL);
    writeExtensionElements(startNode, xmlDump);
    List<Trigger> triggers = startNode.getTriggers();
    if (triggers != null) {
        if (triggers.size() > 1) {
            throw new IllegalArgumentException("Multiple start triggers not supported");
        }
        Trigger trigger = triggers.get(0);
        if (trigger instanceof ConstraintTrigger) {
            ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
            if (constraintTrigger.getHeader() == null) {
                xmlDump.append("      <conditionalEventDefinition>" + EOL);
                xmlDump.append("        <condition xsi:type=\"tFormalExpression\" language=\"" + XmlBPMNProcessDumper.RULE_LANGUAGE + "\">" + constraintTrigger.getConstraint() + "</condition>" + EOL);
                xmlDump.append("      </conditionalEventDefinition>" + EOL);
            }
        } else if (trigger instanceof EventTrigger) {
            EventTrigger eventTrigger = (EventTrigger) trigger;
            String mapping = null;
            String nameMapping = "event";
            if (!trigger.getInMappings().isEmpty()) {
                mapping = eventTrigger.getInMappings().keySet().iterator().next();
                nameMapping = eventTrigger.getInMappings().values().iterator().next();
            } else {
                mapping = (String) startNode.getMetaData("TriggerMapping");
            }
            if (mapping != null) {
                xmlDump.append("      <dataOutput id=\"_" + startNode.getId() + "_Output\" name=\"" + nameMapping + "\" />" + EOL + "      <dataOutputAssociation>" + EOL + "        <sourceRef>_" + startNode.getId() + "_Output</sourceRef>" + EOL + "        <targetRef>" + mapping + "</targetRef>" + EOL + "      </dataOutputAssociation>" + EOL);
            }
            String type = ((EventTypeFilter) eventTrigger.getEventFilters().get(0)).getType();
            if (type.startsWith("Message-")) {
                type = type.substring(8);
                xmlDump.append("      <messageEventDefinition messageRef=\"" + type + "\"/>" + EOL);
            } else if (type.startsWith("Error-")) {
                type = type.substring(6);
                String errorId = getErrorIdForErrorCode(type, startNode);
                xmlDump.append("      <errorEventDefinition errorRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(errorId) + "\"/>" + EOL);
            } else if (type.startsWith("Escalation-")) {
                type = type.substring(11);
                xmlDump.append("      <escalationEventDefinition escalationRef=\"" + type + "\"/>" + EOL);
            } else if (type.equals("Compensation")) {
                xmlDump.append("      <compensateEventDefinition/>" + EOL);
            } else {
                xmlDump.append("      <signalEventDefinition signalRef=\"" + type + "\" />" + EOL);
            }
        } else {
            throw new IllegalArgumentException("Unsupported trigger type " + trigger);
        }
        if (startNode.getTimer() != null) {
            Timer timer = startNode.getTimer();
            xmlDump.append("      <timerEventDefinition>" + EOL);
            if (timer != null && (timer.getDelay() != null || timer.getDate() != null)) {
                if (timer.getTimeType() == Timer.TIME_DATE) {
                    xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDate()) + "</timeDate>" + EOL);
                } else if (timer.getTimeType() == Timer.TIME_DURATION) {
                    xmlDump.append("        <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDuration>" + EOL);
                } else if (timer.getTimeType() == Timer.TIME_CYCLE) {
                    if (timer.getPeriod() != null) {
                        xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "###" + XmlDumper.replaceIllegalChars(timer.getPeriod()) + "</timeCycle>" + EOL);
                    } else {
                        xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeCycle>" + EOL);
                    }
                } else if (timer.getTimeType() == Timer.TIME_DATE) {
                    xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDate>" + EOL);
                }
            }
            xmlDump.append("      </timerEventDefinition>" + EOL);
        }
    } else if (startNode.getTimer() != null) {
        Timer timer = startNode.getTimer();
        xmlDump.append("      <timerEventDefinition>" + EOL);
        if (timer != null && (timer.getDelay() != null || timer.getDate() != null)) {
            if (timer.getTimeType() == Timer.TIME_DATE) {
                xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDate()) + "</timeDate>" + EOL);
            } else if (timer.getTimeType() == Timer.TIME_DURATION) {
                xmlDump.append("        <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDuration>" + EOL);
            } else if (timer.getTimeType() == Timer.TIME_CYCLE) {
                if (timer.getPeriod() != null) {
                    xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "###" + XmlDumper.replaceIllegalChars(timer.getPeriod()) + "</timeCycle>" + EOL);
                } else {
                    xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeCycle>" + EOL);
                }
            } else if (timer.getTimeType() == Timer.TIME_DATE) {
                xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDate>" + EOL);
            }
        }
        xmlDump.append("      </timerEventDefinition>" + EOL);
    }
    endNode("startEvent", xmlDump);
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) Timer(org.jbpm.process.core.timer.Timer) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Example 3 with EventTrigger

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

the class StartEventHandler method handleCompensationNode.

protected void handleCompensationNode(final StartNode startNode, final Element element, final org.w3c.dom.Node xmlNode, final ExtensibleXmlParser parser) throws SAXException {
    if (startNode.isInterrupting()) {
        logger.warn("Compensation Event Sub-Processes [" + startNode.getMetaData("UniqueId") + "] may not be specified as interrupting:" + " overriding attribute and setting to not-interrupting.");
    }
    startNode.setInterrupting(false);
    /**
     * From the BPMN2 spec, P.264:
     * "For a Start Event:
     *  This Event "catches" the compensation for an Event Sub-Process. No further information is required.
     *  The Event Sub-Process will provide the id necessary to match the Compensation Event with the Event
     *  that threw the compensation"
     *
     *  In other words, the id of the Sub-Process containing this Event Sub-Process is what should be used
     *  as the activityRef value in any Intermediate (throw) or End compensation event that targets
     *  this particular Event Sub-Process.
     *
     *  This is similar to the logic used for a Compensation Boundary Event: it's signaled using
     *  the id of the activity to which the CBE is attached to.
     */
    String activityRef = ((Element) xmlNode).getAttribute("activityRef");
    if (activityRef != null && activityRef.length() > 0) {
        logger.warn("activityRef value [" + activityRef + "] on Start Event '" + startNode.getMetaData("UniqueId") + "' ignored per the BPMN2 specification.");
    }
    // so that this node will get processed in ProcessHandler.postProcessNodes(...)
    EventTrigger startTrigger = new EventTrigger();
    EventFilter eventFilter = new NonAcceptingEventTypeFilter();
    ((NonAcceptingEventTypeFilter) eventFilter).setType("Compensation");
    startTrigger.addEventFilter(eventFilter);
    List<Trigger> startTriggers = new ArrayList<Trigger>();
    startTriggers.add(startTrigger);
    startNode.setTriggers(startTriggers);
    String mapping = (String) startNode.getMetaData("TriggerMapping");
    if (mapping != null) {
        startTrigger.addInMapping(mapping, startNode.getOutMapping(mapping));
    }
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventFilter(org.jbpm.process.core.event.EventFilter) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Example 4 with EventTrigger

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

the class StartEventHandler method handleTimerNode.

protected void handleTimerNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    super.handleNode(node, element, uri, localName, parser);
    StartNode startNode = (StartNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("timerEventDefinition".equals(nodeName)) {
            Timer timer = new Timer();
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode instanceof Element) {
                String subNodeName = subNode.getNodeName();
                if ("timeCycle".equals(subNodeName)) {
                    String delay = subNode.getTextContent();
                    int index = delay.indexOf("###");
                    if (index != -1) {
                        String period = delay.substring(index + 3);
                        delay = delay.substring(0, index);
                        timer.setPeriod(period);
                    } else {
                        timer.setPeriod(delay);
                    }
                    timer.setTimeType(Timer.TIME_CYCLE);
                    timer.setDelay(delay);
                    break;
                } else if ("timeDuration".equals(subNodeName)) {
                    String delay = subNode.getTextContent();
                    timer.setTimeType(Timer.TIME_DURATION);
                    timer.setDelay(delay);
                    break;
                } else if ("timeDate".equals(subNodeName)) {
                    String date = subNode.getTextContent();
                    timer.setTimeType(Timer.TIME_DATE);
                    timer.setDate(date);
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            startNode.setTimer(timer);
            if (parser.getParent() instanceof EventSubProcessNode) {
                // handle timer on start events like normal (non rule) timers for event sub process
                EventTrigger trigger = new EventTrigger();
                EventTypeFilter eventFilter = new EventTypeFilter();
                eventFilter.setType("Timer-" + ((EventSubProcessNode) parser.getParent()).getId());
                trigger.addEventFilter(eventFilter);
                String mapping = (String) startNode.getMetaData("TriggerMapping");
                if (mapping != null) {
                    trigger.addInMapping(mapping, "event");
                }
                startNode.addTrigger(trigger);
                ((EventSubProcessNode) parser.getParent()).addTimer(timer, new DroolsConsequenceAction("java", ""));
            }
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : StartNode(org.jbpm.workflow.core.node.StartNode) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) Timer(org.jbpm.process.core.timer.Timer) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) Element(org.w3c.dom.Element) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Example 5 with EventTrigger

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

EventTrigger (org.jbpm.workflow.core.node.EventTrigger)13 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)10 StartNode (org.jbpm.workflow.core.node.StartNode)9 Trigger (org.jbpm.workflow.core.node.Trigger)8 ConstraintTrigger (org.jbpm.workflow.core.node.ConstraintTrigger)7 ArrayList (java.util.ArrayList)6 EventFilter (org.jbpm.process.core.event.EventFilter)5 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)5 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)5 ActionNode (org.jbpm.workflow.core.node.ActionNode)5 EndNode (org.jbpm.workflow.core.node.EndNode)5 List (java.util.List)3 NonAcceptingEventTypeFilter (org.jbpm.process.core.event.NonAcceptingEventTypeFilter)3 Timer (org.jbpm.process.core.timer.Timer)3 DroolsAction (org.jbpm.workflow.core.DroolsAction)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)3 Node (org.kie.api.definition.process.Node)3 Element (org.w3c.dom.Element)3 Work (org.jbpm.process.core.Work)2