Search in sources :

Example 1 with Trigger

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

the class LightProcessRuntime method initProcessEventListener.

private void initProcessEventListener(Process process) {
    if (process instanceof ExecutableProcess) {
        for (Node node : ((ExecutableProcess) process).getNodes()) {
            if (node instanceof StartNode) {
                StartNode startNode = (StartNode) node;
                if (startNode != null) {
                    List<Trigger> triggers = startNode.getTriggers();
                    if (triggers != null) {
                        for (Trigger trigger : triggers) {
                            if (trigger instanceof EventTrigger) {
                                final List<EventFilter> filters = ((EventTrigger) trigger).getEventFilters();
                                String type = null;
                                for (EventFilter filter : filters) {
                                    if (filter instanceof EventTypeFilter) {
                                        type = ((EventTypeFilter) filter).getType();
                                    }
                                }
                                StartProcessEventListener listener = new StartProcessEventListener(process.getId(), filters, trigger.getInMappings(), startNode.getEventTransformer());
                                signalManager.addEventListener(type, listener);
                                ((ExecutableProcess) process).getRuntimeMetaData().put("StartProcessEventType", type);
                                ((ExecutableProcess) process).getRuntimeMetaData().put("StartProcessEventListener", listener);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) 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) Node(io.automatiko.engine.api.definition.process.Node) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) EventFilter(io.automatiko.engine.workflow.base.core.event.EventFilter) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 2 with Trigger

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

the class ServiceTaskDescriptor method collectHandledErrorCodes.

private Set<String> collectHandledErrorCodes() {
    Set<String> errorCodes = new HashSet<>();
    NodeContainer container = workItemNode.getParentContainer();
    String thisNodeId = (String) workItemNode.getMetaData("UniqueId");
    for (Node node : container.getNodes()) {
        if (node instanceof BoundaryEventNode) {
            String errorCode = (String) node.getMetaData().get("ErrorEvent");
            if (errorCode != null && ((BoundaryEventNode) node).getAttachedToNodeId().equals(thisNodeId)) {
                errorCodes.add(errorCode);
            }
        }
    }
    // next collect event subprocess node with error start event from this level and to all parents
    String replaceRegExp = "Error-|Escalation-";
    for (Node node : container.getNodes()) {
        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-")) {
                                    String trimmedType = type.replaceFirst(replaceRegExp, "");
                                    for (String error : trimmedType.split(",")) {
                                        errorCodes.add(error);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return errorCodes;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Node(io.automatiko.engine.api.definition.process.Node) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) NodeContainer(io.automatiko.engine.api.definition.process.NodeContainer) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) 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) HashSet(java.util.HashSet) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger)

Example 3 with Trigger

use of io.automatiko.engine.workflow.process.core.node.Trigger 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 4 with Trigger

use of io.automatiko.engine.workflow.process.core.node.Trigger 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 5 with Trigger

use of io.automatiko.engine.workflow.process.core.node.Trigger 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)

Aggregations

EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)11 Trigger (io.automatiko.engine.workflow.process.core.node.Trigger)11 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)8 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)8 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)8 ConstraintTrigger (io.automatiko.engine.workflow.process.core.node.ConstraintTrigger)7 Node (io.automatiko.engine.api.definition.process.Node)5 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)4 ArrayList (java.util.ArrayList)4 NodeContainer (io.automatiko.engine.api.definition.process.NodeContainer)3 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)3 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)3 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)3 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)3 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)3 List (java.util.List)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 Timer (io.automatiko.engine.workflow.base.core.timer.Timer)2