Search in sources :

Example 1 with Trigger

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

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

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

Example 4 with Trigger

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

the class StartNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    StartNode startNode = (StartNode) node;
    writeNode("start", startNode, xmlDump, includeMeta);
    List<Trigger> triggers = startNode.getTriggers();
    if ((triggers == null || triggers.isEmpty()) && (!includeMeta || !containsMetaData(startNode))) {
        endNode(xmlDump);
    } else {
        xmlDump.append(">" + EOL);
        if (includeMeta) {
            writeMetaData(startNode, xmlDump);
        }
        if (triggers != null) {
            xmlDump.append("      <triggers>" + EOL);
            for (Trigger trigger : triggers) {
                if (trigger instanceof ConstraintTrigger) {
                    xmlDump.append("        <trigger type=\"constraint\" >" + EOL);
                    xmlDump.append("          <constraint type=\"rule\" dialect=\"mvel\" >" + ((ConstraintTrigger) trigger).getConstraint() + "</constraint>" + EOL);
                    Map<String, String> inMappings = trigger.getInMappings();
                    if (inMappings != null && !inMappings.isEmpty()) {
                        for (Map.Entry<String, String> entry : inMappings.entrySet()) {
                            xmlDump.append("          <mapping type=\"in\" from=\"" + XmlDumper.replaceIllegalChars(entry.getValue()) + "\" to=\"" + entry.getKey() + "\" />" + EOL);
                        }
                    }
                    xmlDump.append("        </trigger>" + EOL);
                } else if (trigger instanceof EventTrigger) {
                    xmlDump.append("        <trigger type=\"event\" >" + EOL);
                    xmlDump.append("          <eventFilters>" + EOL);
                    for (EventFilter filter : ((EventTrigger) trigger).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);
                    Map<String, String> inMappings = trigger.getInMappings();
                    if (inMappings != null && !inMappings.isEmpty()) {
                        for (Map.Entry<String, String> entry : inMappings.entrySet()) {
                            xmlDump.append("          <mapping type=\"in\" from=\"" + XmlDumper.replaceIllegalChars(entry.getValue()) + "\" to=\"" + entry.getKey() + "\" />" + EOL);
                        }
                    }
                    xmlDump.append("        </trigger>" + EOL);
                } else {
                    throw new IllegalArgumentException("Unknown trigger type " + trigger);
                }
            }
            xmlDump.append("      </triggers>" + EOL);
        }
        endNode("start", xmlDump);
    }
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) 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) Map(java.util.Map) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Example 5 with Trigger

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

the class TriggerHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    StartNode startNode = (StartNode) parser.getParent();
    String type = attrs.getValue("type");
    emptyAttributeCheck(localName, "type", type, parser);
    Trigger trigger = null;
    if ("constraint".equals(type)) {
        trigger = new ConstraintTrigger();
    } else if ("event".equals(type)) {
        trigger = new EventTrigger();
    } else {
        throw new SAXException("Unknown trigger type " + type);
    }
    startNode.addTrigger(trigger);
    return trigger;
}
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) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) SAXException(org.xml.sax.SAXException)

Aggregations

Trigger (org.jbpm.workflow.core.node.Trigger)9 EventTrigger (org.jbpm.workflow.core.node.EventTrigger)8 ConstraintTrigger (org.jbpm.workflow.core.node.ConstraintTrigger)7 StartNode (org.jbpm.workflow.core.node.StartNode)7 ArrayList (java.util.ArrayList)5 EventFilter (org.jbpm.process.core.event.EventFilter)5 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)5 List (java.util.List)4 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)3 ActionNode (org.jbpm.workflow.core.node.ActionNode)3 EndNode (org.jbpm.workflow.core.node.EndNode)3 EventNode (org.jbpm.workflow.core.node.EventNode)3 Node (org.kie.api.definition.process.Node)3 NodeContainer (org.kie.api.definition.process.NodeContainer)3 Constraint (org.jbpm.workflow.core.Constraint)2 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)2 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)2 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)2 FaultNode (org.jbpm.workflow.core.node.FaultNode)2 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)2