Search in sources :

Example 1 with ConstraintTrigger

use of io.automatiko.engine.workflow.process.core.node.ConstraintTrigger in project automatiko-engine by automatiko-io.

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(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) Map(java.util.Map) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 2 with ConstraintTrigger

use of io.automatiko.engine.workflow.process.core.node.ConstraintTrigger in project automatiko-engine by automatiko-io.

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(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) SAXException(org.xml.sax.SAXException)

Example 3 with ConstraintTrigger

use of io.automatiko.engine.workflow.process.core.node.ConstraintTrigger in project automatiko-engine by automatiko-io.

the class ExecutableProcessFactory method processEventSubprocessStartNode.

private void processEventSubprocessStartNode(ExecutableProcess process, StartNode subNode, EventSubProcessNode eventSubProcessNode, List<String> eventSubProcessHandlers) {
    List<Trigger> triggers = subNode.getTriggers();
    if (triggers != null) {
        for (Trigger trigger : triggers) {
            if (trigger instanceof EventTrigger) {
                final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
                for (EventFilter filter : filters) {
                    eventSubProcessNode.addEvent((EventTypeFilter) filter);
                    String type = ((EventTypeFilter) filter).getType();
                    if (type.startsWith("Error-") || type.startsWith("Escalation")) {
                        String faultCode = (String) subNode.getMetaData().get("FaultCode");
                        String replaceRegExp = "Error-|Escalation-";
                        final String signalType = type;
                        ExceptionScope exceptionScope = (ExceptionScope) ((ContextContainer) eventSubProcessNode.getParentContainer()).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
                        if (exceptionScope == null) {
                            exceptionScope = new ExceptionScope();
                            ((ContextContainer) eventSubProcessNode.getParentContainer()).addContext(exceptionScope);
                            ((ContextContainer) eventSubProcessNode.getParentContainer()).setDefaultContext(exceptionScope);
                        }
                        String faultVariable = null;
                        if (trigger.getInAssociations() != null && !trigger.getInAssociations().isEmpty()) {
                            faultVariable = findVariable(trigger.getInAssociations().get(0).getSources().get(0), process.getVariableScope());
                        }
                        ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
                        ConsequenceAction action = new ConsequenceAction("java", "");
                        action.setMetaData("Action", new SignalProcessInstanceAction(signalType, faultVariable, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
                        exceptionHandler.setAction(action);
                        exceptionHandler.setFaultVariable(faultVariable);
                        exceptionHandler.setRetryAfter((Integer) subNode.getMetaData().get("ErrorRetry"));
                        exceptionHandler.setRetryIncrement((Integer) subNode.getMetaData().get("ErrorRetryIncrement"));
                        if (subNode.getMetaData().get("ErrorRetryIncrementMultiplier") != null) {
                            exceptionHandler.setRetryIncrementMultiplier(((Number) subNode.getMetaData().get("ErrorRetryIncrementMultiplier")).floatValue());
                        }
                        exceptionHandler.setRetryLimit((Integer) subNode.getMetaData().get("ErrorRetryLimit"));
                        if (faultCode != null) {
                            String trimmedType = type.replaceFirst(replaceRegExp, "");
                            for (String error : trimmedType.split(",")) {
                                exceptionScope.setExceptionHandler(error, exceptionHandler);
                                eventSubProcessHandlers.add(error);
                            }
                        } else {
                            exceptionScope.setExceptionHandler(faultCode, exceptionHandler);
                        }
                    } else if (trigger instanceof ConstraintTrigger) {
                        ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
                        if (constraintTrigger.getConstraint() != null) {
                            EventTypeFilter eventTypeFilter = new EventTypeFilter();
                            eventTypeFilter.setType(type);
                            eventSubProcessNode.addEvent(eventTypeFilter);
                            eventSubProcessNode.addEvent("variableChanged");
                        }
                    }
                }
            }
        }
    }
}
Also used : ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 4 with ConstraintTrigger

use of io.automatiko.engine.workflow.process.core.node.ConstraintTrigger in project automatiko-engine by automatiko-io.

the class ProcessHandler method postProcessNodes.

private void postProcessNodes(ExecutableProcess process, NodeContainer container) {
    List<String> eventSubProcessHandlers = new ArrayList<String>();
    for (Node node : container.getNodes()) {
        if (node instanceof StartNode) {
            List<DataAssociation> associations = ((StartNode) node).getOutAssociations();
            if (associations != null) {
                for (DataAssociation da : associations) {
                    VariableScope scope = (VariableScope) process.getDefaultContext(VariableScope.VARIABLE_SCOPE);
                    Variable variable = scope.findVariable(da.getTarget());
                    if (variable != null) {
                        da.setTarget(variable.getName());
                    }
                }
            }
        } else if (node instanceof StateNode) {
            StateNode stateNode = (StateNode) node;
            String condition = (String) stateNode.getMetaData("Condition");
            stateNode.setCondition(context -> {
                return (boolean) MVEL.executeExpression(condition, context.getProcessInstance().getVariables());
            });
        } else if (node instanceof NodeContainer) {
            // prepare event sub process
            if (node instanceof EventSubProcessNode) {
                EventSubProcessNode eventSubProcessNode = (EventSubProcessNode) node;
                Node[] nodes = eventSubProcessNode.getNodes();
                for (Node subNode : nodes) {
                    // avoids cyclomatic complexity
                    if (subNode == null || !(subNode instanceof StartNode)) {
                        continue;
                    }
                    List<Trigger> triggers = ((StartNode) subNode).getTriggers();
                    if (triggers == null) {
                        continue;
                    }
                    for (Trigger trigger : triggers) {
                        if (trigger instanceof EventTrigger) {
                            final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
                            for (EventFilter filter : filters) {
                                if (filter instanceof EventTypeFilter) {
                                    eventSubProcessNode.addEvent((EventTypeFilter) filter);
                                    String type = ((EventTypeFilter) filter).getType();
                                    if (type.startsWith("Error-") || type.startsWith("Escalation")) {
                                        String faultCode = (String) subNode.getMetaData().get("FaultCode");
                                        String replaceRegExp = "Error-|Escalation-";
                                        final String signalType = type;
                                        ExceptionScope exceptionScope = (ExceptionScope) ((ContextContainer) eventSubProcessNode.getParentContainer()).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
                                        if (exceptionScope == null) {
                                            exceptionScope = new ExceptionScope();
                                            ((ContextContainer) eventSubProcessNode.getParentContainer()).addContext(exceptionScope);
                                            ((ContextContainer) eventSubProcessNode.getParentContainer()).setDefaultContext(exceptionScope);
                                        }
                                        String faultVariable = null;
                                        if (trigger.getInAssociations() != null && !trigger.getInAssociations().isEmpty()) {
                                            faultVariable = findVariable(trigger.getInAssociations().get(0).getSources().get(0), process.getVariableScope());
                                        }
                                        ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
                                        ConsequenceAction action = new ConsequenceAction("java", "");
                                        action.setMetaData("Action", new SignalProcessInstanceAction(signalType, faultVariable, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
                                        exceptionHandler.setAction(action);
                                        exceptionHandler.setFaultVariable(faultVariable);
                                        exceptionHandler.setRetryAfter((Integer) subNode.getMetaData().get("ErrorRetry"));
                                        exceptionHandler.setRetryIncrement((Integer) subNode.getMetaData().get("ErrorRetryIncrement"));
                                        if (subNode.getMetaData().get("ErrorRetryIncrementMultiplier") != null) {
                                            exceptionHandler.setRetryIncrementMultiplier(((Number) subNode.getMetaData().get("ErrorRetryIncrementMultiplier")).floatValue());
                                        }
                                        exceptionHandler.setRetryLimit((Integer) subNode.getMetaData().get("ErrorRetryLimit"));
                                        if (faultCode != null) {
                                            String trimmedType = type.replaceFirst(replaceRegExp, "");
                                            for (String error : trimmedType.split(",")) {
                                                exceptionScope.setExceptionHandler(error, exceptionHandler);
                                                eventSubProcessHandlers.add(error);
                                            }
                                        } else {
                                            exceptionScope.setExceptionHandler(faultCode, exceptionHandler);
                                        }
                                    } else if (type.equals("Compensation")) {
                                        // 1. Find the parent sub-process to this event sub-process
                                        NodeContainer parentSubProcess;
                                        NodeContainer subProcess = eventSubProcessNode.getParentContainer();
                                        Object isForCompensationObj = eventSubProcessNode.getMetaData("isForCompensation");
                                        if (isForCompensationObj == null) {
                                            eventSubProcessNode.setMetaData("isForCompensation", true);
                                            logger.warn("Overriding empty or false value of \"isForCompensation\" attribute on Event Sub-Process [" + eventSubProcessNode.getMetaData("UniqueId") + "] and setting it to true.");
                                        }
                                        if (subProcess instanceof ExecutableProcess) {
                                            // (instance)?!?
                                            throw new IllegalArgumentException("Compensation Event Sub-Processes at the process level are not supported.");
                                        }
                                        parentSubProcess = ((Node) subProcess).getParentContainer();
                                        // 2. The event filter (never fires, purely for dumping purposes) has
                                        // already been added
                                        // 3. Add compensation scope
                                        String compensationHandlerId = (String) ((CompositeNode) subProcess).getMetaData("UniqueId");
                                        addCompensationScope(process, eventSubProcessNode, parentSubProcess, compensationHandlerId);
                                    }
                                }
                            }
                        } else if (trigger instanceof ConstraintTrigger) {
                            ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
                            if (constraintTrigger.getConstraint() != null) {
                                String processId = ((ExecutableProcess) container).getId();
                                String type = "RuleFlowStateEventSubProcess-Event-" + processId + "-" + eventSubProcessNode.getUniqueId();
                                EventTypeFilter eventTypeFilter = new EventTypeFilter();
                                eventTypeFilter.setType(type);
                                eventSubProcessNode.addEvent(eventTypeFilter);
                                eventSubProcessNode.addEvent("variableChanged");
                                ((StartNode) subNode).setCondition(context -> {
                                    return (boolean) MVEL.executeExpression(constraintTrigger.getConstraint(), context.getProcessInstance().getVariables());
                                });
                            }
                        }
                    }
                }
            // for( Node subNode : nodes)
            }
            postProcessNodes(process, (NodeContainer) node);
        } else if (node instanceof EndNode) {
            handleIntermediateOrEndThrowCompensationEvent((EndNode) node);
        } else if (node instanceof ActionNode) {
            handleIntermediateOrEndThrowCompensationEvent((ActionNode) node);
        } else if (node instanceof EventNode) {
            final EventNode eventNode = (EventNode) node;
            if (!(eventNode instanceof BoundaryEventNode) && eventNode.getDefaultIncomingConnections().size() == 0) {
                throw new IllegalArgumentException("Event node '" + node.getName() + "' [" + node.getId() + "] has no incoming connection");
            }
        }
    }
    // handler
    for (Node node : container.getNodes()) {
        if (node instanceof FaultNode) {
            FaultNode faultNode = (FaultNode) node;
            if (eventSubProcessHandlers.contains(faultNode.getFaultName())) {
                faultNode.setTerminateParent(false);
            }
        }
    }
}
Also used : Handler(io.automatiko.engine.workflow.compiler.xml.Handler) CompensationHandler(io.automatiko.engine.workflow.base.core.context.exception.CompensationHandler) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) Constraint(io.automatiko.engine.workflow.process.core.Constraint) ExecutableProcessValidator(io.automatiko.engine.workflow.process.executable.core.validation.ExecutableProcessValidator) LoggerFactory(org.slf4j.LoggerFactory) Definitions(io.automatiko.engine.workflow.bpmn2.core.Definitions) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) FunctionTagDefinition(io.automatiko.engine.workflow.base.core.FunctionTagDefinition) Error(io.automatiko.engine.workflow.bpmn2.core.Error) Action(io.automatiko.engine.workflow.base.instance.impl.Action) NodeImpl(io.automatiko.engine.workflow.process.core.impl.NodeImpl) Matcher(java.util.regex.Matcher) ConstraintImpl(io.automatiko.engine.workflow.process.core.impl.ConstraintImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) DataStore(io.automatiko.engine.workflow.bpmn2.core.DataStore) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) TagDefinition(io.automatiko.engine.workflow.base.core.TagDefinition) Swimlane(io.automatiko.engine.workflow.base.core.context.swimlane.Swimlane) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) List(java.util.List) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) ProcessInstanceCompensationAction(io.automatiko.engine.workflow.base.instance.impl.actions.ProcessInstanceCompensationAction) PatternConstants(io.automatiko.engine.workflow.util.PatternConstants) ExtensibleXmlParser(io.automatiko.engine.workflow.compiler.xml.ExtensibleXmlParser) SAXException(org.xml.sax.SAXException) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) BaseAbstractHandler(io.automatiko.engine.workflow.compiler.xml.BaseAbstractHandler) StaticTagDefinition(io.automatiko.engine.workflow.base.core.StaticTagDefinition) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) Interface(io.automatiko.engine.workflow.bpmn2.core.Interface) Lane(io.automatiko.engine.workflow.bpmn2.core.Lane) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) Timer(io.automatiko.engine.workflow.base.core.timer.Timer) IntermediateLink(io.automatiko.engine.workflow.bpmn2.core.IntermediateLink) Resource(io.automatiko.engine.workflow.bpmn2.core.Resource) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Split(io.automatiko.engine.workflow.process.core.node.Split) HashMap(java.util.HashMap) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) Node(io.automatiko.engine.api.definition.process.Node) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) CancelNodeInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Attributes(org.xml.sax.Attributes) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) Association(io.automatiko.engine.workflow.bpmn2.core.Association) Logger(org.slf4j.Logger) Signal(io.automatiko.engine.workflow.bpmn2.core.Signal) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) Connection(io.automatiko.engine.workflow.process.core.Connection) ExtendedNodeImpl(io.automatiko.engine.workflow.process.core.impl.ExtendedNodeImpl) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) SequenceFlow(io.automatiko.engine.workflow.bpmn2.core.SequenceFlow) ConnectionRef(io.automatiko.engine.workflow.process.core.impl.ConnectionRef) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Process(io.automatiko.engine.workflow.base.core.Process) CompensationScope(io.automatiko.engine.workflow.base.core.context.exception.CompensationScope) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) MVEL(org.mvel2.MVEL) Message(io.automatiko.engine.workflow.bpmn2.core.Message) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateBasedNode(io.automatiko.engine.workflow.process.core.node.StateBasedNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) SubProcessNode(io.automatiko.engine.workflow.process.core.node.SubProcessNode) RuleSetNode(io.automatiko.engine.workflow.process.core.node.RuleSetNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Node(io.automatiko.engine.api.definition.process.Node) HumanTaskNode(io.automatiko.engine.workflow.process.core.node.HumanTaskNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) ArrayList(java.util.ArrayList) StateNode(io.automatiko.engine.workflow.process.core.node.StateNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode) Trigger(io.automatiko.engine.workflow.process.core.node.Trigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) FaultNode(io.automatiko.engine.workflow.process.core.node.FaultNode) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 5 with ConstraintTrigger

use of io.automatiko.engine.workflow.process.core.node.ConstraintTrigger in project automatiko-engine by automatiko-io.

the class StartEventHandler method handleNode.

@Override
@SuppressWarnings("unchecked")
protected void handleNode(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;
    // TODO: StartEventHandler.handleNode(): the parser doesn't discriminate between
    // the schema default and the actual set value
    // However, while the schema says the "isInterrupting" attr should default to
    // true
    // The spec says that Escalation start events should default to not
    // interrupting..
    startNode.setInterrupting(Boolean.parseBoolean(element.getAttribute("isInterrupting")));
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataOutput".equals(nodeName)) {
            readDataOutput(xmlNode, parser);
        } else if ("dataOutputAssociation".equals(nodeName)) {
            readDataOutputAssociation(xmlNode, startNode);
        } else if ("outputSet".equals(nodeName)) {
            // p. 225, BPMN2 spec (2011-01-03)
            // InputSet and OutputSet elements imply that process execution should wait for
            // them to be filled
            // and are therefore not applicable to catch events
            String message = "Ignoring <" + nodeName + "> element: " + "<" + nodeName + "> elements should not be used on start or other catch events.";
            SAXParseException saxpe = new SAXParseException(message, parser.getLocator());
            parser.warning(saxpe);
        // no exception thrown for backwards compatibility (we used to ignore these
        // elements)
        } else if ("conditionalEventDefinition".equals(nodeName)) {
            String constraint = null;
            org.w3c.dom.Node subNode = xmlNode.getFirstChild();
            while (subNode != null) {
                String subnodeName = subNode.getNodeName();
                if ("condition".equals(subnodeName)) {
                    constraint = xmlNode.getTextContent();
                    break;
                }
                subNode = subNode.getNextSibling();
            }
            ConstraintTrigger trigger = new ConstraintTrigger();
            trigger.setConstraint(constraint);
            startNode.addTrigger(trigger);
            startNode.setMetaData(TRIGGER_REF, "Condition-" + node.getId());
            startNode.setMetaData(TRIGGER_TYPE, "Condition");
            break;
        } else if ("signalEventDefinition".equals(nodeName)) {
            String type = ((Element) xmlNode).getAttribute("signalRef");
            Signal signal = findSignalByName(parser, type);
            type = checkSignalAndConvertToRealSignalNam(parser, type);
            if (type != null && type.trim().length() > 0) {
                addTriggerWithInMappings(startNode, type);
            }
            startNode.setMetaData(MESSAGE_TYPE, type);
            startNode.setMetaData(TRIGGER_TYPE, "Signal");
            if (signal != null) {
                String eventType = signal.getStructureRef();
                ProcessBuildData buildData = ((ProcessBuildData) parser.getData());
                Map<String, ItemDefinition> itemDefinitions = (Map<String, ItemDefinition>) buildData.getMetaData("ItemDefinitions");
                if (itemDefinitions != null && itemDefinitions.containsKey(eventType)) {
                    startNode.setMetaData(TRIGGER_REF, itemDefinitions.get(eventType).getStructureRef());
                } else {
                    startNode.setMetaData(TRIGGER_REF, type);
                }
            } else {
                startNode.setMetaData(TRIGGER_REF, type);
            }
        } else if ("messageEventDefinition".equals(nodeName)) {
            String messageRef = ((Element) xmlNode).getAttribute("messageRef");
            Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
            if (messages == null) {
                throw new IllegalArgumentException("No messages found");
            }
            Message message = messages.get(messageRef);
            if (message == null) {
                throw new IllegalArgumentException("Could not find message " + messageRef);
            }
            startNode.setMetaData(MESSAGE_TYPE, message.getType());
            startNode.setMetaData(TRIGGER_TYPE, "ConsumeMessage");
            startNode.setMetaData(TRIGGER_REF, message.getName());
            startNode.setMetaData(TRIGGER_CORRELATION, message.getCorrelation());
            startNode.setMetaData(TRIGGER_CORRELATION_EXPR, message.getCorrelationExpression());
            for (Entry<String, Object> entry : message.getMetaData().entrySet()) {
                startNode.setMetaData(entry.getKey(), entry.getValue());
            }
            addTriggerWithInMappings(startNode, "Message-" + message.getName());
        } else if ("timerEventDefinition".equals(nodeName)) {
            handleTimerNode(startNode, element, uri, localName, parser);
            startNode.setMetaData(TRIGGER_TYPE, "Timer");
        // following event definitions are only for event sub process and will be
        // validated to not be included in top process definitions
        } else if ("errorEventDefinition".equals(nodeName)) {
            if (!startNode.isInterrupting()) {
                // BPMN2 spec (p.245-246, (2011-01-03)) implies that
                // - a <startEvent> in an Event Sub-Process
                // - *without* the 'isInterupting' attribute always interrupts (containing
                // process)
                String errorMsg = "Error Start Events in an Event Sub-Process always interrupt the containing (sub)process(es).";
                throw new IllegalArgumentException(errorMsg);
            }
            String errorRef = ((Element) xmlNode).getAttribute("errorRef");
            if (errorRef != null && errorRef.trim().length() > 0) {
                List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
                if (errors == null) {
                    throw new IllegalArgumentException("No errors found");
                }
                Error error = null;
                for (Error listError : errors) {
                    if (errorRef.equals(listError.getId())) {
                        error = listError;
                    }
                }
                if (error == null) {
                    throw new IllegalArgumentException("Could not find error " + errorRef);
                }
                startNode.setMetaData("FaultCode", error.getErrorCode());
                addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode());
                startNode.setMetaData(TRIGGER_TYPE, "Error");
                startNode.setMetaData(TRIGGER_REF, "Error-" + error.getErrorCode());
                if (error.getMetaData().get("retry") != null) {
                    startNode.setMetaData("ErrorRetry", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retry"))).intValue());
                    if (error.getMetaData().get("retryLimit") != null) {
                        startNode.setMetaData("ErrorRetryLimit", Integer.parseInt((String) error.getMetaData().get("retryLimit")));
                    }
                    if (error.getMetaData().get("retryIncrement") != null) {
                        startNode.setMetaData("ErrorRetryIncrement", ((Long) DateTimeUtils.parseDuration((String) error.getMetaData().get("retryIncrement"))).intValue());
                    }
                    if (error.getMetaData().get("retryMultiplier") != null) {
                        startNode.setMetaData("ErrorRetryIncrementMultiplier", Float.parseFloat((String) error.getMetaData().get("retryMultiplier")));
                    }
                }
            }
        } else if ("escalationEventDefinition".equals(nodeName)) {
            String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
            if (escalationRef != null && escalationRef.trim().length() > 0) {
                Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
                if (escalations == null) {
                    throw new IllegalArgumentException("No escalations found");
                }
                Escalation escalation = escalations.get(escalationRef);
                if (escalation == null) {
                    throw new IllegalArgumentException("Could not find escalation " + escalationRef);
                }
                addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
                startNode.setMetaData(TRIGGER_TYPE, "Escalation");
            }
        } else if ("compensateEventDefinition".equals(nodeName)) {
            handleCompensationNode(startNode, xmlNode);
        }
        xmlNode = xmlNode.getNextSibling();
    }
    node.setMetaData("DataOutputs", new LinkedHashMap<String, String>(dataOutputTypes));
}
Also used : ConstraintTrigger(io.automatiko.engine.workflow.process.core.node.ConstraintTrigger) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Message(io.automatiko.engine.workflow.bpmn2.core.Message) Node(io.automatiko.engine.workflow.process.core.Node) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Element(org.w3c.dom.Element) Escalation(io.automatiko.engine.workflow.bpmn2.core.Escalation) ItemDefinition(io.automatiko.engine.workflow.bpmn2.core.ItemDefinition) Error(io.automatiko.engine.workflow.bpmn2.core.Error) Signal(io.automatiko.engine.workflow.bpmn2.core.Signal) Entry(java.util.Map.Entry) ProcessBuildData(io.automatiko.engine.workflow.compiler.xml.ProcessBuildData) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ConstraintTrigger (io.automatiko.engine.workflow.process.core.node.ConstraintTrigger)7 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)5 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)5 Trigger (io.automatiko.engine.workflow.process.core.node.Trigger)5 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)3 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)3 Map (java.util.Map)3 ContextContainer (io.automatiko.engine.workflow.base.core.ContextContainer)2 ActionExceptionHandler (io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler)2 ExceptionScope (io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope)2 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)2 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)2 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)2 SignalProcessInstanceAction (io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction)2 Error (io.automatiko.engine.workflow.bpmn2.core.Error)2 Escalation (io.automatiko.engine.workflow.bpmn2.core.Escalation)2 ItemDefinition (io.automatiko.engine.workflow.bpmn2.core.ItemDefinition)2 Message (io.automatiko.engine.workflow.bpmn2.core.Message)2 Signal (io.automatiko.engine.workflow.bpmn2.core.Signal)2 ProcessBuildData (io.automatiko.engine.workflow.compiler.xml.ProcessBuildData)2