Search in sources :

Example 1 with ExceptionScope

use of io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope in project automatiko-engine by automatiko-io.

the class CompositeNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    super.writeNode(getNodeName(), node, xmlDump, includeMeta);
    CompositeNode compositeNode = (CompositeNode) node;
    writeAttributes(compositeNode, xmlDump, includeMeta);
    xmlDump.append(">" + EOL);
    if (includeMeta) {
        writeMetaData(compositeNode, xmlDump);
    }
    for (String eventType : compositeNode.getActionTypes()) {
        writeActions(eventType, compositeNode.getActions(eventType), xmlDump);
    }
    writeTimers(compositeNode.getTimers(), xmlDump);
    if (compositeNode instanceof CompositeContextNode) {
        VariableScope variableScope = (VariableScope) ((CompositeContextNode) compositeNode).getDefaultContext(VariableScope.VARIABLE_SCOPE);
        if (variableScope != null) {
            List<Variable> variables = variableScope.getVariables();
            XmlWorkflowProcessDumper.visitVariables(variables, xmlDump);
        }
        ExceptionScope exceptionScope = (ExceptionScope) ((CompositeContextNode) compositeNode).getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
        if (exceptionScope != null) {
            XmlWorkflowProcessDumper.visitExceptionHandlers(exceptionScope.getExceptionHandlers(), xmlDump);
        }
    }
    xmlDump.append("      </connections>" + EOL);
    Map<String, CompositeNode.NodeAndType> inPorts = getInPorts(compositeNode);
    xmlDump.append("      <in-ports>" + EOL);
    for (Map.Entry<String, CompositeNode.NodeAndType> entry : inPorts.entrySet()) {
        xmlDump.append("        <in-port type=\"" + entry.getKey() + "\" nodeId=\"" + entry.getValue().getNodeId() + "\" nodeInType=\"" + entry.getValue().getType() + "\" />" + EOL);
    }
    xmlDump.append("      </in-ports>" + EOL);
    Map<String, CompositeNode.NodeAndType> outPorts = getOutPorts(compositeNode);
    xmlDump.append("      <out-ports>" + EOL);
    for (Map.Entry<String, CompositeNode.NodeAndType> entry : outPorts.entrySet()) {
        xmlDump.append("        <out-port type=\"" + entry.getKey() + "\" nodeId=\"" + entry.getValue().getNodeId() + "\" nodeOutType=\"" + entry.getValue().getType() + "\" />" + EOL);
    }
    xmlDump.append("      </out-ports>" + EOL);
    endNode(getNodeName(), xmlDump);
}
Also used : CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) Map(java.util.Map) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 2 with ExceptionScope

use of io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope in project automatiko-engine by automatiko-io.

the class ExceptionHandlerHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    ContextContainer contextContainer = (ContextContainer) parser.getParent();
    final String type = element.getAttribute("type");
    emptyAttributeCheck(localName, "type", type, parser);
    final String faultName = element.getAttribute("faultName");
    emptyAttributeCheck(localName, "faultName", type, parser);
    final String faultVariable = element.getAttribute("faultVariable");
    ActionExceptionHandler exceptionHandler = null;
    if ("action".equals(type)) {
        exceptionHandler = new ActionExceptionHandler();
        org.w3c.dom.Node xmlNode = element.getFirstChild();
        if (xmlNode instanceof Element) {
            Element actionXml = (Element) xmlNode;
            ProcessAction action = ActionNodeHandler.extractAction(actionXml);
            ((ActionExceptionHandler) exceptionHandler).setAction(action);
        }
    } else {
        throw new SAXParseException("Unknown exception handler type " + type, parser.getLocator());
    }
    if (faultVariable != null && faultVariable.length() > 0) {
        exceptionHandler.setFaultVariable(faultVariable);
    }
    ExceptionScope exceptionScope = (ExceptionScope) contextContainer.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope == null) {
        exceptionScope = new ExceptionScope();
        contextContainer.addContext(exceptionScope);
        contextContainer.setDefaultContext(exceptionScope);
    }
    for (String error : faultName.split(",")) {
        exceptionScope.setExceptionHandler(error, exceptionHandler);
    }
    return null;
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope)

Example 3 with ExceptionScope

use of io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope in project automatiko-engine by automatiko-io.

the class ExecutableProcessFactory method linkBoundaryErrorEvent.

private static void linkBoundaryErrorEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    ContextContainer compositeNode = (ContextContainer) attachedNode;
    ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope == null) {
        exceptionScope = new ExceptionScope();
        compositeNode.addContext(exceptionScope);
        compositeNode.setDefaultContext(exceptionScope);
    }
    String errorCode = (String) node.getMetaData().get("ErrorEvent");
    boolean hasErrorCode = (Boolean) node.getMetaData().get("HasErrorEvent");
    String errorStructureRef = (String) node.getMetaData().get("ErrorStructureRef");
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    String variable = ((EventNode) node).getVariableName();
    ConsequenceAction action = new ConsequenceAction("java", null);
    action.setMetaData(ACTION, new SignalProcessInstanceAction("Error-" + attachedTo + "-" + errorCode, variable, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
    exceptionHandler.setAction(action);
    exceptionHandler.setFaultVariable(variable);
    exceptionHandler.setRetryAfter((Integer) node.getMetaData().get("ErrorRetry"));
    exceptionHandler.setRetryIncrement((Integer) node.getMetaData().get("ErrorRetryIncrement"));
    if (node.getMetaData().get("ErrorRetryIncrementMultiplier") != null) {
        exceptionHandler.setRetryIncrementMultiplier(((Number) node.getMetaData().get("ErrorRetryIncrementMultiplier")).floatValue());
    }
    exceptionHandler.setRetryLimit((Integer) node.getMetaData().get("ErrorRetryLimit"));
    if (hasErrorCode) {
        for (String error : errorCode.split(",")) {
            exceptionScope.setExceptionHandler(error, exceptionHandler);
        }
    } else {
        exceptionScope.setExceptionHandler(null, exceptionHandler);
    }
    if (errorStructureRef != null) {
        exceptionScope.setExceptionHandler(errorStructureRef, exceptionHandler);
    }
    List<ProcessAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
    if (actions == null) {
        actions = new ArrayList<ProcessAction>();
    }
    ConsequenceAction cancelAction = new ConsequenceAction("java", null);
    cancelAction.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
    actions.add(cancelAction);
    ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) CancelNodeInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode)

Example 4 with ExceptionScope

use of io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope 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 5 with ExceptionScope

use of io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope in project automatiko-engine by automatiko-io.

the class ProcessHandler method linkBoundaryEscalationEvent.

protected void linkBoundaryEscalationEvent(NodeContainer nodeContainer, Node node, String attachedTo, Node attachedNode) {
    boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity");
    String escalationCode = (String) node.getMetaData().get("EscalationEvent");
    String escalationStructureRef = (String) node.getMetaData().get("EscalationStructureRef");
    ContextContainer compositeNode = (ContextContainer) attachedNode;
    ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE);
    if (exceptionScope == null) {
        exceptionScope = new ExceptionScope();
        compositeNode.addContext(exceptionScope);
        compositeNode.setDefaultContext(exceptionScope);
    }
    String variable = ((EventNode) node).getVariableName();
    ActionExceptionHandler exceptionHandler = new ActionExceptionHandler();
    ConsequenceAction action = createJavaAction(new SignalProcessInstanceAction("Escalation-" + attachedTo + "-" + escalationCode, variable, SignalProcessInstanceAction.PROCESS_INSTANCE_SCOPE));
    exceptionHandler.setAction(action);
    exceptionHandler.setFaultVariable(variable);
    exceptionScope.setExceptionHandler(escalationCode, exceptionHandler);
    if (escalationStructureRef != null) {
        exceptionScope.setExceptionHandler(escalationStructureRef, exceptionHandler);
    }
    if (cancelActivity) {
        List<ProcessAction> actions = ((EventNode) node).getActions(EndNode.EVENT_NODE_EXIT);
        if (actions == null) {
            actions = new ArrayList<ProcessAction>();
        }
        ConsequenceAction cancelAction = new ConsequenceAction("java", "");
        cancelAction.setMetaData("Action", new CancelNodeInstanceAction(attachedTo));
        actions.add(cancelAction);
        ((EventNode) node).setActions(EndNode.EVENT_NODE_EXIT, actions);
    }
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) SignalProcessInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction) CancelNodeInstanceAction(io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ExceptionScope(io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope) ActionExceptionHandler(io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) EventNode(io.automatiko.engine.workflow.process.core.node.EventNode)

Aggregations

ExceptionScope (io.automatiko.engine.workflow.base.core.context.exception.ExceptionScope)9 ContextContainer (io.automatiko.engine.workflow.base.core.ContextContainer)6 ActionExceptionHandler (io.automatiko.engine.workflow.base.core.context.exception.ActionExceptionHandler)6 SignalProcessInstanceAction (io.automatiko.engine.workflow.base.instance.impl.actions.SignalProcessInstanceAction)5 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)5 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)5 CancelNodeInstanceAction (io.automatiko.engine.workflow.base.instance.impl.actions.CancelNodeInstanceAction)4 EventNode (io.automatiko.engine.workflow.process.core.node.EventNode)4 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)3 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)3 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)2 EventFilter (io.automatiko.engine.workflow.base.core.event.EventFilter)2 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)2 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)2 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)2 ConstraintTrigger (io.automatiko.engine.workflow.process.core.node.ConstraintTrigger)2 EventTrigger (io.automatiko.engine.workflow.process.core.node.EventTrigger)2 Trigger (io.automatiko.engine.workflow.process.core.node.Trigger)2 Map (java.util.Map)2 Node (io.automatiko.engine.api.definition.process.Node)1